<commit_before>from .web_handlers import (
    ResourceWebHandler,
    CollectionWebHandler,
    JSAPIWebHandler)
from .utils import url_path_join, with_end_slash
from .resource_handler import ResourceHandler
from .authenticator import NullAuthenticator


class Registry:
    def __init__(self):
        self._registered_types = {}
        self._authenticator = NullAuthenticator

    @property
    def authenticator(self):
        return self._authenticator

    @authenticator.setter
    def authenticator(self, authenticator):
        self._authenticator = authenticator

    @property
    def registered_types(self):
        return self._registered_types

    def register(self, typ, collection_name=None):
        """Registers a Resource type with an appropriate
        collection name. A collection name is a pluralized
        version of the resource, created by lowercasing
        the class name and adding an "s".
        The resulting collection name will be used in the URL
        representing the resource. For example, a resource Image
        will have URLs of the type

        http://example.com/api/v1/images/identifier/

        The collection name can always be overridden by specifying
        __collection_name__ in the resource class, or by specifying
        the collection_name parameter.

        Parameters
        ----------
        typ: ResourceHandler
            A subclass of the rest Resource type
        collection_name: str or None
            Overrides the resource collection name.

        Raises
        ------
        TypeError:
            if typ is not a subclass of Resource
        """
        if not issubclass(typ, ResourceHandler):
            raise TypeError("typ must be a subclass of Resource")

        if collection_name is not None:
            collection_name = collection_name
        elif hasattr(typ, "__collection_name__"):
            collection_name = typ.__collection_name__
        else:
            collection_name = typ.__name__.lower() + "s"

        self._registered_types[collection_name] = typ

    def __getitem__(self, collection_name):
        """Returns the class from the collection name with the
        indexing operator"""
        return self._registered_types[collection_name]

    def __contains__(self, item):
        """If the registry contains the given item"""
        return item in self._registered_types

    def api_handlers(self, base_urlpath, version="v1"):
        """Returns the API handlers for the interface.
        Add these handlers to your application to provide an
        interface to your Resources.


        Parameters
        ----------
        base_urlpath: str
            The base url path to serve<commit_msg>Fixed exception message<commit_after>from .web_handlers import (
    ResourceWebHandler,
    CollectionWebHandler,
    JSAPIWebHandler)
from .utils import url_path_join, with_end_slash
from .resource_handler import ResourceHandler
from .authenticator import NullAuthenticator


class Registry:
    def __init__(self):
        self._registered_types = {}
        self._authenticator = NullAuthenticator

    @property
    def authenticator(self):
        return self._authenticator

    @authenticator.setter
    def authenticator(self, authenticator):
        self._authenticator = authenticator

    @property
    def registered_types(self):
        return self._registered_types

    def register(self, typ, collection_name=None):
        """Registers a Resource type with an appropriate
        collection name. A collection name is a pluralized
        version of the resource, created by lowercasing
        the class name and adding an "s".
        The resulting collection name will be used in the URL
        representing the resource. For example, a resource Image
        will have URLs of the type

        http://example.com/api/v1/images/identifier/

        The collection name can always be overridden by specifying
        __collection_name__ in the resource class, or by specifying
        the collection_name parameter.

        Parameters
        ----------
        typ: ResourceHandler
            A subclass of the rest Resource type
        collection_name: str or None
            Overrides the resource collection name.

        Raises
        ------
        TypeError:
            if typ is not a subclass of Resource
        """
        if not issubclass(typ, ResourceHandler):
            raise TypeError("typ must be a subclass of ResourceHandler")

        if collection_name is not None:
            collection_name = collection_name
        elif hasattr(typ, "__collection_name__"):
            collection_name = typ.__collection_name__
        else:
            collection_name = typ.__name__.lower() + "s"

        self._registered_types[collection_name] = typ

    def __getitem__(self, collection_name):
        """Returns the class from the collection name with the
        indexing operator"""
        return self._registered_types[collection_name]

    def __contains__(self, item):
        """If the registry contains the given item"""
        return item in self._registered_types

    def api_handlers(self, base_urlpath, version="v1"):
        """Returns the API handlers for the interface.
        Add these handlers to your application to provide an
        interface to your Resources.


        Parameters
        ----------
        base_urlpath: str
            The base url path to serve
{'fraction_non_alphanumeric': 0.06198422886484504, 'fraction_numerical': 0.0007335411699981661, 'mean_word_length': 2.398130841121495, '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': '3188766', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1277, 'n_words': 485}