summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-10-06 15:08:56 -0400
committerEli Collins <elic@assurancetechnologies.com>2020-10-06 15:08:56 -0400
commit3709566d41523e5bc31e1063b647e90f1469744a (patch)
treee29eed3fa76fad9373432cda397ff7dc9cb24e4e
parent56017e683f8e31be252c94f23d4dd22a2d5603f9 (diff)
downloadpasslib-3709566d41523e5bc31e1063b647e90f1469744a.tar.gz
cleanup old python compat -- replaced "unicode" alias in favor of "str"
-rw-r--r--admin/benchmarks.py3
-rw-r--r--passlib/apache.py12
-rw-r--r--passlib/context.py25
-rw-r--r--passlib/crypto/_blowfish/__init__.py1
-rw-r--r--passlib/crypto/digest.py10
-rw-r--r--passlib/crypto/scrypt/__init__.py4
-rw-r--r--passlib/exc.py4
-rw-r--r--passlib/ext/django/utils.py11
-rw-r--r--passlib/handlers/argon2.py10
-rw-r--r--passlib/handlers/bcrypt.py14
-rw-r--r--passlib/handlers/cisco.py8
-rw-r--r--passlib/handlers/des_crypt.py10
-rw-r--r--passlib/handlers/digests.py6
-rw-r--r--passlib/handlers/django.py8
-rw-r--r--passlib/handlers/fshp.py8
-rw-r--r--passlib/handlers/ldap_digests.py8
-rw-r--r--passlib/handlers/md5_crypt.py7
-rw-r--r--passlib/handlers/misc.py4
-rw-r--r--passlib/handlers/mssql.py8
-rw-r--r--passlib/handlers/mysql.py6
-rw-r--r--passlib/handlers/oracle.py4
-rw-r--r--passlib/handlers/pbkdf2.py2
-rw-r--r--passlib/handlers/phpass.py4
-rw-r--r--passlib/handlers/postgres.py4
-rw-r--r--passlib/handlers/scram.py2
-rw-r--r--passlib/handlers/sha1_crypt.py3
-rw-r--r--passlib/handlers/sha2_crypt.py7
-rw-r--r--passlib/handlers/sun_md5_crypt.py8
-rw-r--r--passlib/handlers/windows.py11
-rw-r--r--passlib/pwd.py4
-rw-r--r--passlib/tests/test_context.py6
-rw-r--r--passlib/tests/test_handlers_argon2.py3
-rw-r--r--passlib/tests/test_totp.py3
-rw-r--r--passlib/tests/test_utils.py10
-rw-r--r--passlib/tests/test_utils_handlers.py10
-rw-r--r--passlib/tests/utils.py29
-rw-r--r--passlib/totp.py10
-rw-r--r--passlib/utils/__init__.py39
-rw-r--r--passlib/utils/binary.py14
-rw-r--r--passlib/utils/compat/__init__.py4
-rw-r--r--passlib/utils/handlers.py37
41 files changed, 181 insertions, 200 deletions
diff --git a/admin/benchmarks.py b/admin/benchmarks.py
index 71c7b56..01e4bac 100644
--- a/admin/benchmarks.py
+++ b/admin/benchmarks.py
@@ -24,7 +24,6 @@ try:
except ImportError:
PasslibConfigWarning = None
import passlib.utils.handlers as uh
-from passlib.utils.compat import unicode
from passlib.tests.utils import time_call
# local
@@ -113,7 +112,7 @@ class BlankHandler(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
return uh.render_mc3(self.ident, self.rounds, self.salt, self.checksum)
def _calc_checksum(self, secret):
- return unicode(secret[0:1])
+ return secret[0:1]
class AnotherHandler(BlankHandler):
name = "another"
diff --git a/passlib/apache.py b/passlib/apache.py
index 2868fa1..9ac14cd 100644
--- a/passlib/apache.py
+++ b/passlib/apache.py
@@ -16,7 +16,7 @@ from passlib.exc import ExpectedStringError
from passlib.hash import htdigest
from passlib.utils import render_bytes, to_bytes, is_ascii_codec
from passlib.utils.decor import deprecated_method
-from passlib.utils.compat import join_bytes, unicode
+from passlib.utils.compat import join_bytes
# local
__all__ = [
'HtpasswdFile',
@@ -50,7 +50,7 @@ class _CommonFile(object):
# charset encoding used by file (defaults to utf-8)
encoding = None
- # whether users() and other public methods should return unicode or bytes?
+ # whether users() and other public methods should return str or bytes?
# (defaults to True)
return_unicode = True
@@ -76,7 +76,7 @@ class _CommonFile(object):
def from_string(cls, data, **kwds):
"""create new object from raw string.
- :type data: unicode or bytes
+ :type data: str or bytes
:arg data:
database to load, as single string.
@@ -352,7 +352,7 @@ class _CommonFile(object):
:returns:
encoded identifer as bytes
"""
- if isinstance(value, unicode):
+ if isinstance(value, str):
value = value.encode(self.encoding)
elif not isinstance(value, bytes):
raise ExpectedStringError(value, param)
@@ -373,7 +373,7 @@ class _CommonFile(object):
(usually indicates wrong encoding set for file).
:returns:
- field as unicode or bytes, as appropriate.
+ field as str or bytes, as appropriate.
"""
assert isinstance(value, bytes), "expected value to be bytes"
if self.return_unicode:
@@ -794,7 +794,7 @@ class HtpasswdFile(_CommonFile):
hash = self._records.get(user)
if hash is None:
return None
- if isinstance(password, unicode):
+ if isinstance(password, str):
# NOTE: encoding password to match file, making the assumption
# that server will use same encoding to hash the password.
password = password.encode(self.encoding)
diff --git a/passlib/context.py b/passlib/context.py
index 3c82519..7fabc77 100644
--- a/passlib/context.py
+++ b/passlib/context.py
@@ -20,7 +20,6 @@ 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,
)
from passlib.utils.decor import deprecated_method, memoized_property
@@ -738,7 +737,7 @@ class CryptContext(object):
def from_string(cls, source, section="passlib", encoding="utf-8"):
"""create new CryptContext instance from an INI-formatted string.
- :type source: unicode or bytes
+ :type source: str or bytes
:arg source:
string containing INI-formatted content.
@@ -768,7 +767,7 @@ class CryptContext(object):
.. seealso:: :meth:`to_string`, the inverse of this constructor.
"""
if not isinstance(source, unicode_or_bytes):
- raise ExpectedTypeError(source, "unicode or bytes", "source")
+ raise ExpectedTypeError(source, "str or bytes", "source")
self = cls(_autoload=False)
self.load(source, section=section, encoding=encoding)
return self
@@ -912,7 +911,7 @@ class CryptContext(object):
the key/value pairs will be interpreted the same
keywords for the :class:`CryptContext` class constructor.
- * a :class:`!unicode` or :class:`!bytes` string
+ * a :class:`!str` or :class:`!bytes` string
this will be interpreted as an INI-formatted file,
and appropriate key/value pairs will be loaded from
@@ -1443,7 +1442,7 @@ class CryptContext(object):
If so, the password should be re-hashed using :meth:`hash`
Otherwise, it will return ``False``.
- :type hash: unicode or bytes
+ :type hash: str or bytes
:arg hash:
The hash string to examine.
@@ -1467,7 +1466,7 @@ class CryptContext(object):
be used when determining if the hash needs to be updated
(e.g. is below the minimum rounds).
- :type secret: unicode, bytes, or None
+ :type secret: str, bytes, or None
:param secret:
Optional secret associated with the provided ``hash``.
This is not required, or even currently used for anything...
@@ -1549,7 +1548,7 @@ class CryptContext(object):
All registered algorithms will be checked, from first to last,
and whichever one positively identifies the hash first will be returned.
- :type hash: unicode or bytes
+ :type hash: str or bytes
:arg hash:
The hash string to test.
@@ -1587,7 +1586,7 @@ class CryptContext(object):
def hash(self, secret, scheme=None, category=None, **kwds):
"""run secret through selected algorithm, returning resulting hash.
- :type secret: unicode or bytes
+ :type secret: str or bytes
:arg secret:
the password to hash.
@@ -1626,7 +1625,7 @@ class CryptContext(object):
.. seealso:: the :ref:`context-basic-example` example in the tutorial
"""
- # XXX: could insert normalization to preferred unicode encoding here
+ # XXX: could insert normalization to preferred str encoding here
if scheme is not None:
# TODO: offer replacement alternative.
# ``context.handler(scheme).hash()`` would work,
@@ -1660,11 +1659,11 @@ class CryptContext(object):
(limited to the schemes configured for this context).
It will then check whether the password verifies against the hash.
- :type secret: unicode or bytes
+ :type secret: str or bytes
:arg secret:
the secret to verify
- :type hash: unicode or bytes
+ :type hash: str or bytes
:arg hash:
hash string to compare to
@@ -1740,11 +1739,11 @@ class CryptContext(object):
which wish to update deprecated hashes, and this call takes
care of all 3 steps efficiently.
- :type secret: unicode or bytes
+ :type secret: str or bytes
:arg secret:
the secret to verify
- :type secret: unicode or bytes
+ :type secret: str or bytes
:arg hash:
hash string to compare to.
diff --git a/passlib/crypto/_blowfish/__init__.py b/passlib/crypto/_blowfish/__init__.py
index f1e84e9..3ee4590 100644
--- a/passlib/crypto/_blowfish/__init__.py
+++ b/passlib/crypto/_blowfish/__init__.py
@@ -56,7 +56,6 @@ import struct
# pkg
from passlib.utils import getrandbytes, rng
from passlib.utils.binary import bcrypt64
-from passlib.utils.compat import unicode
from passlib.crypto._blowfish.unrolled import BlowfishEngine
# local
__all__ = [
diff --git a/passlib/crypto/digest.py b/passlib/crypto/digest.py
index 7a4fbe2..e46ff15 100644
--- a/passlib/crypto/digest.py
+++ b/passlib/crypto/digest.py
@@ -628,7 +628,7 @@ def compile_hmac(digest, key, multipart=False):
digest name or constructor.
:arg key:
- secret key as :class:`!bytes` or :class:`!unicode` (unicode will be encoded using utf-8).
+ secret key as :class:`!bytes` or :class:`!str` (str will be encoded using utf-8).
:param multipart:
request a multipart constructor instead (see return description).
@@ -707,11 +707,11 @@ def pbkdf1(digest, secret, salt, rounds, keylen=None):
:arg secret:
secret to use when generating the key.
- may be :class:`!bytes` or :class:`unicode` (encoded using UTF-8).
+ may be :class:`!bytes` or :class:`str` (encoded using UTF-8).
:arg salt:
salt string to use when generating key.
- may be :class:`!bytes` or :class:`unicode` (encoded using UTF-8).
+ may be :class:`!bytes` or :class:`str` (encoded using UTF-8).
:param rounds:
number of rounds to use to generate key.
@@ -772,11 +772,11 @@ def pbkdf2_hmac(digest, secret, salt, rounds, keylen=None):
:arg secret:
passphrase to use to generate key.
- may be :class:`!bytes` or :class:`unicode` (encoded using UTF-8).
+ may be :class:`!bytes` or :class:`str` (encoded using UTF-8).
:arg salt:
salt string to use when generating key.
- may be :class:`!bytes` or :class:`unicode` (encoded using UTF-8).
+ may be :class:`!bytes` or :class:`str` (encoded using UTF-8).
:param rounds:
number of rounds to use to generate key.
diff --git a/passlib/crypto/scrypt/__init__.py b/passlib/crypto/scrypt/__init__.py
index 60f0cbe..cd10632 100644
--- a/passlib/crypto/scrypt/__init__.py
+++ b/passlib/crypto/scrypt/__init__.py
@@ -107,10 +107,10 @@ def scrypt(secret, salt, n, r, p=1, keylen=32):
"""run SCrypt key derivation function using specified parameters.
:arg secret:
- passphrase string (unicode is encoded to bytes using utf-8).
+ passphrase string (str is encoded to bytes using utf-8).
:arg salt:
- salt string (unicode is encoded to bytes using utf-8).
+ salt string (str is encoded to bytes using utf-8).
:arg n:
integer 'N' parameter
diff --git a/passlib/exc.py b/passlib/exc.py
index 4539c7d..262eb12 100644
--- a/passlib/exc.py
+++ b/passlib/exc.py
@@ -304,8 +304,8 @@ def ExpectedTypeError(value, expected, param):
return TypeError("%s must be %s, not %s" % (param, expected, name))
def ExpectedStringError(value, param):
- """error message when param was supposed to be unicode or bytes"""
- return ExpectedTypeError(value, "unicode or bytes", param)
+ """error message when param was supposed to be str or bytes"""
+ return ExpectedTypeError(value, "str or bytes", param)
#------------------------------------------------------------------------
# hash/verify parameter errors
diff --git a/passlib/ext/django/utils.py b/passlib/ext/django/utils.py
index 651103b..ab508a3 100644
--- a/passlib/ext/django/utils.py
+++ b/passlib/ext/django/utils.py
@@ -20,7 +20,7 @@ except ImportError:
from passlib import exc, registry
from passlib.context import CryptContext
from passlib.exc import PasslibRuntimeWarning
-from passlib.utils.compat import get_method_function, unicode
+from passlib.utils.compat import get_method_function
from passlib.utils.decor import memoized_property
# local
__all__ = [
@@ -782,7 +782,7 @@ class DjangoContextAdapter(DjangoTranslator):
config = getattr(settings, "PASSLIB_CONTEXT", _UNSET)
if config is _UNSET:
config = "passlib-default"
- if not isinstance(config, (unicode, bytes, dict)):
+ if not isinstance(config, (str, bytes, dict)):
raise exc.ExpectedTypeError(config, "str or dict", "PASSLIB_CONFIG")
# load custom category func (if any)
@@ -985,7 +985,6 @@ class _PasslibHasherWrapper(object):
##from passlib.registry import register_crypt_handler
##from passlib.utils import classproperty, to_native_str, to_unicode
-##from passlib.utils.compat import unicode
##
##
##class _HasherHandler(object):
@@ -1023,7 +1022,7 @@ class _PasslibHasherWrapper(object):
## @property
## def ident(self):
## # this should always be correct, as django relies on ident prefix.
-## return unicode(self.django_name + "$")
+## return self.django_name + "$"
##
## @property
## def identify(self, hash):
@@ -1040,7 +1039,7 @@ class _PasslibHasherWrapper(object):
## opts['iterations'] = kwds.pop("rounds")
## if kwds:
## raise TypeError("unexpected keyword arguments: %r" % list(kwds))
-## if isinstance(secret, unicode):
+## if isinstance(secret, str):
## secret = secret.encode("utf-8")
## if salt is None:
## salt = self.django_hasher.salt()
@@ -1049,7 +1048,7 @@ class _PasslibHasherWrapper(object):
## @property
## def verify(self, secret, hash):
## hash = to_native_str(hash, "utf-8", "hash")
-## if isinstance(secret, unicode):
+## if isinstance(secret, str):
## secret = secret.encode("utf-8")
## return self.django_hasher.verify(secret, hash)
##
diff --git a/passlib/handlers/argon2.py b/passlib/handlers/argon2.py
index 6a38153..dba5b17 100644
--- a/passlib/handlers/argon2.py
+++ b/passlib/handlers/argon2.py
@@ -29,7 +29,7 @@ from passlib import exc
from passlib.crypto.digest import MAX_UINT32
from passlib.utils import classproperty, to_bytes, render_bytes
from passlib.utils.binary import b64s_encode, b64s_decode
-from passlib.utils.compat import unicode, bascii_to_str, uascii_to_str
+from passlib.utils.compat import bascii_to_str, uascii_to_str
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -393,9 +393,9 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin,
@classmethod
def from_string(cls, hash):
- # NOTE: assuming hash will be unicode, or use ascii-compatible encoding.
- # TODO: switch to working w/ str or unicode
- if isinstance(hash, unicode):
+ # NOTE: assuming hash will be str, or use ascii-compatible encoding.
+ # TODO: switch to working w/ str
+ if isinstance(hash, str):
hash = hash.encode("utf-8")
if not isinstance(hash, bytes):
raise exc.ExpectedStringError(hash, "hash")
@@ -499,7 +499,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin,
@classmethod
def _norm_type(cls, value):
# type check
- if not isinstance(value, unicode):
+ if not isinstance(value, str):
raise uh.exc.ExpectedTypeError(value, "str", "type")
# check if type is valid
diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py
index 762b7ee..cc0dd1f 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
+from passlib.utils.compat import uascii_to_str, str_to_uascii
import passlib.utils.handlers as uh
# local
@@ -488,7 +488,7 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
def _norm_digest_args(cls, secret, ident, new=False):
# make sure secret is unicode
require_valid_utf8_bytes = cls._require_valid_utf8_bytes
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
elif require_valid_utf8_bytes:
# if backend requires utf8 bytes (os_crypt);
@@ -628,7 +628,7 @@ class _BcryptBackend(_BcryptCommon):
# # below method has a few edge cases where it chokes though.
# @classmethod
# def verify(cls, secret, hash):
- # if isinstance(hash, unicode):
+ # if isinstance(hash, str):
# hash = hash.encode("ascii")
# ident = hash[:hash.index(b"$", 1)+1].decode("ascii")
# if ident not in cls.ident_values:
@@ -648,7 +648,7 @@ class _BcryptBackend(_BcryptCommon):
# returns ascii bytes
secret, ident = self._prepare_digest_args(secret)
config = self._get_config(ident)
- if isinstance(config, unicode):
+ if isinstance(config, str):
config = config.encode("ascii")
hash = _bcrypt.hashpw(secret, config)
assert isinstance(hash, bytes)
@@ -682,8 +682,6 @@ class _BcryptorBackend(_BcryptCommon):
def _calc_checksum(self, secret):
# bcryptor behavior:
- # py2: unicode secret/hash encoded as ascii bytes before use,
- # bytes taken as-is; returns ascii bytes.
# py3: not supported
secret, ident = self._prepare_digest_args(secret)
config = self._get_config(ident)
@@ -751,8 +749,6 @@ class _PyBcryptBackend(_BcryptCommon):
def _calc_checksum_raw(self, secret):
# py-bcrypt behavior:
- # py2: unicode secret/hash encoded as ascii bytes before use,
- # bytes taken as-is; returns ascii bytes.
# py3: unicode secret encoded as utf-8 bytes,
# hash encoded as ascii bytes, returns ascii unicode.
secret, ident = self._prepare_digest_args(secret)
@@ -1191,7 +1187,7 @@ class bcrypt_sha256(_wrapped_bcrypt):
# thus, have to use base64 (44 bytes) rather than hex (64 bytes).
# XXX: it's later come out that 55-72 may be ok, so later revision of bcrypt_sha256
# may switch to hex encoding, since it's simpler to implement elsewhere.
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
if self.version == 1:
diff --git a/passlib/handlers/cisco.py b/passlib/handlers/cisco.py
index 432d8e4..a8e8870 100644
--- a/passlib/handlers/cisco.py
+++ b/passlib/handlers/cisco.py
@@ -13,7 +13,7 @@ from warnings import warn
# pkg
from passlib.utils import right_pad_string, to_unicode, repeat_string, to_bytes
from passlib.utils.binary import h64
-from passlib.utils.compat import unicode, join_byte_values, \
+from passlib.utils.compat import join_byte_values, \
join_byte_elems, iter_byte_values, uascii_to_str
import passlib.utils.handlers as uh
# local
@@ -124,7 +124,7 @@ class cisco_pix(uh.HasUserContext, uh.StaticHandler):
# been observed when trying to actually *set* a non-ascii password
# via ASDM, and access via SSH seems to strip 8-bit chars.
#
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
#
@@ -186,7 +186,7 @@ class cisco_pix(uh.HasUserContext, uh.StaticHandler):
#
user = self.user
if user:
- if isinstance(user, unicode):
+ if isinstance(user, str):
user = user.encode("utf-8")
if not asa or len(secret) < 28:
secret += repeat_string(user, 4)
@@ -405,7 +405,7 @@ class cisco_type7(uh.GenericHandler):
def _calc_checksum(self, secret):
# XXX: no idea what unicode policy is, but all examples are
# 7-bit ascii compatible, so using UTF-8
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return hexlify(self._cipher(secret, self.salt)).decode("ascii").upper()
diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py
index 80a9ec2..4f3d0a0 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
+from passlib.utils.compat import byte_elem_value, u, uascii_to_str
from passlib.crypto.des import des_encrypt_int_block
import passlib.utils.handlers as uh
# local
@@ -53,7 +53,7 @@ def _raw_des_crypt(secret, salt):
salt_value = h64.decode_int12(salt)
# gotta do something - no official policy since this predates unicode
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
assert isinstance(secret, bytes)
@@ -89,7 +89,7 @@ def _raw_bsdi_crypt(secret, rounds, salt):
salt_value = h64.decode_int24(salt)
# gotta do something - no official policy since this predates unicode
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
assert isinstance(secret, bytes)
@@ -471,7 +471,7 @@ class bigcrypt(uh.HasSalt, uh.GenericHandler):
# backend
#===================================================================
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
chk = _raw_des_crypt(secret, self.salt.encode("ascii"))
idx = 8
@@ -569,7 +569,7 @@ class crypt16(uh.TruncateMixin, uh.HasSalt, uh.GenericHandler):
# backend
#===================================================================
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
# check for truncation (during .hash() calls only)
diff --git a/passlib/handlers/digests.py b/passlib/handlers/digests.py
index 982155c..a7add53 100644
--- a/passlib/handlers/digests.py
+++ b/passlib/handlers/digests.py
@@ -9,7 +9,7 @@ import logging; log = logging.getLogger(__name__)
# site
# pkg
from passlib.utils import to_native_str, to_bytes, render_bytes, consteq
-from passlib.utils.compat import unicode, str_to_uascii
+from passlib.utils.compat import str_to_uascii
import passlib.utils.handlers as uh
from passlib.crypto.digest import lookup_hash
# local
@@ -45,7 +45,7 @@ class HexDigestHash(uh.StaticHandler):
return hash.lower()
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return str_to_uascii(self._hash_func(secret).hexdigest())
@@ -118,7 +118,7 @@ class htdigest(uh.MinimalHandler):
if not encoding:
encoding = cls.default_encoding
uh.validate_secret(secret)
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode(encoding)
user = to_bytes(user, encoding, "user")
realm = to_bytes(realm, encoding, "realm")
diff --git a/passlib/handlers/django.py b/passlib/handlers/django.py
index 40925ae..889ada0 100644
--- a/passlib/handlers/django.py
+++ b/passlib/handlers/django.py
@@ -13,7 +13,7 @@ from passlib.handlers.bcrypt import _wrapped_bcrypt
from passlib.hash import argon2, bcrypt, pbkdf2_sha1, pbkdf2_sha256
from passlib.utils import to_unicode, rng, getrandstr
from passlib.utils.binary import BASE64_CHARS
-from passlib.utils.compat import str_to_uascii, uascii_to_str, unicode
+from passlib.utils.compat import str_to_uascii, uascii_to_str
from passlib.crypto.digest import pbkdf2_hmac
import passlib.utils.handlers as uh
# local
@@ -119,7 +119,7 @@ class django_salted_sha1(DjangoSaltedHash):
checksum_size = 40
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return str_to_uascii(sha1(self.salt.encode("ascii") + secret).hexdigest())
@@ -157,7 +157,7 @@ class django_salted_md5(DjangoSaltedHash):
checksum_size = 32
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return str_to_uascii(md5(self.salt.encode("ascii") + secret).hexdigest())
@@ -233,7 +233,7 @@ class django_bcrypt_sha256(_wrapped_bcrypt):
return uascii_to_str(self.django_prefix) + bhash
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
secret = hexlify(self._digest(secret).digest())
return super(django_bcrypt_sha256, self)._calc_checksum(secret)
diff --git a/passlib/handlers/fshp.py b/passlib/handlers/fshp.py
index ecd75b9..8df4845 100644
--- a/passlib/handlers/fshp.py
+++ b/passlib/handlers/fshp.py
@@ -12,7 +12,7 @@ import logging; log = logging.getLogger(__name__)
# pkg
from passlib.utils import to_unicode
import passlib.utils.handlers as uh
-from passlib.utils.compat import bascii_to_str, u, unicode
+from passlib.utils.compat import bascii_to_str, u
from passlib.crypto.digest import pbkdf1
# local
__all__ = [
@@ -91,7 +91,7 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
3: ("sha512", 64),
}
_variant_aliases = dict(
- [(unicode(k),k) for k in _variant_info] +
+ [(str(k),k) for k in _variant_info] +
[(v[0],k) for k,v in _variant_info.items()]
)
@@ -130,7 +130,7 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
def _norm_variant(cls, variant):
if isinstance(variant, bytes):
variant = variant.decode("ascii")
- if isinstance(variant, unicode):
+ if isinstance(variant, str):
try:
variant = cls._variant_aliases[variant]
except KeyError:
@@ -191,7 +191,7 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
#===================================================================
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
# NOTE: for some reason, FSHP uses pbkdf1 with password & salt reversed.
# this has only a minimal impact on security,
diff --git a/passlib/handlers/ldap_digests.py b/passlib/handlers/ldap_digests.py
index b0e6589..bcd5961 100644
--- a/passlib/handlers/ldap_digests.py
+++ b/passlib/handlers/ldap_digests.py
@@ -12,7 +12,7 @@ import re
# pkg
from passlib.handlers.misc import plaintext
from passlib.utils import unix_crypt_schemes, to_unicode
-from passlib.utils.compat import uascii_to_str, unicode, u
+from passlib.utils.compat import uascii_to_str, u
from passlib.utils.decor import classproperty
import passlib.utils.handlers as uh
# local
@@ -53,7 +53,7 @@ class _Base64DigestHelper(uh.StaticHandler):
return cls.ident
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
chk = self._hash_func(secret).digest()
return b64encode(chk).decode("ascii")
@@ -95,7 +95,7 @@ class _SaltedBase64DigestHelper(uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHand
return uascii_to_str(hash)
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return self._hash_func(secret + self.salt).digest()
@@ -299,7 +299,7 @@ class ldap_plaintext(plaintext):
:param encoding:
This controls the character encoding to use (defaults to ``utf-8``).
- This encoding will be used to encode :class:`!unicode` passwords
+ This encoding will be used to encode :class:`!str` passwords
under Python 2, and decode :class:`!bytes` hashes under Python 3.
.. versionchanged:: 1.6
diff --git a/passlib/handlers/md5_crypt.py b/passlib/handlers/md5_crypt.py
index b2dfea4..419862c 100644
--- a/passlib/handlers/md5_crypt.py
+++ b/passlib/handlers/md5_crypt.py
@@ -9,7 +9,6 @@ import logging; log = logging.getLogger(__name__)
# pkg
from passlib.utils import safe_crypt, test_crypt, repeat_string
from passlib.utils.binary import h64
-from passlib.utils.compat import unicode
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -67,15 +66,15 @@ def _raw_md5_crypt(pwd, salt, use_apr=False):
# validate secret
# XXX: not sure what official unicode policy is, using this as default
- if isinstance(pwd, unicode):
+ if isinstance(pwd, str):
pwd = pwd.encode("utf-8")
- assert isinstance(pwd, bytes), "pwd not unicode or bytes"
+ assert isinstance(pwd, bytes), "pwd not str or bytes"
if _BNULL in pwd:
raise uh.exc.NullPasswordError(md5_crypt)
pwd_len = len(pwd)
# validate salt - should have been taken care of by caller
- assert isinstance(salt, unicode), "salt not unicode"
+ assert isinstance(salt, str), "salt not str"
salt = salt.encode("ascii")
assert len(salt) < 9, "salt too large"
# NOTE: spec says salts larger than 8 bytes should be truncated,
diff --git a/passlib/handlers/misc.py b/passlib/handlers/misc.py
index 289731a..0a46197 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
+from passlib.utils.compat import unicode_or_bytes
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -161,7 +161,7 @@ class plaintext(uh.MinimalHandler):
:param encoding:
This controls the character encoding to use (defaults to ``utf-8``).
- This encoding will be used to encode :class:`!unicode` passwords
+ This encoding will be used to encode :class:`!str` passwords
under Python 2, and decode :class:`!bytes` hashes under Python 3.
.. versionchanged:: 1.6
diff --git a/passlib/handlers/mssql.py b/passlib/handlers/mssql.py
index d6a2bca..fcd1fe5 100644
--- a/passlib/handlers/mssql.py
+++ b/passlib/handlers/mssql.py
@@ -43,7 +43,7 @@ from warnings import warn
# site
# pkg
from passlib.utils import consteq
-from passlib.utils.compat import bascii_to_str, unicode
+from passlib.utils.compat import bascii_to_str
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -55,7 +55,7 @@ __all__ = [
# mssql 2000
#=============================================================================
def _raw_mssql(secret, salt):
- assert isinstance(secret, unicode)
+ assert isinstance(secret, str)
assert isinstance(salt, bytes)
return sha1(secret.encode("utf-16-le") + salt).digest()
@@ -65,7 +65,7 @@ UIDENT = u"0x0100"
def _ident_mssql(hash, csize, bsize):
"""common identify for mssql 2000/2005"""
- if isinstance(hash, unicode):
+ if isinstance(hash, str):
if len(hash) == csize and hash.startswith(UIDENT):
return True
elif isinstance(hash, bytes):
@@ -79,7 +79,7 @@ def _ident_mssql(hash, csize, bsize):
def _parse_mssql(hash, csize, bsize, handler):
"""common parser for mssql 2000/2005; returns 4 byte salt + checksum"""
- if isinstance(hash, unicode):
+ if isinstance(hash, str):
if len(hash) == csize and hash.startswith(UIDENT):
try:
return unhexlify(hash[6:].encode("utf-8"))
diff --git a/passlib/handlers/mysql.py b/passlib/handlers/mysql.py
index 087b08d..e8aa4ef 100644
--- a/passlib/handlers/mysql.py
+++ b/passlib/handlers/mysql.py
@@ -30,7 +30,7 @@ from warnings import warn
# site
# pkg
from passlib.utils import to_native_str
-from passlib.utils.compat import bascii_to_str, unicode, \
+from passlib.utils.compat import bascii_to_str, \
byte_elem_value, str_to_uascii
import passlib.utils.handlers as uh
# local
@@ -65,7 +65,7 @@ class mysql323(uh.StaticHandler):
def _calc_checksum(self, secret):
# FIXME: no idea if mysql has a policy about handling unicode passwords
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
MASK_32 = 0xffffffff
@@ -115,7 +115,7 @@ class mysql41(uh.StaticHandler):
def _calc_checksum(self, secret):
# FIXME: no idea if mysql has a policy about handling unicode passwords
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return str_to_uascii(sha1(sha1(secret).digest()).hexdigest()).upper()
diff --git a/passlib/handlers/oracle.py b/passlib/handlers/oracle.py
index 34c4202..a17f370 100644
--- a/passlib/handlers/oracle.py
+++ b/passlib/handlers/oracle.py
@@ -10,7 +10,7 @@ import logging; log = logging.getLogger(__name__)
# site
# pkg
from passlib.utils import to_unicode, xor_bytes
-from passlib.utils.compat import uascii_to_str, unicode, str_to_uascii
+from passlib.utils.compat import uascii_to_str, str_to_uascii
from passlib.crypto.des import des_encrypt_block
import passlib.utils.handlers as uh
# local
@@ -157,7 +157,7 @@ class oracle11(uh.HasSalt, uh.GenericHandler):
return uascii_to_str(hash)
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
chk = sha1(secret + unhexlify(self.salt.encode("ascii"))).hexdigest()
return str_to_uascii(chk).upper()
diff --git a/passlib/handlers/pbkdf2.py b/passlib/handlers/pbkdf2.py
index bf930c3..723e458 100644
--- a/passlib/handlers/pbkdf2.py
+++ b/passlib/handlers/pbkdf2.py
@@ -10,7 +10,7 @@ import logging; log = logging.getLogger(__name__)
# pkg
from passlib.utils import to_unicode
from passlib.utils.binary import ab64_decode, ab64_encode
-from passlib.utils.compat import str_to_bascii, uascii_to_str, unicode
+from passlib.utils.compat import str_to_bascii, uascii_to_str
from passlib.crypto.digest import pbkdf2_hmac
import passlib.utils.handlers as uh
# local
diff --git a/passlib/handlers/phpass.py b/passlib/handlers/phpass.py
index 10e9877..6428bf2 100644
--- a/passlib/handlers/phpass.py
+++ b/passlib/handlers/phpass.py
@@ -14,7 +14,7 @@ import logging; log = logging.getLogger(__name__)
# site
# pkg
from passlib.utils.binary import h64
-from passlib.utils.compat import uascii_to_str, unicode
+from passlib.utils.compat import uascii_to_str
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -116,7 +116,7 @@ class phpass(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.GenericHandler):
#===================================================================
def _calc_checksum(self, secret):
# FIXME: can't find definitive policy on how phpass handles non-ascii.
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
real_rounds = 1<<self.rounds
result = md5(self.salt.encode("ascii") + secret).digest()
diff --git a/passlib/handlers/postgres.py b/passlib/handlers/postgres.py
index e832c47..aead4c1 100644
--- a/passlib/handlers/postgres.py
+++ b/passlib/handlers/postgres.py
@@ -8,7 +8,7 @@ import logging; log = logging.getLogger(__name__)
# site
# pkg
from passlib.utils import to_bytes
-from passlib.utils.compat import str_to_uascii, unicode
+from passlib.utils.compat import str_to_uascii
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -41,7 +41,7 @@ class postgres_md5(uh.HasUserContext, uh.StaticHandler):
# primary interface
#===================================================================
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
user = to_bytes(self.user, "utf-8", param="user")
return str_to_uascii(md5(secret + user).hexdigest())
diff --git a/passlib/handlers/scram.py b/passlib/handlers/scram.py
index 4486e15..eac9c24 100644
--- a/passlib/handlers/scram.py
+++ b/passlib/handlers/scram.py
@@ -193,7 +193,7 @@ class scram(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
SaltedPassword := Hi(Normalize(password), salt, i)
- :type password: unicode or utf-8 bytes
+ :type password: str or utf-8 bytes
:arg password: password to run through digest
:type salt: bytes
diff --git a/passlib/handlers/sha1_crypt.py b/passlib/handlers/sha1_crypt.py
index 393a59e..287f044 100644
--- a/passlib/handlers/sha1_crypt.py
+++ b/passlib/handlers/sha1_crypt.py
@@ -11,7 +11,6 @@ import logging; log = logging.getLogger(__name__)
# pkg
from passlib.utils import safe_crypt, test_crypt
from passlib.utils.binary import h64
-from passlib.utils.compat import unicode
from passlib.crypto.digest import compile_hmac
import passlib.utils.handlers as uh
# local
@@ -126,7 +125,7 @@ class sha1_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler
return True
def _calc_checksum_builtin(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
if _BNULL in secret:
raise uh.exc.NullPasswordError(self)
diff --git a/passlib/handlers/sha2_crypt.py b/passlib/handlers/sha2_crypt.py
index ce5730b..0b3eead 100644
--- a/passlib/handlers/sha2_crypt.py
+++ b/passlib/handlers/sha2_crypt.py
@@ -10,8 +10,7 @@ import logging; log = logging.getLogger(__name__)
from passlib.utils import safe_crypt, test_crypt, \
repeat_string, to_unicode
from passlib.utils.binary import h64
-from passlib.utils.compat import byte_elem_value, \
- uascii_to_str, unicode
+from passlib.utils.compat import byte_elem_value, uascii_to_str
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -86,7 +85,7 @@ def _raw_sha2_crypt(pwd, salt, rounds, use_512=False):
# for details).
# validate secret
- if isinstance(pwd, unicode):
+ if isinstance(pwd, str):
# XXX: not sure what official unicode policy is, using this as default
pwd = pwd.encode("utf-8")
assert isinstance(pwd, bytes)
@@ -101,7 +100,7 @@ def _raw_sha2_crypt(pwd, salt, rounds, use_512=False):
# by the handler class.
# validate salt
- assert isinstance(salt, unicode), "salt not unicode"
+ assert isinstance(salt, str), "salt not str"
salt = salt.encode("ascii")
salt_len = len(salt)
assert salt_len < 17, "salt too large"
diff --git a/passlib/handlers/sun_md5_crypt.py b/passlib/handlers/sun_md5_crypt.py
index 885613c..394a573 100644
--- a/passlib/handlers/sun_md5_crypt.py
+++ b/passlib/handlers/sun_md5_crypt.py
@@ -19,7 +19,7 @@ from warnings import warn
# pkg
from passlib.utils import to_unicode
from passlib.utils.binary import h64
-from passlib.utils.compat import byte_elem_value, uascii_to_str, unicode, str_to_bascii
+from passlib.utils.compat import byte_elem_value, uascii_to_str, str_to_bascii
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -150,7 +150,7 @@ def raw_sun_md5_crypt(secret, rounds, salt):
h = md5(result)
if coin:
h.update(MAGIC_HAMLET)
- h.update(unicode(round).encode("ascii"))
+ h.update(str(round).encode("ascii"))
result = h.digest()
round += 1
@@ -279,7 +279,7 @@ class sun_md5_crypt(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
rounds = int(rstr)
except ValueError:
raise uh.exc.MalformedHashError(cls, "bad rounds")
- if rstr != unicode(rounds):
+ if rstr != str(rounds):
raise uh.exc.ZeroPaddedRoundsError(cls)
if rounds == 0:
# NOTE: not sure if this is forbidden by spec or not;
@@ -348,7 +348,7 @@ class sun_md5_crypt(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
def _calc_checksum(self, secret):
# NOTE: no reference for how sun_md5_crypt handles unicode
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
config = str_to_bascii(self.to_string(_withchk=False))
return raw_sun_md5_crypt(secret, self.rounds, config).decode("ascii")
diff --git a/passlib/handlers/windows.py b/passlib/handlers/windows.py
index 8ccc8ee..5ac890c 100644
--- a/passlib/handlers/windows.py
+++ b/passlib/handlers/windows.py
@@ -9,7 +9,6 @@ from warnings import warn
# site
# pkg
from passlib.utils import to_unicode, right_pad_string
-from passlib.utils.compat import unicode
from passlib.crypto.digest import lookup_hash
md4 = lookup_hash("md4").const
import passlib.utils.handlers as uh
@@ -100,7 +99,7 @@ class lmhash(uh.TruncateMixin, uh.HasEncodingContext, uh.StaticHandler):
def raw(cls, secret, encoding=None):
"""encode password using LANMAN hash algorithm.
- :type secret: unicode or utf-8 encoded bytes
+ :type secret: str or utf-8 encoded bytes
:arg secret: secret to hash
:type encoding: str
:arg encoding:
@@ -117,7 +116,7 @@ class lmhash(uh.TruncateMixin, uh.HasEncodingContext, uh.StaticHandler):
# http://www.freerainbowtables.com/phpBB3/viewtopic.php?t=387&p=12163
from passlib.crypto.des import des_encrypt_block
MAGIC = cls._magic
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
# perform uppercasing while we're still unicode,
# to give a better shot at getting non-ascii chars right.
# (though some codepages do NOT upper-case the same as unicode).
@@ -129,7 +128,7 @@ class lmhash(uh.TruncateMixin, uh.HasEncodingContext, uh.StaticHandler):
# but *that* might not always be right.
secret = secret.upper()
else:
- raise TypeError("secret must be unicode or bytes")
+ raise TypeError("secret must be str or bytes")
secret = right_pad_string(secret, 14)
return des_encrypt_block(secret[0:7], MAGIC) + \
des_encrypt_block(secret[7:14], MAGIC)
@@ -262,7 +261,7 @@ class msdcc(uh.HasUserContext, uh.StaticHandler):
def raw(cls, secret, user):
"""encode password using mscash v1 algorithm
- :arg secret: secret as unicode or utf-8 encoded bytes
+ :arg secret: secret as str or utf-8 encoded bytes
:arg user: username to use as salt
:returns: returns string of raw bytes
@@ -307,7 +306,7 @@ class msdcc2(uh.HasUserContext, uh.StaticHandler):
def raw(cls, secret, user):
"""encode password using msdcc v2 algorithm
- :type secret: unicode or utf-8 bytes
+ :type secret: str or utf-8 bytes
:arg secret: secret
:type user: str
diff --git a/passlib/pwd.py b/passlib/pwd.py
index 3c45d8e..821c953 100644
--- a/passlib/pwd.py
+++ b/passlib/pwd.py
@@ -483,7 +483,7 @@ def genword(entropy=None, length=None, returns=None, **kwds):
* ``"hex"`` -- Lower case hexadecimal. Providers 4 bits of entropy per character.
:returns:
- :class:`!unicode` string containing randomly generated password;
+ :class:`!str` string containing randomly generated password;
or list of 1+ passwords if :samp:`returns={int}` is specified.
"""
gen = WordGenerator(length=length, entropy=entropy, **kwds)
@@ -775,7 +775,7 @@ def genphrase(entropy=None, length=None, returns=None, **kwds):
Defaults to ``" "`` (a space), but can be an empty string, a hyphen, etc.
:returns:
- :class:`!unicode` string containing randomly generated passphrase;
+ :class:`!str` containing randomly generated passphrase;
or list of 1+ passphrases if :samp:`returns={int}` is specified.
"""
gen = PhraseGenerator(entropy=entropy, length=length, **kwds)
diff --git a/passlib/tests/test_context.py b/passlib/tests/test_context.py
index 5a82d90..f323080 100644
--- a/passlib/tests/test_context.py
+++ b/passlib/tests/test_context.py
@@ -15,7 +15,7 @@ from passlib import hash
from passlib.context import CryptContext, LazyCryptContext
from passlib.exc import PasslibConfigWarning, PasslibHashWarning
from passlib.utils import tick, to_unicode
-from passlib.utils.compat import unicode, str_to_uascii
+from passlib.utils.compat import str_to_uascii
import passlib.utils.handlers as uh
from passlib.tests.utils import (TestCase, set_file, TICK_RESOLUTION,
quicksleep, time_call, handler_derived_from)
@@ -1153,7 +1153,7 @@ sha512_crypt__min_rounds = 45000
def _calc_checksum(self, secret):
from hashlib import md5
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return str_to_uascii(md5(secret).hexdigest())
@@ -1708,7 +1708,7 @@ class DelayHash(uh.StaticHandler):
def _calc_checksum(self, secret):
time.sleep(self.delay)
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return str_to_uascii(hashlib.sha1(b"prefix" + secret).hexdigest())
diff --git a/passlib/tests/test_handlers_argon2.py b/passlib/tests/test_handlers_argon2.py
index e771769..a5309d2 100644
--- a/passlib/tests/test_handlers_argon2.py
+++ b/passlib/tests/test_handlers_argon2.py
@@ -10,7 +10,6 @@ import warnings
# site
# pkg
from passlib import hash
-from passlib.utils.compat import unicode
from passlib.tests.utils import HandlerCase, TEST_MODE
from passlib.tests.test_handlers import UPASS_TABLE, PASS_TABLE_UTF8
# module
@@ -303,7 +302,7 @@ class _base_argon2_test(HandlerCase):
# check supported type_values
for value in cls.type_values:
- self.assertIsInstance(value, unicode)
+ self.assertIsInstance(value, str)
self.assertTrue("i" in cls.type_values)
self.assertTrue("d" in cls.type_values)
diff --git a/passlib/tests/test_totp.py b/passlib/tests/test_totp.py
index 4dc16ed..999c799 100644
--- a/passlib/tests/test_totp.py
+++ b/passlib/tests/test_totp.py
@@ -12,7 +12,6 @@ import time as _time
# site
# pkg
from passlib import exc
-from passlib.utils.compat import unicode
from passlib.tests.utils import TestCase, time_call
# subject
from passlib import totp as totp_module
@@ -871,7 +870,7 @@ class TotpTest(TestCase):
time = self.randtime()
result = otp.generate(time)
token = result.token
- self.assertIsInstance(token, unicode)
+ self.assertIsInstance(token, str)
start_time = result.counter * 30
# should generate same token for next 29s
diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py
index e954422..ceea26a 100644
--- a/passlib/tests/test_utils.py
+++ b/passlib/tests/test_utils.py
@@ -9,7 +9,7 @@ import warnings
# pkg
# module
from passlib.utils import is_ascii_safe, to_bytes
-from passlib.utils.compat import unicode, join_bytes, PYPY
+from passlib.utils.compat import join_bytes, PYPY
from passlib.tests.utils import TestCase, hb, run_with_fixed_seeds
#=============================================================================
@@ -121,7 +121,7 @@ class MiscTest(TestCase):
# letters
x = wrapper(u'abc', 32)
y = wrapper(u'abc', 32)
- self.assertIsInstance(x, unicode)
+ self.assertIsInstance(x, str)
self.assertNotEqual(x,y)
self.assertEqual(sorted(set(x)), [u'a',u'b',u'c'])
@@ -195,18 +195,18 @@ class MiscTest(TestCase):
# helpers to generate hashes & config strings to work with
def get_hash(secret):
- assert isinstance(secret, unicode)
+ assert isinstance(secret, str)
hash = hasher.hash(secret)
if isinstance(hash, bytes): # py2
hash = hash.decode("utf-8")
- assert isinstance(hash, unicode)
+ assert isinstance(hash, str)
return hash
# test ascii password & return type
s1 = u"test"
h1 = get_hash(s1)
result = safe_crypt(s1, h1)
- self.assertIsInstance(result, unicode)
+ self.assertIsInstance(result, str)
self.assertEqual(result, h1)
self.assertEqual(safe_crypt(to_bytes(s1), to_bytes(h1)), h1)
diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py
index 0a98978..8527304 100644
--- a/passlib/tests/test_utils_handlers.py
+++ b/passlib/tests/test_utils_handlers.py
@@ -12,7 +12,7 @@ import warnings
from passlib.hash import ldap_md5, sha256_crypt
from passlib.exc import MissingBackendError, PasslibHashWarning
from passlib.utils.compat import str_to_uascii, \
- uascii_to_str, unicode
+ uascii_to_str
import passlib.utils.handlers as uh
from passlib.tests.utils import HandlerCase, TestCase
# module
@@ -155,7 +155,7 @@ class SkeletonTest(TestCase):
# relaxed
# NOTE: this could be turned back on if we test _norm_checksum() directly...
- #with self.assertWarningList("checksum should be unicode"):
+ #with self.assertWarningList("checksum should be str"):
# self.assertEqual(norm_checksum(b'xxzx', relaxed=True), u'xxzx')
#self.assertRaises(TypeError, norm_checksum, 1, relaxed=True)
@@ -174,7 +174,7 @@ class SkeletonTest(TestCase):
# test bytes
self.assertEqual(norm_checksum(b'1234'), b'1234')
- # test unicode
+ # test str
self.assertRaises(TypeError, norm_checksum, u'xxyx')
# NOTE: this could be turned back on if we test _norm_checksum() directly...
@@ -746,7 +746,7 @@ class UnsaltedHash(uh.StaticHandler):
checksum_size = 40
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
data = b"boblious" + secret
return str_to_uascii(hashlib.sha1(data).hexdigest())
@@ -776,7 +776,7 @@ class SaltedHash(uh.HasSalt, uh.GenericHandler):
return uascii_to_str(hash)
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
data = self.salt.encode("ascii") + secret + self.salt.encode("ascii")
return str_to_uascii(hashlib.sha1(data).hexdigest())
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index be46bdd..28ddf49 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -28,7 +28,6 @@ import passlib.registry as registry
from passlib.utils import has_rounds_info, has_salt_info, rounds_cost_values, \
rng as sys_rng, getrandstr, is_ascii_safe, to_native_str, \
repeat_string, tick, batch
-from passlib.utils.compat import unicode
from passlib.utils.decor import classproperty
import passlib.utils.handlers as uh
# local
@@ -218,7 +217,7 @@ def patch_calc_min_rounds(handler):
#=============================================================================
def set_file(path, content):
"""set file to specified bytes"""
- if isinstance(content, unicode):
+ if isinstance(content, str):
content = content.encode("utf-8")
with open(path, "wb") as fh:
fh.write(content)
@@ -1447,7 +1446,7 @@ class HandlerCase(TestCase):
if getattr(self.handler, "_salt_is_bytes", False):
return bytes
else:
- return unicode
+ return str
def test_15_salt_type(self):
"""test non-string salt values"""
@@ -1461,7 +1460,7 @@ class HandlerCase(TestCase):
self.assertRaises(TypeError, self.do_encrypt, 'stub', salt=fake())
# unicode should be accepted only if salt_type is unicode.
- if salt_type is not unicode:
+ if salt_type is not str:
self.assertRaises(TypeError, self.do_encrypt, 'stub', salt=u'x' * salt_size)
# bytes should be accepted only if salt_type is bytes
@@ -1941,24 +1940,24 @@ class HandlerCase(TestCase):
# check ident_values list
for value in cls.ident_values:
- self.assertIsInstance(value, unicode,
- "cls.ident_values must be unicode:")
+ self.assertIsInstance(value, str,
+ "cls.ident_values must be str:")
self.assertTrue(len(cls.ident_values)>1,
"cls.ident_values must have 2+ elements:")
# check default_ident value
- self.assertIsInstance(cls.default_ident, unicode,
- "cls.default_ident must be unicode:")
+ self.assertIsInstance(cls.default_ident, str,
+ "cls.default_ident must be str:")
self.assertTrue(cls.default_ident in cls.ident_values,
"cls.default_ident must specify member of cls.ident_values")
# check optional aliases list
if cls.ident_aliases:
for alias, ident in cls.ident_aliases.items():
- self.assertIsInstance(alias, unicode,
- "cls.ident_aliases keys must be unicode:") # XXX: allow ints?
- self.assertIsInstance(ident, unicode,
- "cls.ident_aliases values must be unicode:")
+ self.assertIsInstance(alias, str,
+ "cls.ident_aliases keys must be str:") # XXX: allow ints?
+ self.assertIsInstance(ident, str,
+ "cls.ident_aliases values must be str:")
self.assertTrue(ident in cls.ident_values,
"cls.ident_aliases must map to cls.ident_values members: %r" % (ident,))
@@ -2581,7 +2580,7 @@ class HandlerCase(TestCase):
"""
if value is None:
return
- self.assertIsInstance(value, unicode)
+ self.assertIsInstance(value, str)
# assumes mask_value() defaults will never show more than <show> chars (4);
# and show nothing if size less than 1/<pct> (8).
ref = value if len(value) < 8 else value[4:]
@@ -2799,7 +2798,7 @@ class HandlerCase(TestCase):
used by fuzz testing.
verifiers should be callable with signature
- ``func(password: unicode, hash: ascii str) -> ok: bool``.
+ ``func(password: str, hash: ascii str) -> ok: bool``.
"""
handler = self.handler
verifiers = []
@@ -2983,7 +2982,7 @@ class HandlerCase(TestCase):
result = getrandstr(rng, self.password_alphabet, size)
# trim ones that encode past truncate point.
- if truncate_size and isinstance(result, unicode):
+ if truncate_size and isinstance(result, str):
while len(result.encode("utf-8")) > truncate_size:
result = result[:-1]
diff --git a/passlib/totp.py b/passlib/totp.py
index c0b0342..822f724 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 (u, unicode, bascii_to_str, int_types, num_types,
+from passlib.utils.compat import (u, bascii_to_str, int_types, num_types,
byte_elem_value)
from passlib.utils.decor import hybrid_method, memoized_property
from passlib.crypto.digest import lookup_hash, compile_hmac, pbkdf2_hmac
@@ -329,7 +329,7 @@ class AppWallet(object):
elif isinstance(tag, int):
tag = str(tag)
else:
- raise TypeError("tag must be unicode/string: %r" % (tag,))
+ raise TypeError("tag must be string: %r" % (tag,))
if not _tag_re.match(tag):
raise ValueError("tag contains invalid characters: %r" % (tag,))
if not isinstance(value, bytes):
@@ -1014,13 +1014,13 @@ class TOTP(object):
or use the class default.
:arg token:
- token as ascii bytes, unicode, or an integer.
+ token as ascii bytes, str, or an integer.
:raises ValueError:
if token has wrong number of digits, or contains non-numeric characters.
:returns:
- token as :class:`!unicode` string, containing only digits 0-9.
+ token as :class:`!str`, containing only digits 0-9.
"""
digits = self_or_cls.digits
if isinstance(token, int_types):
@@ -1558,7 +1558,7 @@ class TOTP(object):
(as generated by :meth:`to_json`).
:arg json:
- Serialized output from :meth:`to_json`, as unicode or ascii bytes.
+ Serialized output from :meth:`to_json`, as str or ascii bytes.
:raises ValueError:
If the key has been encrypted, but the application secret isn't available;
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index b06ba57..e5ff515 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -63,7 +63,7 @@ from passlib.utils.decor import (
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,
+ join_unicode, byte_elem_value,
unicode_or_bytes,
get_method_function, PYPY)
# local
@@ -323,16 +323,16 @@ def consteq(left, right):
# http://bugs.python.org/issue14955
# validate types
- if isinstance(left, unicode):
- if not isinstance(right, unicode):
- raise TypeError("inputs must be both unicode or both bytes")
+ if isinstance(left, str):
+ if not isinstance(right, str):
+ raise TypeError("inputs must be both str or both bytes")
is_bytes = False
elif isinstance(left, bytes):
if not isinstance(right, bytes):
- raise TypeError("inputs must be both unicode or both bytes")
+ raise TypeError("inputs must be both str or both bytes")
is_bytes = True
else:
- raise TypeError("inputs must be both unicode or both bytes")
+ raise TypeError("inputs must be both str or both bytes")
# do size comparison.
# NOTE: the double-if construction below is done deliberately, to ensure
@@ -431,8 +431,8 @@ def saslprep(source, param="value"):
# validate type
# XXX: support bytes (e.g. run through want_unicode)?
# might be easier to just integrate this into cryptcontext.
- if not isinstance(source, unicode):
- raise TypeError("input must be unicode string, not %s" %
+ if not isinstance(source, str):
+ raise TypeError("input must be string, not %s" %
(type(source),))
# mapping stage
@@ -583,7 +583,7 @@ def right_pad_string(source, size, pad=None):
cur = len(source)
if size > cur:
if pad is None:
- pad = _UNULL if isinstance(source, unicode) else _BNULL
+ pad = _UNULL if isinstance(source, str) else _BNULL
return source+pad*(size-cur)
else:
return source[:size]
@@ -698,7 +698,7 @@ def to_bytes(source, encoding="utf-8", param="value", source_encoding=None):
the source will be transcoded from *source_encoding* to *encoding*
(via unicode).
- :raises TypeError: if source is not unicode or bytes.
+ :raises TypeError: if source is not str or bytes.
:returns:
* unicode strings will be encoded using *encoding*, and returned.
@@ -713,7 +713,7 @@ def to_bytes(source, encoding="utf-8", param="value", source_encoding=None):
return source.decode(source_encoding).encode(encoding)
else:
return source
- elif isinstance(source, unicode):
+ elif isinstance(source, str):
return source.encode(encoding)
else:
raise ExpectedStringError(source, param)
@@ -730,14 +730,14 @@ def to_unicode(source, encoding="utf-8", param="value"):
:param param:
optional name of variable/noun to reference when raising errors.
- :raises TypeError: if source is not unicode or bytes.
+ :raises TypeError: if source is not str or bytes.
:returns:
* returns unicode strings unchanged.
* returns bytes strings decoded using *encoding*
"""
assert encoding
- if isinstance(source, unicode):
+ if isinstance(source, str):
return source
elif isinstance(source, bytes):
return source.decode(encoding)
@@ -748,17 +748,16 @@ def to_unicode(source, encoding="utf-8", param="value"):
def to_native_str(source, encoding="utf-8", param="value"):
if isinstance(source, bytes):
return source.decode(encoding)
- elif isinstance(source, unicode):
+ elif isinstance(source, str):
return source
else:
raise ExpectedStringError(source, param)
add_doc(to_native_str,
- """Take in unicode or bytes, return native string.
+ """Take in str or bytes, returns str.
- Python 2: encodes unicode using specified encoding, leaves bytes alone.
- Python 3: leaves unicode alone, decodes bytes using specified encoding.
+ leaves str alone, decodes bytes using specified encoding.
:raises TypeError: if source is not unicode or bytes.
@@ -879,11 +878,11 @@ else:
if crypt_accepts_bytes:
# PyPy3 -- all bytes accepted, but unicode encoded to ASCII,
# so handling that ourselves.
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
if _BNULL in secret:
raise ValueError("null character in secret")
- if isinstance(hash, unicode):
+ if isinstance(hash, str):
hash = hash.encode("ascii")
else:
# CPython3's crypt() doesn't take bytes, only unicode; unicode which is then
@@ -1086,7 +1085,7 @@ def getrandstr(rng, charset, count):
value //= letters
i += 1
- if isinstance(charset, unicode):
+ if isinstance(charset, str):
return join_unicode(helper())
else:
return join_byte_elems(helper())
diff --git a/passlib/utils/binary.py b/passlib/utils/binary.py
index 5c55477..37bfefa 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,
+ unicode_or_bytes,
)
from passlib.utils.decor import memoized_property
# from passlib.utils import BASE64_CHARS, HASH64_CHARS
@@ -129,7 +129,7 @@ def compile_byte_translation(mapping, source=None):
if isinstance(k, unicode_or_bytes):
k = ord(k)
assert isinstance(k, int) and 0 <= k < 256
- if isinstance(v, unicode):
+ if isinstance(v, str):
v = v.encode("ascii")
assert isinstance(v, bytes) and len(v) == 1
target[k] = v
@@ -150,7 +150,7 @@ def b64s_decode(data):
decode from shortened base64 format which omits padding & whitespace.
uses default ``+/`` altchars.
"""
- if isinstance(data, unicode):
+ if isinstance(data, str):
# needs bytes for replace() call, but want to accept ascii-unicode ala a2b_base64()
try:
data = data.encode("ascii")
@@ -196,7 +196,7 @@ def ab64_decode(data):
it is primarily used by Passlib's custom pbkdf2 hashes.
"""
- if isinstance(data, unicode):
+ if isinstance(data, str):
# needs bytes for replace() call, but want to accept ascii-unicode ala a2b_base64()
try:
data = data.encode("ascii")
@@ -231,7 +231,7 @@ def b32decode(source):
padding optional, ignored if present.
"""
# encode & correct for typos
- if isinstance(source, unicode):
+ if isinstance(source, str):
source = source.encode("ascii")
source = source.translate(_b32_translate)
@@ -334,7 +334,7 @@ class Base64Engine(object):
#===================================================================
def __init__(self, charmap, big=False):
# validate charmap, generate encode64/decode64 helper functions.
- if isinstance(charmap, unicode):
+ if isinstance(charmap, str):
charmap = charmap.encode("latin-1")
elif not isinstance(charmap, bytes):
raise exc.ExpectedStringError(charmap, "charmap")
@@ -621,7 +621,7 @@ class Base64Engine(object):
# we have dirty bits - repair the string by decoding last char,
# clearing the padding bits via <mask>, and encoding new char.
- if isinstance(source, unicode):
+ if isinstance(source, str):
cm = self.charmap
last = cm[cm.index(last) & mask]
assert last in padset, "failed to generate valid padding char"
diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py
index 5ecb3e2..f81c6ad 100644
--- a/passlib/utils/compat/__init__.py
+++ b/passlib/utils/compat/__init__.py
@@ -44,7 +44,6 @@ __all__ = [
# unicode/bytes types & helpers
'u',
- 'unicode',
'uascii_to_str', 'bascii_to_str',
'str_to_uascii', 'str_to_bascii',
'join_unicode', 'join_bytes',
@@ -68,7 +67,6 @@ _lazy_attrs = dict()
#=============================================================================
if True: # legacy PY3 indent
- unicode = str
# NOTE: don't need to use this for general u'xxx' case,
# but DO need it as wrapper for u(r'xxx') case (mainly when compiling regexen)
@@ -90,7 +88,7 @@ join_bytes = b''.join
if True: # legacy PY3 indent
def uascii_to_str(s):
- assert isinstance(s, unicode)
+ assert isinstance(s, str)
return s
def bascii_to_str(s):
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index fbdc22e..c5b0bf9 100644
--- a/passlib/utils/handlers.py
+++ b/passlib/utils/handlers.py
@@ -27,7 +27,7 @@ from passlib.utils.binary import (
ALL_BYTE_VALUES,
)
from passlib.utils.compat import join_byte_values, \
- uascii_to_str, join_unicode, unicode, str_to_uascii, \
+ uascii_to_str, join_unicode, str_to_uascii, \
join_unicode, unicode_or_bytes, int_types
from passlib.utils.decor import classproperty, deprecated_method
# local
@@ -124,7 +124,7 @@ def validate_secret(secret):
def to_unicode_for_identify(hash):
"""convert hash to unicode for identify method"""
- if isinstance(hash, unicode):
+ if isinstance(hash, str):
return hash
elif isinstance(hash, bytes):
# try as utf-8, but if it fails, use foolproof latin-1,
@@ -143,8 +143,8 @@ def parse_mc2(hash, prefix, sep=_UDOLLAR, handler=None):
this expects a hash of the format :samp:`{prefix}{salt}[${checksum}]`,
such as md5_crypt, and parses it into salt / checksum portions.
- :arg hash: the hash to parse (bytes or unicode)
- :arg prefix: the identifying prefix (unicode)
+ :arg hash: the hash to parse (bytes or str)
+ :arg prefix: the identifying prefix (str)
:param sep: field separator (unicode, defaults to ``$``).
:param handler: handler class to pass to error constructors.
@@ -153,12 +153,12 @@ def parse_mc2(hash, prefix, sep=_UDOLLAR, handler=None):
"""
# detect prefix
hash = to_unicode(hash, "ascii", "hash")
- assert isinstance(prefix, unicode)
+ assert isinstance(prefix, str)
if not hash.startswith(prefix):
raise exc.InvalidHashError(handler)
# parse 2-part hash or 1-part config string
- assert isinstance(sep, unicode)
+ assert isinstance(sep, str)
parts = hash[len(prefix):].split(sep)
if len(parts) == 2:
salt, chk = parts
@@ -192,12 +192,12 @@ def parse_mc3(hash, prefix, sep=_UDOLLAR, rounds_base=10,
"""
# detect prefix
hash = to_unicode(hash, "ascii", "hash")
- assert isinstance(prefix, unicode)
+ assert isinstance(prefix, str)
if not hash.startswith(prefix):
raise exc.InvalidHashError(handler)
# parse 3-part hash or 2-part config string
- assert isinstance(sep, unicode)
+ assert isinstance(sep, str)
parts = hash[len(prefix):].split(sep)
if len(parts) == 3:
rounds, salt, chk = parts
@@ -307,7 +307,7 @@ def render_mc3(ident, rounds, salt, checksum, sep=u"$", rounds_base=10):
rounds = u"%x" % rounds
else:
assert rounds_base == 10
- rounds = unicode(rounds)
+ rounds = str(rounds)
if checksum:
parts = [ident, rounds, sep, salt, sep, checksum]
else:
@@ -335,12 +335,12 @@ def mask_value(value, show=4, pct=0.125, char=u"*"):
"""
if value is None:
return None
- if not isinstance(value, unicode):
+ if not isinstance(value, str):
if isinstance(value, bytes):
from passlib.utils.binary import ab64_encode
value = ab64_encode(value).decode("ascii")
else:
- value = unicode(value)
+ value = str(value)
size = len(value)
show = min(show, int(size * pct))
return value[:show] + char * (size - show)
@@ -640,12 +640,12 @@ class GenericHandler(MinimalHandler):
if not isinstance(checksum, bytes):
raise exc.ExpectedTypeError(checksum, "bytes", "checksum")
- elif not isinstance(checksum, unicode):
+ elif not isinstance(checksum, str):
if isinstance(checksum, bytes) and relaxed:
warn("checksum should be unicode, not bytes", PasslibHashWarning)
checksum = checksum.decode("ascii")
else:
- raise exc.ExpectedTypeError(checksum, "unicode", "checksum")
+ raise exc.ExpectedTypeError(checksum, "str", "checksum")
# check size
cc = self.checksum_size
@@ -712,8 +712,7 @@ class GenericHandler(MinimalHandler):
:returns:
hash string with salt & digest included.
- should return native string type (ascii-bytes under python 2,
- unicode under python 3)
+ should return native str.
"""
raise NotImplementedError("%s must implement from_string()" % (self.__class__,))
@@ -751,7 +750,7 @@ class GenericHandler(MinimalHandler):
string, taking config from object state
calc checksum implementations may assume secret is always
- either unicode or bytes, checks are performed by verify/etc.
+ either str or bytes, checks are performed by verify/etc.
"""
raise NotImplementedError("%s must implement _calc_checksum()" %
(self.__class__,))
@@ -1057,7 +1056,7 @@ class HasManyIdents(GenericHandler):
#===================================================================
# class attrs
#===================================================================
- default_ident = None # should be unicode
+ default_ident = None # should be str
ident_values = None # should be list of unicode strings
ident_aliases = None # should be dict of unicode -> unicode
# NOTE: any aliases provided to norm_ident() as bytes
@@ -1406,12 +1405,12 @@ class HasSalt(GenericHandler):
if not isinstance(salt, bytes):
raise exc.ExpectedTypeError(salt, "bytes", "salt")
else:
- if not isinstance(salt, unicode):
+ if not isinstance(salt, str):
# NOTE: allowing bytes under py2 so salt can be native str.
if relaxed and isinstance(salt, bytes):
salt = salt.decode("ascii")
else:
- raise exc.ExpectedTypeError(salt, "unicode", "salt")
+ raise exc.ExpectedTypeError(salt, "str", "salt")
# check charset
sc = cls.salt_chars