<commit_before>from __future__ import absolute_import, unicode_literals

import inspect

from django.apps import AppConfig
from django.conf import settings
from django.core.checks import Error, register
from django.middleware.gzip import GZipMiddleware
from django.utils.module_loading import import_string
from django.utils.translation import ugettext_lazy as _


class DebugToolbarConfig(AppConfig):
    name = 'debug_toolbar'
    verbose_name = _("Debug Toolbar")


@register
def check_middleware(app_configs, **kwargs):
    from debug_toolbar.middleware import DebugToolbarMiddleware

    errors = []
    gzip_index = None
    debug_toolbar_indexes = []

    setting = getattr(settings, 'MIDDLEWARE', None)
    setting_name = 'MIDDLEWARE'
    if setting is None:
        setting = settings.MIDDLEWARE_CLASSES
        setting_name = 'MIDDLEWARE_CLASSES'

    # Determine the indexes which gzip and/or the toolbar are installed at
    for i, middleware in enumerate(setting):
        if is_middleware_class(GZipMiddleware, middleware):
            gzip_index = i
        elif is_middleware_class(DebugToolbarMiddleware, middleware):
            debug_toolbar_indexes.append(i)

    if not debug_toolbar_indexes:
        # If the toolbar does not appear, report an error.
        errors.append(
            Error(
                "debug_toolbar.middleware.DebugToolbarMiddleware is missing "
                "from %s." % setting_name,
                hint="Add debug_toolbar.middleware.DebugToolbarMiddleware to "
                "%s." % setting_name,
            )
        )
    elif len(debug_toolbar_indexes) != 1:
       errors.append(
            Error(
                "debug_toolbar.middleware.DebugToolbarMiddleware occurs "
                "multiple times in %s." % setting_name,
                hint="Load debug_toolbar.middleware.DebugToolbarMiddleware only "
                "once in %s." % setting_name,
            )
        ) 
    elif gzip_index is not None and debug_toolbar_indexes[0] < gzip_index:
        # If the toolbar appears before the gzip index, report an error.
        errors.append(
            Error(
                "debug_toolbar.middleware.DebugToolbarMiddleware occurs before "
                "django.middleware.gzip.GZipMiddleware in %s." % setting_name,
                hint="Move debug_toolbar.middleware.DebugToolbarMiddleware to "
                "after django.middleware.gzip.GZipMiddleware in %s." % setting_name,
            )
        )<commit_msg>Fix flake8 issues<commit_after>from __future__ import absolute_import, unicode_literals

import inspect

from django.apps import AppConfig
from django.conf import settings
from django.core.checks import Error, register
from django.middleware.gzip import GZipMiddleware
from django.utils.module_loading import import_string
from django.utils.translation import ugettext_lazy as _


class DebugToolbarConfig(AppConfig):
    name = 'debug_toolbar'
    verbose_name = _("Debug Toolbar")


@register
def check_middleware(app_configs, **kwargs):
    from debug_toolbar.middleware import DebugToolbarMiddleware

    errors = []
    gzip_index = None
    debug_toolbar_indexes = []

    setting = getattr(settings, 'MIDDLEWARE', None)
    setting_name = 'MIDDLEWARE'
    if setting is None:
        setting = settings.MIDDLEWARE_CLASSES
        setting_name = 'MIDDLEWARE_CLASSES'

    # Determine the indexes which gzip and/or the toolbar are installed at
    for i, middleware in enumerate(setting):
        if is_middleware_class(GZipMiddleware, middleware):
            gzip_index = i
        elif is_middleware_class(DebugToolbarMiddleware, middleware):
            debug_toolbar_indexes.append(i)

    if not debug_toolbar_indexes:
        # If the toolbar does not appear, report an error.
        errors.append(
            Error(
                "debug_toolbar.middleware.DebugToolbarMiddleware is missing "
                "from %s." % setting_name,
                hint="Add debug_toolbar.middleware.DebugToolbarMiddleware to "
                "%s." % setting_name,
            )
        )
    elif len(debug_toolbar_indexes) != 1:
        errors.append(
            Error(
                "debug_toolbar.middleware.DebugToolbarMiddleware occurs "
                "multiple times in %s." % setting_name,
                hint="Load debug_toolbar.middleware.DebugToolbarMiddleware only "
                "once in %s." % setting_name,
            )
        )
    elif gzip_index is not None and debug_toolbar_indexes[0] < gzip_index:
        # If the toolbar appears before the gzip index, report an error.
        errors.append(
            Error(
                "debug_toolbar.middleware.DebugToolbarMiddleware occurs before "
                "django.middleware.gzip.GZipMiddleware in %s." % setting_name,
                hint="Move debug_toolbar.middleware.DebugToolbarMiddleware to "
                "after django.middleware.gzip.GZipMiddleware in %s." % setting_name,
            )
        )
{'fraction_non_alphanumeric': 0.07014028056112225, 'fraction_numerical': 0.001002004008016032, 'mean_word_length': 2.5624553890078516, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6113406', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1361, 'n_words': 344}