def __init__(self, docs, seeds):
    '\n        Initialize from database documents.\n\n        :param docs: Database document.\n        :type docs: list[dict]\n        :param seeds: Seed URLs, used for computing the costs for crawled links.\n        :type seeds: list[str]\n        '
    if (not docs):
        _invalid('At least one URL rule is required')
    self._rules = list()
    max_index = (len(docs) - 1)
    seed_domains = {URL(seed).host for seed in seeds}
    for (index, url_rule) in enumerate(docs):
        if (index < max_index):
            location = 'URL rule #{}'.format((index + 1))
            if (url_rule.get('pattern', '').strip() == ''):
                _invalid('Pattern is required', location)
            if ('match' not in url_rule):
                _invalid('Match selector is required', location)
            if ('action' not in url_rule):
                _invalid('Action selector is required', location)
            if ('amount' not in url_rule):
                _invalid('Amount is required', location)
            try:
                pattern_re = re.compile(url_rule['pattern'].format(SEED_DOMAINS='|'.join(seed_domains)))
            except:
                _invalid('Invalid regular expression', location)
            self._rules.append((pattern_re, url_rule['match'], url_rule['action'], url_rule['amount']))
        else:
            location = 'last URL rule'
            if ('pattern' in url_rule):
                _invalid('Pattern is not allowed', location)
            if ('match' in url_rule):
                _invalid('Match is not allowed', location)
            if ('action' not in url_rule):
                _invalid('Action is required', location)
            if ('amount' not in url_rule):
                _invalid('Amount is required', location)
            self._rules.append((None, None, url_rule['action'], url_rule['amount']))
Initialize from database documents.

:param docs: Database document.
:type docs: list[dict]
:param seeds: Seed URLs, used for computing the costs for crawled links.
:type seeds: list[str]
def __init__(self, docs, seeds):
    '\n        Initialize from database documents.\n\n        :param docs: Database document.\n        :type docs: list[dict]\n        :param seeds: Seed URLs, used for computing the costs for crawled links.\n        :type seeds: list[str]\n        '
    if (not docs):
        _invalid('At least one URL rule is required')
    self._rules = list()
    max_index = (len(docs) - 1)
    seed_domains = {URL(seed).host for seed in seeds}
    for (index, url_rule) in enumerate(docs):
        if (index < max_index):
            location = 'URL rule #{}'.format((index + 1))
            if (url_rule.get('pattern', ).strip() == ):
                _invalid('Pattern is required', location)
            if ('match' not in url_rule):
                _invalid('Match selector is required', location)
            if ('action' not in url_rule):
                _invalid('Action selector is required', location)
            if ('amount' not in url_rule):
                _invalid('Amount is required', location)
            try:
                pattern_re = re.compile(url_rule['pattern'].format(SEED_DOMAINS='|'.join(seed_domains)))
            except:
                _invalid('Invalid regular expression', location)
            self._rules.append((pattern_re, url_rule['match'], url_rule['action'], url_rule['amount']))
        else:
            location = 'last URL rule'
            if ('pattern' in url_rule):
                _invalid('Pattern is not allowed', location)
            if ('match' in url_rule):
                _invalid('Match is not allowed', location)
            if ('action' not in url_rule):
                _invalid('Action is required', location)
            if ('amount' not in url_rule):
                _invalid('Amount is required', location)
            self._rules.append((None, None, url_rule['action'], url_rule['amount']))