diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 14:52:34 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 14:52:34 -0400 |
commit | 56017e683f8e31be252c94f23d4dd22a2d5603f9 (patch) | |
tree | 1893084b022faa3fe179cffef5537be202ff62d4 | |
parent | e82f75c13f9815f82b0cf046b2a502925f194703 (diff) | |
download | passlib-56017e683f8e31be252c94f23d4dd22a2d5603f9.tar.gz |
cleanup old python compat -- unified "unicode_or_bytes" aliases
-rw-r--r-- | passlib/context.py | 10 | ||||
-rw-r--r-- | passlib/crypto/digest.py | 4 | ||||
-rw-r--r-- | passlib/handlers/misc.py | 4 | ||||
-rw-r--r-- | passlib/utils/__init__.py | 4 | ||||
-rw-r--r-- | passlib/utils/binary.py | 4 | ||||
-rw-r--r-- | passlib/utils/compat/__init__.py | 14 | ||||
-rw-r--r-- | passlib/utils/handlers.py | 4 |
7 files changed, 18 insertions, 26 deletions
diff --git a/passlib/context.py b/passlib/context.py index 6195d1b..3c82519 100644 --- a/passlib/context.py +++ b/passlib/context.py @@ -21,7 +21,7 @@ from passlib.utils import (handlers as uh, to_bytes, from passlib.utils.binary import BASE64_CHARS from passlib.utils.compat import (num_types, unicode, - unicode_or_bytes_types, + unicode_or_bytes, ) from passlib.utils.decor import deprecated_method, memoized_property # local @@ -601,7 +601,7 @@ class _CryptConfig(object): # unique identifiers will work properly in a CryptContext. # XXX: if all handlers have a unique prefix (e.g. all are MCF / LDAP), # could use dict-lookup to speed up this search. - if not isinstance(hash, unicode_or_bytes_types): + if not isinstance(hash, unicode_or_bytes): raise ExpectedStringError(hash, "hash") # type check of category - handled by _get_record_list() for record in self._get_record_list(category): @@ -767,7 +767,7 @@ class CryptContext(object): .. seealso:: :meth:`to_string`, the inverse of this constructor. """ - if not isinstance(source, unicode_or_bytes_types): + if not isinstance(source, unicode_or_bytes): raise ExpectedTypeError(source, "unicode or bytes", "source") self = cls(_autoload=False) self.load(source, section=section, encoding=encoding) @@ -965,7 +965,7 @@ class CryptContext(object): # autodetect source type, convert to dict #----------------------------------------------------------- parse_keys = True - if isinstance(source, unicode_or_bytes_types): + if isinstance(source, unicode_or_bytes): source = to_unicode(source, encoding, param="source") source = self._parse_ini_stream(StringIO(source), section, "<string passed to CryptContext.load()>") @@ -1406,7 +1406,7 @@ class CryptContext(object): def _get_or_identify_record(self, hash, scheme=None, category=None): """return record based on scheme, or failing that, by identifying hash""" if scheme: - if not isinstance(hash, unicode_or_bytes_types): + if not isinstance(hash, unicode_or_bytes): raise ExpectedStringError(hash, "hash") return self._get_record(scheme, category) else: diff --git a/passlib/crypto/digest.py b/passlib/crypto/digest.py index 4f7bc97..7a4fbe2 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 +from passlib.utils.compat import int_types, unicode_or_bytes from passlib.utils.decor import memoized_property # local __all__ = [ @@ -292,7 +292,7 @@ def lookup_hash(digest, # *, # resolve ``digest`` to ``const`` & ``name_record`` cache_by_name = True - if isinstance(digest, unicode_or_bytes_types): + if isinstance(digest, unicode_or_bytes): # normalize name name_list = _get_hash_aliases(digest) name = name_list[0] diff --git a/passlib/handlers/misc.py b/passlib/handlers/misc.py index 8644fee..289731a 100644 --- a/passlib/handlers/misc.py +++ b/passlib/handlers/misc.py @@ -10,7 +10,7 @@ from warnings import warn # site # pkg from passlib.utils import to_native_str, str_consteq -from passlib.utils.compat import unicode, unicode_or_bytes_types +from passlib.utils.compat import unicode, unicode_or_bytes import passlib.utils.handlers as uh # local __all__ = [ @@ -176,7 +176,7 @@ class plaintext(uh.MinimalHandler): @classmethod def identify(cls, hash): - if isinstance(hash, unicode_or_bytes_types): + if isinstance(hash, unicode_or_bytes): return True else: raise uh.exc.ExpectedStringError(hash, "hash") diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index 9ad8f00..b06ba57 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -64,7 +64,7 @@ from passlib.exc import ExpectedStringError, ExpectedTypeError from passlib.utils.compat import (add_doc, join_bytes, join_byte_values, join_byte_elems, join_unicode, unicode, byte_elem_value, - unicode_or_bytes_types, + unicode_or_bytes, get_method_function, PYPY) # local __all__ = [ @@ -790,7 +790,7 @@ def as_bool(value, none=None, param="boolean"): recognizes strings such as "true", "false" """ assert none in [True, False, None] - if isinstance(value, unicode_or_bytes_types): + if isinstance(value, unicode_or_bytes): clean = value.lower().strip() if clean in _true_set: return True diff --git a/passlib/utils/binary.py b/passlib/utils/binary.py index 813d5cc..5c55477 100644 --- a/passlib/utils/binary.py +++ b/passlib/utils/binary.py @@ -20,7 +20,7 @@ from passlib import exc from passlib.utils.compat import ( bascii_to_str, iter_byte_chars, join_byte_values, join_byte_elems, - unicode, unicode_or_bytes_types, + unicode, unicode_or_bytes, ) from passlib.utils.decor import memoized_property # from passlib.utils import BASE64_CHARS, HASH64_CHARS @@ -126,7 +126,7 @@ def compile_byte_translation(mapping, source=None): assert isinstance(source, bytes) and len(source) == 255 target = list(iter_byte_chars(source)) for k, v in mapping.items(): - if isinstance(k, unicode_or_bytes_types): + if isinstance(k, unicode_or_bytes): k = ord(k) assert isinstance(k, int) and 0 <= k < 256 if isinstance(v, unicode): diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py index 2b00d89..5ecb3e2 100644 --- a/passlib/utils/compat/__init__.py +++ b/passlib/utils/compat/__init__.py @@ -39,7 +39,7 @@ __all__ = [ ## 'is_mapping', 'int_types', 'num_types', - 'unicode_or_bytes_types', + 'unicode_or_bytes', 'str', # unicode/bytes types & helpers @@ -76,16 +76,8 @@ if True: # legacy PY3 indent assert isinstance(s, str) return s - unicode_or_bytes_types = (str, bytes) - - -# shorter preferred aliases -# TODO: align compat module w/ crowbar.compat naming -unicode_or_bytes = unicode_or_bytes_types - -# unicode -- unicode type, regardless of python version -# bytes -- bytes type, regardless of python version -# unicode_or_bytes_types -- types that text can occur in, whether encoded or not +#: alias for isinstance() tests to detect any string type +unicode_or_bytes = (str, bytes) #============================================================================= # unicode & bytes helpers diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py index 7703683..fbdc22e 100644 --- a/passlib/utils/handlers.py +++ b/passlib/utils/handlers.py @@ -28,7 +28,7 @@ from passlib.utils.binary import ( ) from passlib.utils.compat import join_byte_values, \ uascii_to_str, join_unicode, unicode, str_to_uascii, \ - join_unicode, unicode_or_bytes_types, int_types + join_unicode, unicode_or_bytes, int_types from passlib.utils.decor import classproperty, deprecated_method # local __all__ = [ @@ -117,7 +117,7 @@ _UZERO = u"0" def validate_secret(secret): """ensure secret has correct type & size""" - if not isinstance(secret, unicode_or_bytes_types): + if not isinstance(secret, unicode_or_bytes): raise exc.ExpectedStringError(secret, "secret") if len(secret) > MAX_PASSWORD_SIZE: raise exc.PasswordSizeError(MAX_PASSWORD_SIZE) |