<commit_before>"""Catalog module."""

from six import iteritems
from six import add_metaclass

from .errors import Error
from .utils import is_provider


class CatalogMetaClass(type):

    """Providers catalog meta class."""

    def __new__(mcs, class_name, bases, attributes):
        """Meta class factory."""
        providers = dict()
        new_attributes = dict()
        for name, value in attributes.iteritems():
            if is_provider(value):
                providers[name] = value
            new_attributes[name] = value

        cls = type.__new__(mcs, class_name, bases, new_attributes)
        cls.providers = cls.providers.copy()
        cls.providers.update(providers)
        return cls


@add_metaclass(CatalogMetaClass)
class AbstractCatalog(object):

    """Abstract providers catalog."""

    providers = dict()

    __slots__ = ('__used_providers__',)

    def __init__(self, *used_providers):
        """Initializer."""
        self.__used_providers__ = set(used_providers)

    def __getattribute__(self, item):
        """Return providers."""
        attribute = super(AbstractCatalog, self).__getattribute__(item)
        if item in ('providers', '__used_providers__',):
            return attribute

        if attribute not in self.__used_providers__:
            raise Error('Provider \'{0}\' '.format(item) +
                        'is not listed in dependencies')
        return attribute

    @classmethod
    def filter(cls, provider_type):
        """Return dict of providers, that are instance of provided type."""
        return dict([(name, provider)
                     for name, provider in iteritems(cls.providers)
                     if isinstance(provider, provider_type)])

    @classmethod
    def override(cls, overriding):
        """Override current catalog providers by overriding catalog providers.

        :type overriding: AbstractCatalog
        """
        for name, provider in iteritems(overriding.providers):
            cls.providers[name].override(provider)
<commit_msg>Fixing bad for py3 dict.iteritems() usage after refactoring of Catalog using metaclasses<commit_after>"""Catalog module."""

from six import iteritems
from six import add_metaclass

from .errors import Error
from .utils import is_provider


class CatalogMetaClass(type):

    """Providers catalog meta class."""

    def __new__(mcs, class_name, bases, attributes):
        """Meta class factory."""
        providers = dict()
        new_attributes = dict()
        for name, value in iteritems(attributes):
            if is_provider(value):
                providers[name] = value
            new_attributes[name] = value

        cls = type.__new__(mcs, class_name, bases, new_attributes)
        cls.providers = cls.providers.copy()
        cls.providers.update(providers)
        return cls


@add_metaclass(CatalogMetaClass)
class AbstractCatalog(object):

    """Abstract providers catalog."""

    providers = dict()

    __slots__ = ('__used_providers__',)

    def __init__(self, *used_providers):
        """Initializer."""
        self.__used_providers__ = set(used_providers)

    def __getattribute__(self, item):
        """Return providers."""
        attribute = super(AbstractCatalog, self).__getattribute__(item)
        if item in ('providers', '__used_providers__',):
            return attribute

        if attribute not in self.__used_providers__:
            raise Error('Provider \'{0}\' '.format(item) +
                        'is not listed in dependencies')
        return attribute

    @classmethod
    def filter(cls, provider_type):
        """Return dict of providers, that are instance of provided type."""
        return dict([(name, provider)
                     for name, provider in iteritems(cls.providers)
                     if isinstance(provider, provider_type)])

    @classmethod
    def override(cls, overriding):
        """Override current catalog providers by overriding catalog providers.

        :type overriding: AbstractCatalog
        """
        for name, provider in iteritems(overriding.providers):
            cls.providers[name].override(provider)

{'fraction_non_alphanumeric': 0.1001926782273603, 'fraction_numerical': 0.000722543352601156, 'mean_word_length': 2.662257495590829, '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': '6393231', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1063, 'n_words': 311}