1
- import functools
2
- import inspect
3
1
from datetime import timedelta
4
2
from hashlib import sha256
5
3
from logging import getLogger
@@ -58,7 +56,7 @@ def get_cool_off(request: Optional[HttpRequest] = None) -> Optional[timedelta]:
58
56
The return value is either None or timedelta.
59
57
60
58
Notice that the settings.AXES_COOLOFF_TIME is either None, timedelta, integer/float of hours,
61
- a path to a callable or a callable taking zero or 1 argument (the request). This function
59
+ a path to a callable or a callable taking 1 argument (the request). This function
62
60
offers a unified _timedelta or None_ representation of that configuration for use with the
63
61
Axes internal implementations.
64
62
@@ -73,21 +71,13 @@ def get_cool_off(request: Optional[HttpRequest] = None) -> Optional[timedelta]:
73
71
return timedelta (minutes = cool_off * 60 )
74
72
if isinstance (cool_off , str ):
75
73
cool_off_func = import_string (cool_off )
76
- return _maybe_partial ( cool_off_func , request )( )
74
+ return cool_off_func ( request )
77
75
if callable (cool_off ):
78
- return _maybe_partial ( cool_off , request )( ) # pylint: disable=not-callable
76
+ return cool_off ( request ) # pylint: disable=not-callable
79
77
80
78
return cool_off
81
79
82
80
83
- def _maybe_partial (func : Callable , request : Optional [HttpRequest ] = None ):
84
- """Bind the given request to the function if it accepts a single argument."""
85
- sig = inspect .signature (func )
86
- if len (sig .parameters ) == 1 :
87
- return functools .partial (func , request )
88
- return func
89
-
90
-
91
81
def get_cool_off_iso8601 (delta : timedelta ) -> str :
92
82
"""
93
83
Return datetime.timedelta translated to ISO 8601 formatted duration for use in e.g. cool offs.
0 commit comments