diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 14:39:13 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 14:39:13 -0400 |
commit | ab0b14e8b2178160b1279d2a0679b8d9149cfe55 (patch) | |
tree | c5f80ad16e026ea5506343263fa5ea961fd7ce70 | |
parent | f5da8e35044119040776cb5564d4a5f82de9928d (diff) | |
download | passlib-ab0b14e8b2178160b1279d2a0679b8d9149cfe55.tar.gz |
cleanup old python compat -- removed suppress_cause() and error_from() wrappers
-rw-r--r-- | passlib/crypto/digest.py | 2 | ||||
-rw-r--r-- | passlib/handlers/bcrypt.py | 6 | ||||
-rw-r--r-- | passlib/handlers/des_crypt.py | 6 | ||||
-rw-r--r-- | passlib/handlers/scrypt.py | 6 | ||||
-rw-r--r-- | passlib/tests/test_ext_django_source.py | 7 | ||||
-rw-r--r-- | passlib/totp.py | 4 | ||||
-rw-r--r-- | passlib/utils/__init__.py | 2 | ||||
-rw-r--r-- | passlib/utils/binary.py | 7 | ||||
-rw-r--r-- | passlib/utils/compat/__init__.py | 14 |
9 files changed, 18 insertions, 36 deletions
diff --git a/passlib/crypto/digest.py b/passlib/crypto/digest.py index eb37e6f..4f7bc97 100644 --- a/passlib/crypto/digest.py +++ b/passlib/crypto/digest.py @@ -32,7 +32,7 @@ except ImportError: from passlib import exc from passlib.utils import join_bytes, to_native_str, join_byte_values, to_bytes, \ SequenceMixin, as_bool -from passlib.utils.compat import int_types, unicode_or_bytes_types, error_from +from passlib.utils.compat import int_types, unicode_or_bytes_types from passlib.utils.decor import memoized_property # local __all__ = [ diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py index dda7433..762b7ee 100644 --- a/passlib/handlers/bcrypt.py +++ b/passlib/handlers/bcrypt.py @@ -29,7 +29,7 @@ from passlib.utils import safe_crypt, repeat_string, to_bytes, parse_version, \ rng, getrandstr, test_crypt, to_unicode, \ utf8_truncate, utf8_repeat_string, crypt_accepts_bytes from passlib.utils.binary import bcrypt64 -from passlib.utils.compat import uascii_to_str, unicode, str_to_uascii, error_from +from passlib.utils.compat import uascii_to_str, unicode, str_to_uascii import passlib.utils.handlers as uh # local @@ -812,10 +812,10 @@ class _OsCryptBackend(_BcryptCommon): try: secret.decode("utf-8") except UnicodeDecodeError: - raise error_from(uh.exc.PasswordValueError( + raise uh.exc.PasswordValueError( "python3 crypt.crypt() ony supports bytes passwords using UTF8; " "passlib recommends running `pip install bcrypt` for general bcrypt support.", - ), None) + ) from None # # else crypt() call failed for unknown reason. diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py index 3c7bb7e..80a9ec2 100644 --- a/passlib/handlers/des_crypt.py +++ b/passlib/handlers/des_crypt.py @@ -10,7 +10,7 @@ from warnings import warn # pkg from passlib.utils import safe_crypt, test_crypt, to_unicode from passlib.utils.binary import h64, h64big -from passlib.utils.compat import byte_elem_value, u, uascii_to_str, unicode, suppress_cause +from passlib.utils.compat import byte_elem_value, u, uascii_to_str, unicode from passlib.crypto.des import des_encrypt_int_block import passlib.utils.handlers as uh # local @@ -579,8 +579,8 @@ class crypt16(uh.TruncateMixin, uh.HasSalt, uh.GenericHandler): # parse salt value try: salt_value = h64.decode_int12(self.salt.encode("ascii")) - except ValueError: # pragma: no cover - caught by class - raise suppress_cause(ValueError("invalid chars in salt")) + except ValueError: # pragma: no cover - caught by class + raise ValueError("invalid chars in salt") from None # convert first 8 byts of secret string into an integer, key1 = _crypt_secret_to_key(secret) diff --git a/passlib/handlers/scrypt.py b/passlib/handlers/scrypt.py index 57b921e..f3113dd 100644 --- a/passlib/handlers/scrypt.py +++ b/passlib/handlers/scrypt.py @@ -9,7 +9,7 @@ import logging; log = logging.getLogger(__name__) from passlib.crypto import scrypt as _scrypt from passlib.utils import h64, to_bytes from passlib.utils.binary import h64, b64s_decode, b64s_encode -from passlib.utils.compat import bascii_to_str, suppress_cause +from passlib.utils.compat import bascii_to_str from passlib.utils.decor import classproperty import passlib.utils.handlers as uh # local @@ -163,7 +163,7 @@ class scrypt(uh.ParallelismMixin, uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum try: _scrypt.validate(1 << cls.default_rounds, cls.block_size, cls.parallelism) except ValueError as err: - raise suppress_cause(ValueError("scrypt: invalid settings combination: " + str(err))) + raise ValueError("scrypt: invalid settings combination: " + str(err)) from None return subcls @@ -287,7 +287,7 @@ class scrypt(uh.ParallelismMixin, uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum try: salt.decode("ascii") except UnicodeDecodeError: - raise suppress_cause(NotImplementedError("scrypt $7$ hashes dont support non-ascii salts")) + raise NotImplementedError("scrypt $7$ hashes dont support non-ascii salts") from None return bascii_to_str(b"".join([ b"$7$", h64.encode_int6(self.rounds), diff --git a/passlib/tests/test_ext_django_source.py b/passlib/tests/test_ext_django_source.py index 49d66cb..cc8c25f 100644 --- a/passlib/tests/test_ext_django_source.py +++ b/passlib/tests/test_ext_django_source.py @@ -8,7 +8,6 @@ test passlib.ext.django against django source tests import logging; log = logging.getLogger(__name__) # site # pkg -from passlib.utils.compat import suppress_cause from passlib.ext.django.utils import DJANGO_VERSION, DjangoTranslator, _PasslibHasherWrapper # tests from passlib.tests.utils import TestCase, TEST_MODE @@ -59,10 +58,8 @@ elif has_min_django: try: from auth_tests import test_hashers as test_hashers_mod except ImportError as err: - raise suppress_cause( - EnvironmentError("error trying to import django tests " - "from source path (%r): %r" % - (source_path, err))) + raise EnvironmentError("error trying to import django tests " + "from source path (%r): %r" % (source_path, err)) from None finally: sys.path.remove(tests_path) diff --git a/passlib/totp.py b/passlib/totp.py index 73605f2..b60284b 100644 --- a/passlib/totp.py +++ b/passlib/totp.py @@ -32,7 +32,7 @@ from passlib.utils import (to_unicode, to_bytes, consteq, getrandbytes, rng, SequenceMixin, xor_bytes, getrandstr) from passlib.utils.binary import BASE64_CHARS, b32encode, b32decode from passlib.utils.compat import (u, unicode, native_string_types, bascii_to_str, int_types, num_types, - byte_elem_value, UnicodeIO, suppress_cause) + byte_elem_value, UnicodeIO) from passlib.utils.decor import hybrid_method, memoized_property from passlib.crypto.digest import lookup_hash, compile_hmac, pbkdf2_hmac from passlib.hash import pbkdf2_sha256 @@ -358,7 +358,7 @@ class AppWallet(object): try: return secrets[tag] except KeyError: - raise suppress_cause(KeyError("unknown secret tag: %r" % (tag,))) + raise KeyError("unknown secret tag: %r" % (tag,)) from None #======================================================================== # encrypted key helpers -- used internally by TOTP diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index df4daf0..d6c61a0 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -65,7 +65,7 @@ from passlib.utils.compat import (add_doc, join_bytes, join_byte_values, join_byte_elems, join_unicode, unicode, byte_elem_value, unicode_or_str, unicode_or_bytes_types, - get_method_function, suppress_cause, PYPY) + get_method_function, PYPY) # local __all__ = [ # constants diff --git a/passlib/utils/binary.py b/passlib/utils/binary.py index e5bdf2b..813d5cc 100644 --- a/passlib/utils/binary.py +++ b/passlib/utils/binary.py @@ -20,7 +20,6 @@ from passlib import exc from passlib.utils.compat import ( bascii_to_str, iter_byte_chars, join_byte_values, join_byte_elems, - suppress_cause, unicode, unicode_or_bytes_types, ) from passlib.utils.decor import memoized_property @@ -156,7 +155,7 @@ def b64s_decode(data): try: data = data.encode("ascii") except UnicodeEncodeError: - raise suppress_cause(ValueError("string argument should contain only ASCII characters")) + raise ValueError("string argument should contain only ASCII characters") from None off = len(data) & 3 if off == 0: pass @@ -169,7 +168,7 @@ def b64s_decode(data): try: return a2b_base64(data) except _BinAsciiError as err: - raise suppress_cause(TypeError(err)) + raise TypeError(err) from None #============================================================================= # adapted-base64 encoding @@ -202,7 +201,7 @@ def ab64_decode(data): try: data = data.encode("ascii") except UnicodeEncodeError: - raise suppress_cause(ValueError("string argument should contain only ASCII characters")) + raise ValueError("string argument should contain only ASCII characters") from None return b64s_decode(data.replace(b".", b"+")) #============================================================================= diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py index e582e0d..32cd777 100644 --- a/passlib/utils/compat/__init__.py +++ b/passlib/utils/compat/__init__.py @@ -178,20 +178,6 @@ def get_method_function(func): """given (potential) method, return underlying function""" return getattr(func, "__func__", func) -def error_from(exc, # *, - cause=None): - """ - backward compat hack to suppress exception cause in python3.3+ - - one python < 3.3 support is dropped, can replace all uses with "raise exc from None" - """ - exc.__cause__ = cause - exc.__suppress_context__ = True - return exc - -# legacy alias -suppress_cause = error_from - #============================================================================= # input/output #============================================================================= |