'Create a collection of Rules from YAML documents.'

def __init__(self, yaml_text='', timer=None):

    if (timer is None):
        timer = SimpleSillyStub()
    self.init_time = datetime.now(g.tz)
    self.rules = []
    if (not yaml_text):
        return
    yaml_sections = [section.strip('\r\n') for section in re.split('^---', yaml_text, flags=re.MULTILINE)]
    rule_defs = []
    for (section_num, section) in enumerate(yaml_sections, 1):
        try:
            parsed = yaml.safe_load(section)
        except Exception as e:
            raise ValueError(('YAML    parsing    error    in    section    %s:    %s' % (section_num, e)))
        if isinstance(parsed, dict):
            rule_defs.append(RuleDefinition(yaml=section, values=parsed))
    timer.intermediate('yaml_parsing')
    if any((('standard' in rule_def.values) for rule_def in rule_defs)):
        standard_rules = {}
        try:
            wp = WikiPage.get(Frontpage, 'automoderator_standards')
            standard_defs = yaml.safe_load_all(wp.content)
            for standard_def in standard_defs:
                name = standard_def.pop('standard')
                standard_rules[name] = standard_def
        except Exception as e:
            g.log.error('Error    while    loading    automod    standards:    %s', e)
            standard_rules = None
    timer.intermediate('init_standard_rules')
    for rule_def in rule_defs:
        standard_name = rule_def.values.pop('standard', None)
        if standard_name:
            if (standard_rules is None):
                continue
            standard_values = None
            if isinstance(standard_name, basestring):
                standard_values = standard_rules.get(standard_name, None)
            if (not standard_values):
                raise AutoModeratorSyntaxError(('Invalid    standard:    `%s`' % standard_name), rule_def.yaml)
            new_values = standard_values.copy()
            new_values.update(rule_def.values)
            rule_def = rule_def._replace(values=new_values)
        type = rule_def.values.get('type', 'any')
        if (type == 'any'):
            rule = None
            for type_value in ('comment', 'submission'):
                rule_def.values['type'] = type_value
                try:
                    rule = Rule(rule_def.values, rule_def.yaml)
                except AutoModeratorRuleTypeError as type_error:
                    continue
                if rule.has_any_checks(targets_only=True):
                    self.rules.append(rule)
            if (not rule):
                raise type_error
        else:
            self.rules.append(Rule(rule_def.values, rule_def.yaml))
    timer.intermediate('init_rules')
    self.rules = [rule for rule in self.rules if (rule.has_any_checks() and rule.has_any_actions())]
    self.rules.sort(key=(lambda r: r.priority), reverse=True)
