<commit_before>"""A shim module for deprecated imports
"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import types

class ShimModule(types.ModuleType):

    def __init__(self, *args, **kwargs):
        self._mirror = kwargs.pop("mirror")
        super(ShimModule, self).__init__(*args, **kwargs)

    def __getattr__(self, key):
        # Use the equivalent of import_item(name), see below
        name = "%s.%s" % (self._mirror, key)

        # NOTE: the code below is copied *verbatim* from
        # importstring.import_item. For some very strange reason that makes no
        # sense to me, if we call it *as a function*, it doesn't work.  This
        # has something to do with the deep bowels of the import machinery and
        # I couldn't find a way to make the code work as a standard function
        # call.  But at least since it's an unmodified copy of import_item,
        # which is used extensively and has a test suite, we can be reasonably
        # confident this is OK.  If anyone finds how to call the function, all
        # the below could be replaced simply with:
        #
        # from IPython.utils.importstring import import_item
        # return import_item('MIRROR.' + key)

        parts = name.rsplit('.', 1)
        if len(parts) == 2:
            # called with 'foo.bar....'
            package, obj = parts
            module = __import__(package, fromlist=[obj])
            try:
                pak = module.__dict__[obj]
            except KeyError:
                raise
                raise AttributeError(obj)
            return pak
        else:
            # called with un-dotted string
            return __import__(parts[0])

class ShimPackage(ShimModule):
    @property
    def __path__(self):
        return __import__(self._mirror).__path__<commit_msg>Remove debugging parts of shim module code<commit_after>"""A shim module for deprecated imports
"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import types

class ShimModule(types.ModuleType):

    def __init__(self, *args, **kwargs):
        self._mirror = kwargs.pop("mirror")
        super(ShimModule, self).__init__(*args, **kwargs)

    def __getattr__(self, key):
        # Use the equivalent of import_item(name), see below
        name = "%s.%s" % (self._mirror, key)

        # NOTE: the code below is copied *verbatim* from
        # importstring.import_item. For some very strange reason that makes no
        # sense to me, if we call it *as a function*, it doesn't work.  This
        # has something to do with the deep bowels of the import machinery and
        # I couldn't find a way to make the code work as a standard function
        # call.  But at least since it's an unmodified copy of import_item,
        # which is used extensively and has a test suite, we can be reasonably
        # confident this is OK.  If anyone finds how to call the function, all
        # the below could be replaced simply with:
        #
        # from IPython.utils.importstring import import_item
        # return import_item('MIRROR.' + key)

        parts = name.rsplit('.', 1)
        if len(parts) == 2:
            # called with 'foo.bar....'
            package, obj = parts
            module = __import__(package, fromlist=[obj])
            try:
                pak = module.__dict__[obj]
            except KeyError:
                raise AttributeError(obj)
            return pak
        else:
            # called with un-dotted string
            return __import__(parts[0])
{'fraction_non_alphanumeric': 0.08434734513274336, 'fraction_numerical': 0.00165929203539823, 'mean_word_length': 2.2294642857142857, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1432819', 'n_tokens_mistral': 996, 'n_tokens_neox': 956, 'n_words': 387}