<commit_before># -*- coding: utf-8 -*-


import logging

from zope.interface import implementer

from scrapy.interfaces import ISpiderLoader

from .spiderfactory import SpiderFactory, SpiderFactoryException
from .model import get_spider_settings


logger = logging.getLogger(__name__)


@implementer(ISpiderLoader)
class MongoSpiderLoader(object):
    def __init__(self):
        self._spiders = None

    @property
    def spiders(self):
        if self._spiders is None:
            spiders = {}
            for setting in get_spider_settings():
                spid = setting['_id']
                try:
                    cls = SpiderFactory.mkspider(setting)
                except SpiderFactoryException as e:
                    logger.error('{}'.format(e))
                else:
                    spiders[spid] = cls
            self._spiders = spiders
        return self._spiders

    @classmethod
    def from_settings(cls, settings):
        return cls()

    def load(self, spid):
        return self.spiders[spid]

    def find_by_request(self, request):
        return [spid for spid, cls in self.spiders.items()
                if cls.handles_request(request)]<commit_msg>clean<commit_after># -*- coding: utf-8 -*-


import logging

from zope.interface import implementer

from scrapy.interfaces import ISpiderLoader

from .spiderfactory import SpiderFactory, SpiderFactoryException
from .model import get_spider_settings


logger = logging.getLogger(__name__)


@implementer(ISpiderLoader)
class MongoSpiderLoader:
    def __init__(self):
        self._spiders = None

    @property
    def spiders(self):
        if self._spiders is None:
            spiders = {}
            for setting in get_spider_settings():
                spid = setting['_id']
                try:
                    cls = SpiderFactory.mkspider(setting)
                except SpiderFactoryException as e:
                    logger.error('{}'.format(e))
                else:
                    spiders[spid] = cls
            self._spiders = spiders
        return self._spiders

    @classmethod
    def from_settings(cls, settings):
        return cls()

    def load(self, spid):
        return self.spiders[spid]

    def find_by_request(self, request):
        return [spid for spid, cls in self.spiders.items()
                if cls.handles_request(request)]
{'fraction_non_alphanumeric': 0.08368554522400676, 'fraction_numerical': 0.0008453085376162299, 'mean_word_length': 2.1268163804491413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4899873', 'n_tokens_mistral': 677, 'n_tokens_neox': 644, 'n_words': 165}