From 034adeef2a3e8582135002ee61b38fe7063b4f6e Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Tue, 6 Oct 2020 15:26:59 -0400 Subject: cleanup old python compat -- removed int_types alias --- passlib/crypto/des.py | 9 ++++----- passlib/crypto/digest.py | 10 +++++----- passlib/handlers/argon2.py | 2 +- passlib/pwd.py | 3 +-- passlib/totp.py | 12 ++++++------ passlib/utils/compat/__init__.py | 2 -- passlib/utils/handlers.py | 6 +++--- 7 files changed, 20 insertions(+), 24 deletions(-) (limited to 'passlib') diff --git a/passlib/crypto/des.py b/passlib/crypto/des.py index b473846..fc63ee0 100644 --- a/passlib/crypto/des.py +++ b/passlib/crypto/des.py @@ -47,7 +47,6 @@ The netbsd des-crypt implementation has some nice notes on how this all works - import struct # pkg from passlib import exc -from passlib.utils.compat import int_types # local __all__ = [ "expand_des_key", @@ -612,7 +611,7 @@ def expand_des_key(key): if isinstance(key, bytes): if len(key) != 7: raise ValueError("key must be 7 bytes in size") - elif isinstance(key, int_types): + elif isinstance(key, int): if key < 0 or key > INT_56_MASK: raise ValueError("key must be 56-bit non-negative integer") return _unpack64(expand_des_key(_pack56(key))) @@ -632,7 +631,7 @@ def shrink_des_key(key): if len(key) != 8: raise ValueError("key must be 8 bytes in size") return _pack56(shrink_des_key(_unpack64(key))) - elif isinstance(key, int_types): + elif isinstance(key, int): if key < 0 or key > INT_64_MASK: raise ValueError("key must be 64-bit non-negative integer") else: @@ -746,13 +745,13 @@ def des_encrypt_int_block(key, input, salt=0, rounds=1): raise ValueError("salt must be 24-bit non-negative integer") # validate & unpack key - if not isinstance(key, int_types): + if not isinstance(key, int): raise exc.ExpectedTypeError(key, "int", "key") elif key < 0 or key > INT_64_MASK: raise ValueError("key must be 64-bit non-negative integer") # validate & unpack input - if not isinstance(input, int_types): + if not isinstance(input, int): raise exc.ExpectedTypeError(input, "int", "input") elif input < 0 or input > INT_64_MASK: raise ValueError("input must be 64-bit non-negative integer") diff --git a/passlib/crypto/digest.py b/passlib/crypto/digest.py index 4d2b983..bbcace1 100644 --- a/passlib/crypto/digest.py +++ b/passlib/crypto/digest.py @@ -31,7 +31,7 @@ except ImportError: # pkg from passlib import exc from passlib.utils import join_bytes, to_native_str, to_bytes, SequenceMixin, as_bool -from passlib.utils.compat import int_types, unicode_or_bytes +from passlib.utils.compat import unicode_or_bytes from passlib.utils.decor import memoized_property # local __all__ = [ @@ -735,7 +735,7 @@ def pbkdf1(digest, secret, salt, rounds, keylen=None): salt = to_bytes(salt, param="salt") # validate rounds - if not isinstance(rounds, int_types): + if not isinstance(rounds, int): raise exc.ExpectedTypeError(rounds, "int", "rounds") if rounds < 1: raise ValueError("rounds must be at least 1") @@ -743,7 +743,7 @@ def pbkdf1(digest, secret, salt, rounds, keylen=None): # validate keylen if keylen is None: keylen = digest_size - elif not isinstance(keylen, int_types): + elif not isinstance(keylen, int): raise exc.ExpectedTypeError(keylen, "int or None", "keylen") elif keylen < 0: raise ValueError("keylen must be at least 0") @@ -807,7 +807,7 @@ def pbkdf2_hmac(digest, secret, salt, rounds, keylen=None): digest_size = digest_info.digest_size # validate rounds - if not isinstance(rounds, int_types): + if not isinstance(rounds, int): raise exc.ExpectedTypeError(rounds, "int", "rounds") if rounds < 1: raise ValueError("rounds must be at least 1") @@ -815,7 +815,7 @@ def pbkdf2_hmac(digest, secret, salt, rounds, keylen=None): # validate keylen if keylen is None: keylen = digest_size - elif not isinstance(keylen, int_types): + elif not isinstance(keylen, int): raise exc.ExpectedTypeError(keylen, "int or None", "keylen") elif keylen < 1: # XXX: could allow keylen=0, but want to be compat w/ stdlib diff --git a/passlib/handlers/argon2.py b/passlib/handlers/argon2.py index fb8f90a..5935c3e 100644 --- a/passlib/handlers/argon2.py +++ b/passlib/handlers/argon2.py @@ -516,7 +516,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, @classmethod def _norm_version(cls, version): - if not isinstance(version, uh.int_types): + if not isinstance(version, int): raise uh.exc.ExpectedTypeError(version, "integer", "version") # minimum valid version diff --git a/passlib/pwd.py b/passlib/pwd.py index 821c953..847b90b 100644 --- a/passlib/pwd.py +++ b/passlib/pwd.py @@ -17,7 +17,6 @@ import os # site # pkg from passlib import exc -from passlib.utils.compat import int_types from passlib.utils import rng, getrandstr, to_unicode from passlib.utils.decor import memoized_property # local @@ -303,7 +302,7 @@ class SequenceGenerator(object): """ if returns is None: return next(self) - elif isinstance(returns, int_types): + elif isinstance(returns, int): return [next(self) for _ in range(returns)] elif returns is iter: return self diff --git a/passlib/totp.py b/passlib/totp.py index faea4c0..17ac3bd 100644 --- a/passlib/totp.py +++ b/passlib/totp.py @@ -31,7 +31,7 @@ from passlib.exc import TokenError, MalformedTokenError, InvalidTokenError, Used 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 bascii_to_str, int_types, num_types +from passlib.utils.compat import bascii_to_str, num_types 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 @@ -798,7 +798,7 @@ class TOTP(object): # validate digits if digits is None: digits = self.digits - if not isinstance(digits, int_types): + if not isinstance(digits, int): raise TypeError("digits must be an integer, not a %r" % type(digits)) if digits < 6 or digits > 10: raise ValueError("digits must in range(6,11)") @@ -828,7 +828,7 @@ class TOTP(object): """ check that serial value (e.g. 'counter') is non-negative integer """ - if not isinstance(value, int_types): + if not isinstance(value, int): raise exc.ExpectedTypeError(value, "int", param) if value < minval: raise ValueError("%s must be >= %d" % (param, minval)) @@ -974,7 +974,7 @@ class TOTP(object): :returns: unix epoch timestamp as :class:`int`. """ - if isinstance(time, int_types): + if isinstance(time, int): return time elif isinstance(time, float): return int(time) @@ -1022,7 +1022,7 @@ class TOTP(object): token as :class:`!str`, containing only digits 0-9. """ digits = self_or_cls.digits - if isinstance(token, int_types): + if isinstance(token, int): token = u"%0*d" % (digits, token) else: token = to_unicode(token, param="token") @@ -1089,7 +1089,7 @@ class TOTP(object): :returns: token as unicode string """ # generate digest - assert isinstance(counter, int_types), "counter must be integer" + assert isinstance(counter, int), "counter must be integer" assert counter >= 0, "counter must be non-negative" keyed_hmac = self._keyed_hmac if keyed_hmac is None: diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py index f90d914..06bd266 100644 --- a/passlib/utils/compat/__init__.py +++ b/passlib/utils/compat/__init__.py @@ -37,7 +37,6 @@ def add_doc(obj, doc): __all__ = [ # type detection ## 'is_mapping', - 'int_types', 'num_types', 'unicode_or_bytes', @@ -100,7 +99,6 @@ add_doc(iter_byte_chars, "iterate over byte string as sequence of 1-byte strings # numeric #============================================================================= -int_types = (int,) num_types = (int, float) #============================================================================= diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py index 8c02e69..97ac757 100644 --- a/passlib/utils/handlers.py +++ b/passlib/utils/handlers.py @@ -26,7 +26,7 @@ from passlib.utils.binary import ( HEX_CHARS, UPPER_HEX_CHARS, LOWER_HEX_CHARS, ALL_BYTE_VALUES, ) -from passlib.utils.compat import join_unicode, unicode_or_bytes, int_types +from passlib.utils.compat import join_unicode, unicode_or_bytes from passlib.utils.decor import classproperty, deprecated_method # local __all__ = [ @@ -369,7 +369,7 @@ def norm_integer(handler, value, min=1, max=None, # * :returns: validated value """ # check type - if not isinstance(value, int_types): + if not isinstance(value, int): raise exc.ExpectedTypeError(value, "integer", param) # check minimum @@ -1739,7 +1739,7 @@ class HasRounds(GenericHandler): vary_rounds = int(default_rounds * vary_rounds) # calculate bounds based on default_rounds +/- vary_rounds - assert vary_rounds >= 0 and isinstance(vary_rounds, int_types) + assert vary_rounds >= 0 and isinstance(vary_rounds, int) lower = linear_to_native(default_rounds - vary_rounds, False) upper = linear_to_native(default_rounds + vary_rounds, True) return cls._clip_to_desired_rounds(lower), cls._clip_to_desired_rounds(upper) -- cgit v1.2.1