mirror of
https://github.com/jazzband/django-axes.git
synced 2026-03-16 22:30:23 +00:00
Make code Black's compliant.
This commit is contained in:
parent
f772817bc8
commit
45109341be
5 changed files with 14 additions and 15 deletions
|
|
@ -51,7 +51,7 @@ class AbstractAxesHandler(ABC):
|
|||
raise NotImplementedError("get_failures should be implemented")
|
||||
|
||||
|
||||
class AxesBaseHandler:
|
||||
class AxesBaseHandler: # pylint: disable=unused-argument
|
||||
"""
|
||||
Handler API definition for implementations that are used by the ``AxesProxyHandler``.
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ class AxesBaseHandler:
|
|||
|
||||
return True
|
||||
|
||||
def is_blacklisted(self, request, credentials: dict = None) -> bool: # pylint: disable=unused-argument
|
||||
def is_blacklisted(self, request, credentials: dict = None) -> bool:
|
||||
"""
|
||||
Checks if the request or given credentials are blacklisted from access.
|
||||
"""
|
||||
|
|
@ -104,7 +104,7 @@ class AxesBaseHandler:
|
|||
|
||||
return False
|
||||
|
||||
def is_whitelisted(self, request, credentials: dict = None) -> bool: # pylint: disable=unused-argument
|
||||
def is_whitelisted(self, request, credentials: dict = None) -> bool:
|
||||
"""
|
||||
Checks if the request or given credentials are whitelisted for access.
|
||||
"""
|
||||
|
|
@ -127,9 +127,9 @@ class AxesBaseHandler:
|
|||
|
||||
if settings.AXES_LOCK_OUT_AT_FAILURE:
|
||||
# get_failures will have to be implemented by each specialized handler
|
||||
return self.get_failures(request, credentials) >= get_failure_limit( # type: ignore
|
||||
return self.get_failures( # type: ignore
|
||||
request, credentials
|
||||
)
|
||||
) >= get_failure_limit(request, credentials)
|
||||
|
||||
return False
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ class AxesBaseHandler:
|
|||
|
||||
return False
|
||||
|
||||
def reset_attempts(self, *, ip_address: str = None, username: str = None) -> int: # pylint: disable=unused-argument
|
||||
def reset_attempts(self, *, ip_address: str = None, username: str = None) -> int:
|
||||
"""
|
||||
Resets access attempts that match the given IP address or username.
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ class AxesBaseHandler:
|
|||
"""
|
||||
return 0
|
||||
|
||||
def reset_logs(self, *, age_days: int = None) -> int: # pylint: disable=unused-argument
|
||||
def reset_logs(self, *, age_days: int = None) -> int:
|
||||
"""
|
||||
Resets access logs that are older than given number of days.
|
||||
|
||||
|
|
@ -169,10 +169,11 @@ class AxesBaseHandler:
|
|||
return 0
|
||||
|
||||
|
||||
class AxesHandler(AbstractAxesHandler, AxesBaseHandler): # pylint: disable=unused-argument
|
||||
class AxesHandler(AbstractAxesHandler, AxesBaseHandler):
|
||||
"""
|
||||
Signal bare handler implementation without any storage backend.
|
||||
"""
|
||||
|
||||
def user_login_failed(self, sender, credentials: dict, request=None, **kwargs):
|
||||
pass
|
||||
|
||||
|
|
@ -183,4 +184,4 @@ class AxesHandler(AbstractAxesHandler, AxesBaseHandler): # pylint: disable=unuse
|
|||
pass
|
||||
|
||||
def get_failures(self, request, credentials: dict = None) -> int:
|
||||
return 0
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from axes.helpers import (
|
|||
log = getLogger(settings.AXES_LOGGER)
|
||||
|
||||
|
||||
class AxesCacheHandler(AbstractAxesHandler, AxesBaseHandler): # pylint: disable=too-many-locals
|
||||
class AxesCacheHandler(AbstractAxesHandler, AxesBaseHandler):
|
||||
"""
|
||||
Signal handler implementation that records user login attempts to cache and locks users out if necessary.
|
||||
"""
|
||||
|
|
@ -25,7 +25,6 @@ class AxesCacheHandler(AbstractAxesHandler, AxesBaseHandler): # pylint: disable
|
|||
self.cache = get_cache()
|
||||
self.cache_timeout = get_cache_timeout()
|
||||
|
||||
|
||||
def get_failures(self, request, credentials: dict = None) -> int:
|
||||
cache_key = get_client_cache_key(request, credentials)
|
||||
return self.cache.get(cache_key, default=0)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ from axes.helpers import (
|
|||
log = getLogger(settings.AXES_LOGGER)
|
||||
|
||||
|
||||
class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler): # pylint: disable=too-many-locals
|
||||
class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler):
|
||||
"""
|
||||
Signal handler implementation that records user login attempts to database and locks users out if necessary.
|
||||
|
||||
|
|
@ -250,4 +250,4 @@ class AxesDatabaseHandler(AbstractAxesHandler, AxesBaseHandler): # pylint: disa
|
|||
|
||||
When needed, all post_delete actions for this backend should be located
|
||||
here.
|
||||
"""
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from axes.handlers.base import AxesBaseHandler, AbstractAxesHandler
|
||||
|
||||
|
||||
class AxesDummyHandler(AbstractAxesHandler, AxesBaseHandler): # pylint: disable=unused-argument
|
||||
class AxesDummyHandler(AbstractAxesHandler, AxesBaseHandler):
|
||||
"""
|
||||
Signal handler implementation that does nothing and can be used to disable signal processing.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ from axes.tests.base import AxesTestCase
|
|||
|
||||
@override_settings(AXES_HANDLER="axes.handlers.base.AxesHandler")
|
||||
class AxesHandlerTestCase(AxesTestCase):
|
||||
|
||||
@override_settings(AXES_IP_BLACKLIST=["127.0.0.1"])
|
||||
def test_is_allowed_with_blacklisted_ip_address(self):
|
||||
self.assertFalse(AxesProxyHandler.is_allowed(self.request))
|
||||
|
|
|
|||
Loading…
Reference in a new issue