<commit_before>"""
Django compatibility utils
"""
try:
    from unittest import mock  # NOQA
except ImportError:
    import mock  # NOQA


try:
    # djagno 1.7
    from django.apps import apps
    from django.utils.deconstruct import deconstructible  # NOQA
    from django.utils.module_loading import autodiscover_modules  # NOQA
    from django.utils.module_loading import import_string  # NOQA

    def get_app_package(app_label):
        """
        Return app package string
        """
        app_config = apps.get_app_config(app_label)
        if not app_config:
            return None
        return app_config.module.__name__

    def get_containing_app_data(module):
        """
        Return app label and package string
        """
        app_config = apps.get_containing_app_config(module)
        if not app_config:
            return None, None
        return app_config.label, app_config.module.__name__

    def manager_from_queryset(manager_cls, queryset_class, class_name=None):
        return manager_cls.from_queryset(queryset_class, class_name=class_name)

except ImportError:
    # djagno 1.6 backport
    import inspect
    from django.db.models import loading
    from django.utils import six
    from django.utils.module_loading import import_by_path as import_string  # NOQA

    def get_app_package(app_label):
        app_config = loading.get_app(app_label)
        if not app_config:
            return None
        return app_config.__package__

    def _get_containing_app(object_name):
        candidates = []
        for app_config in loading.get_apps():
            if app_config.__package__ is None:
                app_config.__package__ = app_config.__name__.rpartition('.')[0]

            if object_name.startswith(app_config.__package__):
                subpath = object_name[len(app_config.__package__):]
                if subpath == '' or subpath[0] == '.':
                    candidates.append(app_config)
        if candidates:
            return sorted(candidates, key=lambda ac: -len(ac.__package__))[0]

    def get_containing_app_data(object_name):
        app = _get_containing_app(object_name)
        if app:
            return app.__package__.rsplit('.', 1)[-1], app.__package__
        return None, None

    def deconstructible(cls):
        """
        Deconstructible decorator stub
        """
        return cls
<commit_msg>get_app_package() and get_containing_app_data() fixes for django 1.6<commit_after>"""
Django compatibility utils
"""
try:
    from unittest import mock  # NOQA
except ImportError:
    import mock  # NOQA


try:
    # djagno 1.7
    from django.apps import apps
    from django.utils.deconstruct import deconstructible  # NOQA
    from django.utils.module_loading import autodiscover_modules  # NOQA
    from django.utils.module_loading import import_string  # NOQA

    def get_app_package(app_label):
        """
        Return app package string
        """
        app_config = apps.get_app_config(app_label)
        if not app_config:
            return None
        return app_config.module.__name__

    def get_containing_app_data(module):
        """
        Return app label and package string
        """
        app_config = apps.get_containing_app_config(module)
        if not app_config:
            return None, None
        return app_config.label, app_config.module.__name__

    def manager_from_queryset(manager_cls, queryset_class, class_name=None):
        return manager_cls.from_queryset(queryset_class, class_name=class_name)

except ImportError:
    # djagno 1.6 backport
    import inspect
    from django.db.models import loading
    from django.utils import six
    from django.utils.module_loading import import_by_path as import_string  # NOQA

    def get_app_package(app_label):
        app_config = loading.get_app(app_label)
        if not app_config:
            return None
        if app_config.__package__.endswith('.models'):
            return app_config.__package__[0:-len('.models')]
        return app_config.__package__

    def _get_containing_app_package(object_name):
        candidates = []
        for app_config in loading.get_apps():
            if app_config.__package__ is None:
                app_config.__package__ = app_config.__name__.rpartition('.')[0]

            if app_config.__package__.endswith('.models'):
                package = app_config.__package__[0:-len('.models')]
            else:
                package = app_config.__package__

            if object_name.startswith(package):
                subpath = object_name[len(package):]
                if subpath == '' or subpath[0] == '.':
                    candidates.append(package)
        if candidates:
            return sorted(candidates, key=lambda ac: -len(ac))[0]

    def get_containing_app_data(object_name):
        package = _get_containing_app_package(object_name)
        if package:
            return package.rsplit('.', 1)[-1], package
        return None, None

    def deconstructible(cls):
        """
        Deconstructible decorator stub
        """
        return cls

{'fraction_non_alphanumeric': 0.07904519663470945, 'fraction_numerical': 0.00430444140090002, 'mean_word_length': 2.477551020408163, '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': '5243304', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1439, 'n_words': 337}