<commit_before>from http import HTTPStatus

from django.conf import settings as django_settings
from django.contrib.auth import REDIRECT_FIELD_NAME, authenticate, login
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import resolve_url
from django.utils.http import url_has_allowed_host_and_scheme  # private API
from django.views.generic import View

from . import settings

try:
    from django.contrib.auth.views import RedirectURLMixin  # private API
except ImportError:  # Django < 4.1
    # Added to Django in https://github.com/django/django/pull/15608
    class RedirectURLMixin:
        next_page = None
        redirect_field_name = REDIRECT_FIELD_NAME
        success_url_allowed_hosts = set()

        def get_success_url(self):
            return self.get_redirect_url() or self.get_default_redirect_url()

        def get_redirect_url(self):
            """Return the user-originating redirect URL if it's safe."""
            redirect_to = self.request.POST.get(
                self.redirect_field_name, self.request.GET.get(self.redirect_field_name)
            )
            url_is_safe = url_has_allowed_host_and_scheme(
                url=redirect_to,
                allowed_hosts=self.get_success_url_allowed_hosts(),
                require_https=self.request.is_secure(),
            )
            return redirect_to if url_is_safe else ""

        def get_success_url_allowed_hosts(self):
            return {self.request.get_host(), *self.success_url_allowed_hosts}

        def get_default_redirect_url(self):
            """Return the default redirect URL."""
            if self.next_page:
                return resolve_url(self.next_page)
            else:  # pragma: no cover
                raise ImproperlyConfigured(
                    "no URL to redirect to; provide a next_page"
                )


__all__ = ["LoginView"]


class LoginView(RedirectURLMixin, View):
<commit_msg>Apply black formatting.<commit_after>from http import HTTPStatus

from django.conf import settings as django_settings
from django.contrib.auth import REDIRECT_FIELD_NAME, authenticate, login
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import resolve_url
from django.utils.http import url_has_allowed_host_and_scheme  # private API
from django.views.generic import View

from . import settings

try:
    from django.contrib.auth.views import RedirectURLMixin  # private API
except ImportError:  # Django < 4.1
    # Added to Django in https://github.com/django/django/pull/15608
    class RedirectURLMixin:
        next_page = None
        redirect_field_name = REDIRECT_FIELD_NAME
        success_url_allowed_hosts = set()

        def get_success_url(self):
            return self.get_redirect_url() or self.get_default_redirect_url()

        def get_redirect_url(self):
            """Return the user-originating redirect URL if it's safe."""
            redirect_to = self.request.POST.get(
                self.redirect_field_name, self.request.GET.get(self.redirect_field_name)
            )
            url_is_safe = url_has_allowed_host_and_scheme(
                url=redirect_to,
                allowed_hosts=self.get_success_url_allowed_hosts(),
                require_https=self.request.is_secure(),
            )
            return redirect_to if url_is_safe else ""

        def get_success_url_allowed_hosts(self):
            return {self.request.get_host(), *self.success_url_allowed_hosts}

        def get_default_redirect_url(self):
            """Return the default redirect URL."""
            if self.next_page:
                return resolve_url(self.next_page)
            else:  # pragma: no cover
                raise ImproperlyConfigured("no URL to redirect to; provide a next_page")


__all__ = ["LoginView"]


class LoginView(RedirectURLMixin, View):

{'fraction_non_alphanumeric': 0.07039800995024875, 'fraction_numerical': 0.003482587064676617, 'mean_word_length': 2.844168260038241, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7444872', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1090, 'n_words': 265}