mirror of
https://github.com/jazzband/django-defender.git
synced 2026-03-16 22:10:32 +00:00
remove_prefix method working same for all python versions
This commit is contained in:
parent
d90dfa8db7
commit
a4b3f9f332
2 changed files with 6 additions and 7 deletions
|
|
@ -1176,3 +1176,6 @@ class TestUtils(DefenderTestCase):
|
|||
"defender:blocked:ip:192.168.24.24", "defender:blocked:"), "ip:192.168.24.24")
|
||||
self.assertEqual(utils.remove_prefix(
|
||||
"defender:blocked:username:johndoe", "defender:blocked:"), "username:johndoe")
|
||||
self.assertEqual(utils.remove_prefix(
|
||||
"defender:blocked:username:johndoe", "blocked:username:"),
|
||||
"defender:blocked:username:johndoe")
|
||||
|
|
|
|||
|
|
@ -129,14 +129,10 @@ def get_username_blocked_cache_key(username):
|
|||
|
||||
|
||||
def remove_prefix(string, prefix):
|
||||
if string.startswith(prefix):
|
||||
return string[len(prefix):]
|
||||
return string
|
||||
|
||||
# backwards compatibility for str.removeprefix for python < 3.9
|
||||
if sys.version_info < (3, 9):
|
||||
if string.startswith(prefix):
|
||||
return string[len(prefix) :]
|
||||
return string
|
||||
|
||||
return string.removeprefix(prefix)
|
||||
|
||||
|
||||
def strip_keys(key_list):
|
||||
|
|
|
|||
Loading…
Reference in a new issue