<commit_before>"""
A base Fetcher class.
"""

from tea_party.fetchers.callbacks import NullFetcherCallback


class DuplicateFetcherShortNameError(ValueError):

    """
    An already existing shortname was specified for a new BaseFetcher subclass.
    """

    def __init__(self, shortname, original_class, new_class):
        """
        Create a DuplicateFetcherShortNameError for the specified `shortname`,
        `original_class` and `new_class`.
        """

        super(DuplicateFetcherShortNameError, self).__init__(
            'Cannot assign shortname %r to %s as is already registered to %s' % (
                shortname,
                original_class,
                new_class,
            )
        )


class UnsupportedLocationError(ValueError):

    """
    A fetcher does not handle the specified location.
    """

    def __init__(self, source, fetcher_class):
        """
        Create an UnsupportedLocationError for the specified `source` and
        `fetcher_class`.
        """

        super(UnsupportedLocationError, self).__init__(
            'The fetcher class %s does not support the specified source (%s)' % (
                fetcher_class,
                source,
            )
        )


class BaseFetcher(object):

    """
    Base class for all fetcher classes.

    If you subclass this class, you will have to re-implement the
    :func:`read_source` and :func:`do_fetch` methods in your subclass to
    provide your fetcher specific fetch logic.

    If you intend to expose your fetcher to users, you must also declare a
    unique class-level `shortname`. This is what the user will specify in the
    :term:`party-file` to use a specific fetcher.
    """

    index = {}

    class __metaclass__(type):

        """
        A metaclass that automatically registers all BaseFetcher subclasses
        that provide a shortname attribute in their definition.
        """

        def __init__(cls, name, bases, attrs):
            """
            Registers the class into the index if it has a shortname attribute
            in its definition.
            """

            type.__init__(cls, name, bases, attrs)

            if 'shortname' in attrs and cls.shortname:
                if not isinstance(cls.shortname, basestring):
                    raise TypeError(
                        'The shortname attribute for %s must be a string.' %
                        cls)

                if cls.shortname in BaseFetcher.index:
                    raise DuplicateFetcherShortNameError(
                        shortname=cls.shortname,
                        original_class=BaseFetcher.index[cls.shortname],<commit_msg>Fixed incorrect term reference<commit_after>"""
A base Fetcher class.
"""

from tea_party.fetchers.callbacks import NullFetcherCallback


class DuplicateFetcherShortNameError(ValueError):

    """
    An already existing shortname was specified for a new BaseFetcher subclass.
    """

    def __init__(self, shortname, original_class, new_class):
        """
        Create a DuplicateFetcherShortNameError for the specified `shortname`,
        `original_class` and `new_class`.
        """

        super(DuplicateFetcherShortNameError, self).__init__(
            'Cannot assign shortname %r to %s as is already registered to %s' % (
                shortname,
                original_class,
                new_class,
            )
        )


class UnsupportedLocationError(ValueError):

    """
    A fetcher does not handle the specified location.
    """

    def __init__(self, source, fetcher_class):
        """
        Create an UnsupportedLocationError for the specified `source` and
        `fetcher_class`.
        """

        super(UnsupportedLocationError, self).__init__(
            'The fetcher class %s does not support the specified source (%s)' % (
                fetcher_class,
                source,
            )
        )


class BaseFetcher(object):

    """
    Base class for all fetcher classes.

    If you subclass this class, you will have to re-implement the
    :func:`read_source` and :func:`do_fetch` methods in your subclass to
    provide your fetcher specific fetch logic.

    If you intend to expose your fetcher to users, you must also declare a
    unique class-level `shortname`. This is what the user will specify in the
    :term:`party file` to use a specific fetcher.
    """

    index = {}

    class __metaclass__(type):

        """
        A metaclass that automatically registers all BaseFetcher subclasses
        that provide a shortname attribute in their definition.
        """

        def __init__(cls, name, bases, attrs):
            """
            Registers the class into the index if it has a shortname attribute
            in its definition.
            """

            type.__init__(cls, name, bases, attrs)

            if 'shortname' in attrs and cls.shortname:
                if not isinstance(cls.shortname, basestring):
                    raise TypeError(
                        'The shortname attribute for %s must be a string.' %
                        cls)

                if cls.shortname in BaseFetcher.index:
                    raise DuplicateFetcherShortNameError(
                        shortname=cls.shortname,
                        original_class=BaseFetcher.index[cls.shortname],
{'fraction_non_alphanumeric': 0.072751075369366, 'fraction_numerical': 0.0, 'mean_word_length': 2.0146561443066515, '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': '2251717', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1342, 'n_words': 465}