summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-10-05 21:06:56 -0400
committerEli Collins <elic@assurancetechnologies.com>2020-10-05 21:06:56 -0400
commit0b6c5bdc88ace23e7f609ef9ef72da92495dddab (patch)
treea32bca412b521f0df3838a73edf058dd0c9a4fd9
parentc62bfc22df2f73aedcd5e88a0dd26c38430be740 (diff)
downloadpasslib-0b6c5bdc88ace23e7f609ef9ef72da92495dddab.tar.gz
passlib.handlers.bcrypt: safe_verify() calls should test for NotImplemented
before boolean; bool(NotImplemented) is deprecated as of python 3.9 (fixes issue 125)
-rw-r--r--docs/history/1.7.rst3
-rw-r--r--passlib/handlers/bcrypt.py24
-rw-r--r--passlib/utils/__init__.py2
3 files changed, 16 insertions, 13 deletions
diff --git a/docs/history/1.7.rst b/docs/history/1.7.rst
index 1e3c1d7..99c5bec 100644
--- a/docs/history/1.7.rst
+++ b/docs/history/1.7.rst
@@ -89,6 +89,9 @@ Other Changes
a load-time error (though they will still receive an error if an attempt is made to actually
*use* a FIPS-disabled hash).
+* Various Python 3.9 compatibility fixes (including ``NotImplemented``-related warning, :issue:`125`)
+
+
**1.7.2** (2019-11-22)
======================
diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py
index b595aaa..5a7ef87 100644
--- a/passlib/handlers/bcrypt.py
+++ b/passlib/handlers/bcrypt.py
@@ -400,21 +400,21 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
#----------------------------------------------------------------
test_hash_20 = b"$2$04$5BJqKfqMQvV7nS.yUguNcuRfMMOXK0xPWavM7pOzjEi5ze5T1k8/S"
result = safe_verify("test", test_hash_20)
- if not result:
- raise RuntimeError("%s incorrectly rejected $2$ hash" % backend)
- elif result is NotImplemented:
+ if result is NotImplemented:
mixin_cls._lacks_20_support = True
log.debug("%r backend lacks $2$ support, enabling workaround", backend)
+ elif not result:
+ raise RuntimeError("%s incorrectly rejected $2$ hash" % backend)
#----------------------------------------------------------------
# check for 2a support
#----------------------------------------------------------------
result = safe_verify("test", TEST_HASH_2A)
- if not result:
- raise RuntimeError("%s incorrectly rejected $2a$ hash" % backend)
- elif result is NotImplemented:
+ if result is NotImplemented:
# 2a support is required, and should always be present
raise RuntimeError("%s lacks support for $2a$ hashes" % backend)
+ elif not result:
+ raise RuntimeError("%s incorrectly rejected $2a$ hash" % backend)
else:
assert_lacks_8bit_bug(IDENT_2A)
if detect_wrap_bug(IDENT_2A):
@@ -438,11 +438,11 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
#----------------------------------------------------------------
test_hash_2y = TEST_HASH_2A.replace("2a", "2y")
result = safe_verify("test", test_hash_2y)
- if not result:
- raise RuntimeError("%s incorrectly rejected $2y$ hash" % backend)
- elif result is NotImplemented:
+ if result is NotImplemented:
mixin_cls._lacks_2y_support = True
log.debug("%r backend lacks $2y$ support, enabling workaround", backend)
+ elif not result:
+ raise RuntimeError("%s incorrectly rejected $2y$ hash" % backend)
else:
# NOTE: Not using this as fallback candidate,
# lacks wide enough support across implementations.
@@ -458,11 +458,11 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
#----------------------------------------------------------------
test_hash_2b = TEST_HASH_2A.replace("2a", "2b")
result = safe_verify("test", test_hash_2b)
- if not result:
- raise RuntimeError("%s incorrectly rejected $2b$ hash" % backend)
- elif result is NotImplemented:
+ if result is NotImplemented:
mixin_cls._lacks_2b_support = True
log.debug("%r backend lacks $2b$ support, enabling workaround", backend)
+ elif not result:
+ raise RuntimeError("%s incorrectly rejected $2b$ hash" % backend)
else:
mixin_cls._fallback_ident = IDENT_2B
assert_lacks_8bit_bug(IDENT_2B)
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index 9f9f3ed..fd30b3e 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -144,7 +144,7 @@ class SequenceMixin(object):
subclass just needs to provide :meth:`_as_tuple()`.
"""
def _as_tuple(self):
- raise NotImplemented("implement in subclass")
+ raise NotImplementedError("implement in subclass")
def __repr__(self):
return repr(self._as_tuple())