# Path: axes/conf.py

# 
# Path: axes/helpers.py
# def get_failure_limit(request, credentials) -> int:
#     if callable(settings.AXES_FAILURE_LIMIT):
#         return settings.AXES_FAILURE_LIMIT(  # pylint: disable=not-callable
#             request, credentials
#         )
#     if isinstance(settings.AXES_FAILURE_LIMIT, str):
#         return import_string(settings.AXES_FAILURE_LIMIT)(request, credentials)
#     if isinstance(settings.AXES_FAILURE_LIMIT, int):
#         return settings.AXES_FAILURE_LIMIT
#     raise TypeError("settings.AXES_FAILURE_LIMIT needs to be a callable or an integer")
# 
# def is_client_ip_address_blacklisted(request) -> bool:
#     """
#     Check if the given request refers to a blacklisted IP.
#     """
# 
#     if is_ip_address_in_blacklist(request.axes_ip_address):
#         return True
# 
#     if settings.AXES_ONLY_WHITELIST and not is_ip_address_in_whitelist(
#         request.axes_ip_address
#     ):
#         return True
# 
#     return False
# 
# def is_client_ip_address_whitelisted(request):
#     """
#     Check if the given request refers to a whitelisted IP.
#     """
# 
#     if settings.AXES_NEVER_LOCKOUT_WHITELIST and is_ip_address_in_whitelist(
#         request.axes_ip_address
#     ):
#         return True
# 
#     if settings.AXES_ONLY_WHITELIST and is_ip_address_in_whitelist(
#         request.axes_ip_address
#     ):
#         return True
# 
#     return False
# 
# def is_client_method_whitelisted(request) -> bool:
#     """
#     Check if the given request uses a whitelisted method.
#     """
# 
#     if settings.AXES_NEVER_LOCKOUT_GET and request.method == "GET":
#         return True
# 
#     return False
# 
# def is_user_attempt_whitelisted(request, credentials: dict = None) -> bool:
#     """
#     Check if the given request or credentials refer to a whitelisted username.
# 
#     This method invokes the ``settings.AXES_WHITELIST`` callable
#     with ``request`` and ``credentials`` arguments.
# 
#     This function could use the following implementation for checking
#     the lockout flags from a specific property in the user object:
# 
#     .. code-block: python
# 
#        username_value = get_client_username(request, credentials)
#        username_field = getattr(
#            get_user_model(),
#            "USERNAME_FIELD",
#            "username"
#        )
#        kwargs = {username_field: username_value}
# 
#        user_model = get_user_model()
#        user = user_model.objects.get(**kwargs)
#        return user.nolockout
#     """
# 
#     whitelist_callable = settings.AXES_WHITELIST_CALLABLE
#     if whitelist_callable is None:
#         return False
#     if callable(whitelist_callable):
#         return whitelist_callable(request, credentials)  # pylint: disable=not-callable
#     if isinstance(whitelist_callable, str):
#         return import_string(whitelist_callable)(request, credentials)
# 
#     raise TypeError(
#         "settings.AXES_WHITELIST_CALLABLE needs to be a string, callable, or None."
#     )


import re
from abc import ABC, abstractmethod
from django.urls import reverse
from django.urls.exceptions import NoReverseMatch
from axes.conf import settings
from axes.helpers import (
    get_failure_limit,
    is_client_ip_address_blacklisted,
    is_client_ip_address_whitelisted,
    is_client_method_whitelisted,
    is_user_attempt_whitelisted,
)
        This method is abstract and other backends can specialize it as needed, but the default implementation
        checks if the user has attempted to authenticate into the site too many times through the
        Django authentication backends and returns ``False`` if user exceeds the configured Axes thresholds.

        This checker can implement arbitrary checks such as IP whitelisting or blacklisting,
        request frequency checking, failed attempt monitoring or similar functions.

        Please refer to the ``axes.handlers.database.AxesDatabaseHandler`` for the default implementation
        and inspiration on some common checks and access restrictions before writing your own implementation.
        """

        if self.is_admin_site(request):
            return True

        if self.is_blacklisted(request, credentials):
            return False

        if self.is_whitelisted(request, credentials):
            return True

        if self.is_locked(request, credentials):
            return False

        return True

    def is_blacklisted(self, request, credentials: dict = None) -> bool:
        """
        Checks if the request or given credentials are blacklisted from access.
        """


# Path: axes/conf.py

# 
# Path: axes/helpers.py
# def get_failure_limit(request, credentials) -> int:
#     if callable(settings.AXES_FAILURE_LIMIT):
#         return settings.AXES_FAILURE_LIMIT(  # pylint: disable=not-callable
#             request, credentials
#         )
#     if isinstance(settings.AXES_FAILURE_LIMIT, str):
#         return import_string(settings.AXES_FAILURE_LIMIT)(request, credentials)
#     if isinstance(settings.AXES_FAILURE_LIMIT, int):
#         return settings.AXES_FAILURE_LIMIT
#     raise TypeError("settings.AXES_FAILURE_LIMIT needs to be a callable or an integer")
# 
# def is_client_ip_address_blacklisted(request) -> bool:
#     """
#     Check if the given request refers to a blacklisted IP.
#     """
# 
#     if is_ip_address_in_blacklist(request.axes_ip_address):
#         return True
# 
#     if settings.AXES_ONLY_WHITELIST and not is_ip_address_in_whitelist(
#         request.axes_ip_address
#     ):
#         return True
# 
#     return False
# 
# def is_client_ip_address_whitelisted(request):
#     """
#     Check if the given request refers to a whitelisted IP.
#     """
# 
#     if settings.AXES_NEVER_LOCKOUT_WHITELIST and is_ip_address_in_whitelist(
#         request.axes_ip_address
#     ):
#         return True
# 
#     if settings.AXES_ONLY_WHITELIST and is_ip_address_in_whitelist(
#         request.axes_ip_address
#     ):
#         return True
# 
#     return False
# 
# def is_client_method_whitelisted(request) -> bool:
#     """
#     Check if the given request uses a whitelisted method.
#     """
# 
#     if settings.AXES_NEVER_LOCKOUT_GET and request.method == "GET":
#         return True
# 
#     return False
# 
# def is_user_attempt_whitelisted(request, credentials: dict = None) -> bool:
#     """
#     Check if the given request or credentials refer to a whitelisted username.
# 
#     This method invokes the ``settings.AXES_WHITELIST`` callable
#     with ``request`` and ``credentials`` arguments.
# 
#     This function could use the following implementation for checking
#     the lockout flags from a specific property in the user object:
# 
#     .. code-block: python
# 
#        username_value = get_client_username(request, credentials)
#        username_field = getattr(
#            get_user_model(),
#            "USERNAME_FIELD",
#            "username"
#        )
#        kwargs = {username_field: username_value}
# 
#        user_model = get_user_model()
#        user = user_model.objects.get(**kwargs)
#        return user.nolockout
#     """
# 
#     whitelist_callable = settings.AXES_WHITELIST_CALLABLE
#     if whitelist_callable is None:
#         return False
#     if callable(whitelist_callable):
#         return whitelist_callable(request, credentials)  # pylint: disable=not-callable
#     if isinstance(whitelist_callable, str):
#         return import_string(whitelist_callable)(request, credentials)
# 
#     raise TypeError(
#         "settings.AXES_WHITELIST_CALLABLE needs to be a string, callable, or None."
#     )


# Path: axes/handlers/base.py
import re
from abc import ABC, abstractmethod
from django.urls import reverse
from django.urls.exceptions import NoReverseMatch
from axes.conf import settings
from axes.helpers import (
    get_failure_limit,
    is_client_ip_address_blacklisted,
    is_client_ip_address_whitelisted,
    is_client_method_whitelisted,
    is_user_attempt_whitelisted,
)

        This method is abstract and other backends can specialize it as needed, but the default implementation
        checks if the user has attempted to authenticate into the site too many times through the
        Django authentication backends and returns ``False`` if user exceeds the configured Axes thresholds.

        This checker can implement arbitrary checks such as IP whitelisting or blacklisting,
        request frequency checking, failed attempt monitoring or similar functions.

        Please refer to the ``axes.handlers.database.AxesDatabaseHandler`` for the default implementation
        and inspiration on some common checks and access restrictions before writing your own implementation.
        """

        if self.is_admin_site(request):
            return True

        if self.is_blacklisted(request, credentials):
            return False

        if self.is_whitelisted(request, credentials):
            return True

        if self.is_locked(request, credentials):
            return False

        return True

    def is_blacklisted(self, request, credentials: dict = None) -> bool:
        """
        Checks if the request or given credentials are blacklisted from access.
        """


        if is_client_ip_address_blacklisted(request):