summaryrefslogtreecommitdiff
path: root/passlib/utils
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-10-06 14:49:50 -0400
committerEli Collins <elic@assurancetechnologies.com>2020-10-06 14:49:50 -0400
commite82f75c13f9815f82b0cf046b2a502925f194703 (patch)
tree19e9bd2034b27e1fbcdfbfb93bfff29e6cbb848d /passlib/utils
parent2cabd30db6306316c7a193585ea1cec5235d5209 (diff)
downloadpasslib-e82f75c13f9815f82b0cf046b2a502925f194703.tar.gz
cleanup old python compat -- removed "unicode_or_str" and "native_string_types" aliases
Diffstat (limited to 'passlib/utils')
-rw-r--r--passlib/utils/__init__.py8
-rw-r--r--passlib/utils/compat/__init__.py11
-rw-r--r--passlib/utils/handlers.py14
-rw-r--r--passlib/utils/pbkdf2.py5
4 files changed, 14 insertions, 24 deletions
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index d6c61a0..9ad8f00 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_str, unicode_or_bytes_types,
+ unicode_or_bytes_types,
get_method_function, PYPY)
# local
__all__ = [
@@ -960,9 +960,9 @@ def test_crypt(secret, hash):
# safe_crypt() always returns unicode, which means that for py3,
# 'hash' can't be bytes, or "== hash" will never be True.
# under py2 unicode & str(bytes) will compare fine;
- # so just enforcing "unicode_or_str" limitation
- assert isinstance(hash, unicode_or_str), \
- "hash must be unicode_or_str, got %s" % type(hash)
+ # so just enforcing "str" limitation
+ assert isinstance(hash, str), \
+ "hash must be str, got %s" % type(hash)
assert hash, "hash must be non-empty"
return safe_crypt(secret, hash) == hash
diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py
index 1a206e8..2b00d89 100644
--- a/passlib/utils/compat/__init__.py
+++ b/passlib/utils/compat/__init__.py
@@ -22,15 +22,10 @@ PYPY = hasattr(sys, "pypy_version_info")
if PYPY and sys.pypy_version_info < (2,0):
raise RuntimeError("passlib requires pypy >= 2.0 (as of passlib 1.7)")
-# e.g. '2.7.7\n[Pyston 0.5.1]'
-# NOTE: deprecated support 2019-11
-PYSTON = "Pyston" in sys.version
-
#=============================================================================
# common imports
#=============================================================================
import logging; log = logging.getLogger(__name__)
-import builtins
def add_doc(obj, doc):
"""add docstring to an object"""
@@ -45,7 +40,7 @@ __all__ = [
'int_types',
'num_types',
'unicode_or_bytes_types',
- 'native_string_types',
+ 'str',
# unicode/bytes types & helpers
'u',
@@ -82,18 +77,15 @@ if True: # legacy PY3 indent
return s
unicode_or_bytes_types = (str, bytes)
- native_string_types = (unicode,)
# shorter preferred aliases
# TODO: align compat module w/ crowbar.compat naming
unicode_or_bytes = unicode_or_bytes_types
-unicode_or_str = native_string_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
-# native_string_types -- types that native python strings (dict keys etc) can occur in.
#=============================================================================
# unicode & bytes helpers
@@ -266,7 +258,6 @@ class _LazyOverlayModule(ModuleType):
return list(attrs)
# replace this module with overlay that will lazily import attributes.
-_lazy_attrs = dict()
_LazyOverlayModule.replace_module(__name__, _lazy_attrs)
#=============================================================================
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index 8fa797d..7703683 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_byte_values, native_string_types, \
+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
from passlib.utils.decor import classproperty, deprecated_method
@@ -1298,7 +1298,7 @@ class HasSalt(GenericHandler):
# replace default_rounds
relaxed = kwds.get("relaxed")
if default_salt_size is not None:
- if isinstance(default_salt_size, native_string_types):
+ if isinstance(default_salt_size, str):
default_salt_size = int(default_salt_size)
subcls.default_salt_size = subcls._clip_to_valid_salt_size(default_salt_size,
param="salt_size",
@@ -1619,7 +1619,7 @@ class HasRounds(GenericHandler):
min_desired_rounds = cls.min_desired_rounds
else:
explicit_min_rounds = True
- if isinstance(min_desired_rounds, native_string_types):
+ if isinstance(min_desired_rounds, str):
min_desired_rounds = int(min_desired_rounds)
subcls.min_desired_rounds = subcls._norm_rounds(min_desired_rounds,
param="min_desired_rounds",
@@ -1629,7 +1629,7 @@ class HasRounds(GenericHandler):
if max_desired_rounds is None:
max_desired_rounds = cls.max_desired_rounds
else:
- if isinstance(max_desired_rounds, native_string_types):
+ if isinstance(max_desired_rounds, str):
max_desired_rounds = int(max_desired_rounds)
if min_desired_rounds and max_desired_rounds < min_desired_rounds:
msg = "%s: max_desired_rounds (%r) below min_desired_rounds (%r)" % \
@@ -1645,7 +1645,7 @@ class HasRounds(GenericHandler):
# replace default_rounds
if default_rounds is not None:
- if isinstance(default_rounds, native_string_types):
+ if isinstance(default_rounds, str):
default_rounds = int(default_rounds)
if min_desired_rounds and default_rounds < min_desired_rounds:
raise ValueError("%s: default_rounds (%r) below min_desired_rounds (%r)" %
@@ -1663,7 +1663,7 @@ class HasRounds(GenericHandler):
# replace / set vary_rounds
if vary_rounds is not None:
- if isinstance(vary_rounds, native_string_types):
+ if isinstance(vary_rounds, str):
if vary_rounds.endswith("%"):
vary_rounds = float(vary_rounds[:-1]) * 0.01
elif "." in vary_rounds:
@@ -1892,7 +1892,7 @@ class ParallelismMixin(GenericHandler):
def using(cls, parallelism=None, **kwds):
subcls = super(ParallelismMixin, cls).using(**kwds)
if parallelism is not None:
- if isinstance(parallelism, native_string_types):
+ if isinstance(parallelism, str):
parallelism = int(parallelism)
subcls.parallelism = subcls._norm_parallelism(parallelism, relaxed=kwds.get("relaxed"))
return subcls
diff --git a/passlib/utils/pbkdf2.py b/passlib/utils/pbkdf2.py
index e490af5..d9bd083 100644
--- a/passlib/utils/pbkdf2.py
+++ b/passlib/utils/pbkdf2.py
@@ -11,7 +11,6 @@ import logging; log = logging.getLogger(__name__)
# site
# pkg
from passlib.exc import ExpectedTypeError
-from passlib.utils.compat import native_string_types
from passlib.crypto.digest import lookup_hash, pbkdf1 as _pbkdf1, pbkdf2_hmac, compile_hmac
# local
__all__ = [
@@ -85,7 +84,7 @@ def get_prf(name):
global _prf_cache
if name in _prf_cache:
return _prf_cache[name]
- if isinstance(name, native_string_types):
+ if isinstance(name, str):
if not name.startswith(_HMAC_PREFIXES):
raise ValueError("unknown prf algorithm: %r" % (name,))
digest = lookup_hash(name[5:]).name
@@ -171,7 +170,7 @@ def pbkdf2(secret, salt, rounds, keylen=None, prf="hmac-sha1"):
This has been deprecated in favor of :func:`passlib.crypto.digest.pbkdf2_hmac`,
and will be removed in Passlib 2.0. *Note the call signature has changed.*
"""
- if callable(prf) or (isinstance(prf, native_string_types) and not prf.startswith(_HMAC_PREFIXES)):
+ if callable(prf) or (isinstance(prf, str) and not prf.startswith(_HMAC_PREFIXES)):
raise NotImplementedError("non-HMAC prfs are not supported as of Passlib 1.7")
digest = prf[5:]
return pbkdf2_hmac(digest, secret, salt, rounds, keylen)