<commit_before>
class TypeRegistered(type):
    """
    As classes of this metaclass are created, they keep a registry in the
    base class of all handler referenced by the keys in cls._handles.
    """
    def __init__(cls, name, bases, namespace):
        super(TypeRegistered, cls).__init__(name, bases, namespace)
        if not hasattr(cls, '_registry'):
            cls._registry = {}
        types_handled = getattr(cls, '_handles', [])
        cls._registry.update((type_, cls) for type_ in types_handled)

class BaseHandler(object):
    """
    Abstract base class for handlers.
    """

    __metaclass__ = TypeRegistered

    def __init__(self, base):
        """
        Initialize a new handler to handle `type`.

        :Parameters:
          - `base`: reference to pickler/unpickler

        """
        self._base = base

    def flatten(self, obj, data):
        """
        Flatten `obj` into a json-friendly form.

        :Parameters:
          - `obj`: object of `type`

        """
        raise NotImplementedError("Abstract method.")

    def restore(self, obj):
        """
        Restores the `obj` to `type`

        :Parameters:
          - `object`: json-friendly object

        """
        raise NotImplementedError("Abstract method.")<commit_msg>Add a backward-compatibility shim to lessen the burden upgrading from 0.4 to 0.5<commit_after>
class TypeRegistered(type):
    """
    As classes of this metaclass are created, they keep a registry in the
    base class of all handler referenced by the keys in cls._handles.
    """
    def __init__(cls, name, bases, namespace):
        super(TypeRegistered, cls).__init__(name, bases, namespace)
        if not hasattr(cls, '_registry'):
            cls._registry = {}
        types_handled = getattr(cls, '_handles', [])
        cls._registry.update((type_, cls) for type_ in types_handled)

class BaseHandler(object):
    """
    Abstract base class for handlers.
    """

    __metaclass__ = TypeRegistered

    def __init__(self, base):
        """
        Initialize a new handler to handle `type`.

        :Parameters:
          - `base`: reference to pickler/unpickler

        """
        self._base = base

    def flatten(self, obj, data):
        """
        Flatten `obj` into a json-friendly form.

        :Parameters:
          - `obj`: object of `type`

        """
        raise NotImplementedError("Abstract method.")

    def restore(self, obj):
        """
        Restores the `obj` to `type`

        :Parameters:
          - `object`: json-friendly object

        """
        raise NotImplementedError("Abstract method.")

# for backward compatibility, provide 'registry'
# jsonpickle 0.4 clients will call it with something like:
# registry.register(handled_type, handler_class)
class registry:
    @staticmethod
    def register(handled_type, handler_class):
        pass
{'fraction_non_alphanumeric': 0.10586601874349184, 'fraction_numerical': 0.0020826102047900035, 'mean_word_length': 2.3628938156359394, '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': '3181677', 'n_tokens_mistral': 817, 'n_tokens_neox': 789, 'n_words': 252}