summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2017-02-17 11:21:50 -0500
committerEli Collins <elic@assurancetechnologies.com>2017-02-17 11:21:50 -0500
commit5b529f14d35c657c6d67a8fc5ee5dfaf89d5c6e3 (patch)
treecbba1a0ce1111317c8647a0396804db24b4f45f6
parentd9ebfa4a70506d47dae94c1ab1a3c40f854428d7 (diff)
downloadpasslib-5b529f14d35c657c6d67a8fc5ee5dfaf89d5c6e3.tar.gz
compat cleanup: replaced all u("") instances with u""
realized can do this now that we're requiring python3 >= 3.3. had to keep u() helper around for u(r"") instances, since py3 doesn't have ur"". but switched it to use ascii decoding for py2, to make sure things are clean.
-rw-r--r--admin/benchmarks.py12
-rw-r--r--passlib/crypto/_blowfish/__init__.py8
-rw-r--r--passlib/handlers/argon2.py6
-rw-r--r--passlib/handlers/bcrypt.py30
-rw-r--r--passlib/handlers/cisco.py4
-rw-r--r--passlib/handlers/des_crypt.py8
-rw-r--r--passlib/handlers/django.py20
-rw-r--r--passlib/handlers/fshp.py5
-rw-r--r--passlib/handlers/ldap_digests.py10
-rw-r--r--passlib/handlers/md5_crypt.py6
-rw-r--r--passlib/handlers/misc.py8
-rw-r--r--passlib/handlers/mssql.py4
-rw-r--r--passlib/handlers/mysql.py6
-rw-r--r--passlib/handlers/oracle.py6
-rw-r--r--passlib/handlers/pbkdf2.py20
-rw-r--r--passlib/handlers/phpass.py12
-rw-r--r--passlib/handlers/postgres.py4
-rw-r--r--passlib/handlers/roundup.py7
-rw-r--r--passlib/handlers/scram.py6
-rw-r--r--passlib/handlers/scrypt.py8
-rw-r--r--passlib/handlers/sha1_crypt.py6
-rw-r--r--passlib/handlers/sha2_crypt.py20
-rw-r--r--passlib/handlers/sun_md5_crypt.py24
-rw-r--r--passlib/tests/test_apache.py13
-rw-r--r--passlib/tests/test_context.py28
-rw-r--r--passlib/tests/test_crypto_builtin_md4.py6
-rw-r--r--passlib/tests/test_crypto_digest.py4
-rw-r--r--passlib/tests/test_crypto_scrypt.py6
-rw-r--r--passlib/tests/test_ext_django.py6
-rw-r--r--passlib/tests/test_handlers.py52
-rw-r--r--passlib/tests/test_handlers_cisco.py5
-rw-r--r--passlib/tests/test_handlers_django.py5
-rw-r--r--passlib/tests/test_handlers_pbkdf2.py33
-rw-r--r--passlib/tests/test_totp.py16
-rw-r--r--passlib/tests/test_utils.py182
-rw-r--r--passlib/tests/test_utils_handlers.py113
-rw-r--r--passlib/tests/test_utils_pbkdf2.py2
-rw-r--r--passlib/tests/utils.py26
-rw-r--r--passlib/totp.py10
-rw-r--r--passlib/utils/__init__.py14
-rw-r--r--passlib/utils/binary.py18
-rw-r--r--passlib/utils/compat/__init__.py11
-rw-r--r--passlib/utils/handlers.py20
43 files changed, 402 insertions, 408 deletions
diff --git a/admin/benchmarks.py b/admin/benchmarks.py
index f664cea..b6a5d99 100644
--- a/admin/benchmarks.py
+++ b/admin/benchmarks.py
@@ -24,7 +24,7 @@ try:
except ImportError:
PasslibConfigWarning = None
import passlib.utils.handlers as uh
-from passlib.utils.compat import u, print_, unicode
+from passlib.utils.compat import print_, unicode
from passlib.tests.utils import time_call
# local
@@ -93,12 +93,12 @@ from passlib.context import CryptContext
class BlankHandler(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
name = "blank"
- ident = u("$b$")
+ ident = u"$b$"
setting_kwds = ("rounds", "salt", "salt_size")
checksum_size = 1
min_salt_size = max_salt_size = 1
- salt_chars = u("a")
+ salt_chars = u"a"
min_rounds = 1000
max_rounds = 3000
@@ -117,10 +117,10 @@ class BlankHandler(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
class AnotherHandler(BlankHandler):
name = "another"
- ident = u("$a$")
+ ident = u"$a$"
-SECRET = u("toomanysecrets")
-OTHER = u("setecastronomy")
+SECRET = u"toomanysecrets"
+OTHER = u"setecastronomy"
#=============================================================================
# CryptContext benchmarks
diff --git a/passlib/crypto/_blowfish/__init__.py b/passlib/crypto/_blowfish/__init__.py
index 1aa1c85..9a9d378 100644
--- a/passlib/crypto/_blowfish/__init__.py
+++ b/passlib/crypto/_blowfish/__init__.py
@@ -56,7 +56,7 @@ import struct
# pkg
from passlib.utils import getrandbytes, rng
from passlib.utils.binary import bcrypt64
-from passlib.utils.compat import BytesIO, unicode, u, native_string_types
+from passlib.utils.compat import BytesIO, unicode, native_string_types
from passlib.crypto._blowfish.unrolled import BlowfishEngine
# local
__all__ = [
@@ -101,11 +101,11 @@ def raw_bcrypt(password, ident, salt, log_rounds):
# parse ident
assert isinstance(ident, native_string_types)
add_null_padding = True
- if ident == u('2a') or ident == u('2y') or ident == u('2b'):
+ if ident == u'2a' or ident == u'2y' or ident == u'2b':
pass
- elif ident == u('2'):
+ elif ident == u'2':
add_null_padding = False
- elif ident == u('2x'):
+ elif ident == u'2x':
raise ValueError("crypt_blowfish's buggy '2x' hashes are not "
"currently supported")
else:
diff --git a/passlib/handlers/argon2.py b/passlib/handlers/argon2.py
index 578c2c5..1844eff 100644
--- a/passlib/handlers/argon2.py
+++ b/passlib/handlers/argon2.py
@@ -30,7 +30,7 @@ from passlib import exc
from passlib.crypto.digest import MAX_UINT32
from passlib.utils import to_bytes
from passlib.utils.binary import b64s_encode, b64s_decode
-from passlib.utils.compat import u, unicode, bascii_to_str
+from passlib.utils.compat import unicode, bascii_to_str
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -109,11 +109,11 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin,
#------------------------
# GenericHandler
#------------------------
- ident = u("$argon2i")
+ ident = u"$argon2i"
checksum_size = _default_settings.hash_len
# NOTE: from_string() relies on the ordering of these...
- ident_values = (u("$argon2i$"), u("$argon2d$"))
+ ident_values = (u"$argon2i$", u"$argon2d$")
#------------------------
# HasSalt
diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py
index e5fbfe0..afec733 100644
--- a/passlib/handlers/bcrypt.py
+++ b/passlib/handlers/bcrypt.py
@@ -28,7 +28,7 @@ from passlib.exc import PasslibHashWarning, PasslibSecurityWarning, PasslibSecur
from passlib.utils import safe_crypt, repeat_string, to_bytes, parse_version, \
rng, getrandstr, test_crypt, to_unicode
from passlib.utils.binary import bcrypt64
-from passlib.utils.compat import u, uascii_to_str, unicode, str_to_uascii
+from passlib.utils.compat import uascii_to_str, unicode, str_to_uascii
import passlib.utils.handlers as uh
# local
@@ -39,11 +39,11 @@ __all__ = [
#=============================================================================
# support funcs & constants
#=============================================================================
-IDENT_2 = u("$2$")
-IDENT_2A = u("$2a$")
-IDENT_2X = u("$2x$")
-IDENT_2Y = u("$2y$")
-IDENT_2B = u("$2b$")
+IDENT_2 = u"$2$"
+IDENT_2A = u"$2a$"
+IDENT_2X = u"$2x$"
+IDENT_2Y = u"$2y$"
+IDENT_2B = u"$2b$"
_BNULL = b'\x00'
# reference hash of "test", used in various self-checks
@@ -117,8 +117,8 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
#--------------------
default_ident = IDENT_2B
ident_values = (IDENT_2, IDENT_2A, IDENT_2X, IDENT_2Y, IDENT_2B)
- ident_aliases = {u("2"): IDENT_2, u("2a"): IDENT_2A, u("2y"): IDENT_2Y,
- u("2b"): IDENT_2B}
+ ident_aliases = {u"2": IDENT_2, u"2a": IDENT_2A, u"2y": IDENT_2Y,
+ u"2b": IDENT_2B}
#--------------------
# HasSalt
@@ -163,9 +163,9 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
if ident == IDENT_2X:
raise ValueError("crypt_blowfish's buggy '2x' hashes are not "
"currently supported")
- rounds_str, data = tail.split(u("$"))
+ rounds_str, data = tail.split(u"$")
rounds = int(rounds_str)
- if rounds_str != u('%02d') % (rounds,):
+ if rounds_str != u'%02d' % (rounds,):
raise uh.exc.MalformedHashError(cls, "malformed cost field")
salt, chk = data[:22], data[22:]
return cls(
@@ -176,14 +176,14 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents,
)
def to_string(self):
- hash = u("%s%02d$%s%s") % (self.ident, self.rounds, self.salt, self.checksum)
+ hash = u"%s%02d$%s%s" % (self.ident, self.rounds, self.salt, self.checksum)
return uascii_to_str(hash)
# NOTE: this should be kept separate from to_string()
# so that bcrypt_sha256() can still use it, while overriding to_string()
def _get_config(self, ident):
"""internal helper to prepare config string for backends"""
- config = u("%s%02d$%s") % (ident, self.rounds, self.salt)
+ config = u"%s%02d$%s" % (ident, self.rounds, self.salt)
return uascii_to_str(config)
#===================================================================
@@ -850,7 +850,7 @@ class bcrypt(_NoBackend, _BcryptCommon):
#=============================================================================
# variants
#=============================================================================
-_UDOLLAR = u("$")
+_UDOLLAR = u"$"
# XXX: it might be better to have all the bcrypt variants share a common base class,
# and have the (django_)bcrypt_sha256 wrappers just proxy bcrypt instead of subclassing it.
@@ -940,7 +940,7 @@ class bcrypt_sha256(_wrapped_bcrypt):
# XXX: we can't use .ident attr due to bcrypt code using it.
# working around that via prefix.
- prefix = u('$bcrypt-sha256$')
+ prefix = u'$bcrypt-sha256$'
_hash_re = re.compile(r"""
^
@@ -976,7 +976,7 @@ class bcrypt_sha256(_wrapped_bcrypt):
checksum=m.group("digest"),
)
- _template = u("$bcrypt-sha256$%s,%d$%s$%s")
+ _template = u"$bcrypt-sha256$%s,%d$%s$%s"
def to_string(self):
hash = self._template % (self.ident.strip(_UDOLLAR),
diff --git a/passlib/handlers/cisco.py b/passlib/handlers/cisco.py
index e715e1a..432d8e4 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, u, join_byte_values, \
+from passlib.utils.compat import unicode, join_byte_values, \
join_byte_elems, iter_byte_values, uascii_to_str
import passlib.utils.handlers as uh
# local
@@ -423,7 +423,7 @@ class cisco_type7(uh.GenericHandler):
return raw.decode(encoding) if encoding else raw
# type7 uses a xor-based vingere variant, using the following secret key:
- _key = u("dsfd;kfoA,.iyewrkldJKDHSUBsgvca69834ncxv9873254k;fg87")
+ _key = u"dsfd;kfoA,.iyewrkldJKDHSUBsgvca69834ncxv9873254k;fg87"
@classmethod
def _cipher(cls, data, salt):
diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py
index 9561ab4..8630cbe 100644
--- a/passlib/handlers/des_crypt.py
+++ b/passlib/handlers/des_crypt.py
@@ -184,7 +184,7 @@ class des_crypt(uh.TruncateMixin, uh.HasManyBackends, uh.HasSalt, uh.GenericHand
return cls(salt=salt, checksum=chk or None)
def to_string(self):
- hash = u("%s%s") % (self.salt, self.checksum)
+ hash = u"%s%s" % (self.salt, self.checksum)
return uascii_to_str(hash)
#===================================================================
@@ -319,7 +319,7 @@ class bsdi_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler
)
def to_string(self):
- hash = u("_%s%s%s") % (h64.encode_int24(self.rounds).decode("ascii"),
+ hash = u"_%s%s%s" % (h64.encode_int24(self.rounds).decode("ascii"),
self.salt, self.checksum)
return uascii_to_str(hash)
@@ -458,7 +458,7 @@ class bigcrypt(uh.HasSalt, uh.GenericHandler):
return cls(salt=salt, checksum=chk)
def to_string(self):
- hash = u("%s%s") % (self.salt, self.checksum)
+ hash = u"%s%s" % (self.salt, self.checksum)
return uascii_to_str(hash)
def _norm_checksum(self, checksum, relaxed=False):
@@ -562,7 +562,7 @@ class crypt16(uh.TruncateMixin, uh.HasSalt, uh.GenericHandler):
return cls(salt=salt, checksum=chk)
def to_string(self):
- hash = u("%s%s") % (self.salt, self.checksum)
+ hash = u"%s%s" % (self.salt, self.checksum)
return uascii_to_str(hash)
#===================================================================
diff --git a/passlib/handlers/django.py b/passlib/handlers/django.py
index 88906f5..ca2b94a 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, u
+from passlib.utils.compat import str_to_uascii, uascii_to_str, unicode
from passlib.crypto.digest import pbkdf2_hmac
import passlib.utils.handlers as uh
# local
@@ -115,7 +115,7 @@ class django_salted_sha1(DjangoSaltedHash):
"""
name = "django_salted_sha1"
django_name = "sha1"
- ident = u("sha1$")
+ ident = u"sha1$"
checksum_size = 40
def _calc_checksum(self, secret):
@@ -153,7 +153,7 @@ class django_salted_md5(DjangoSaltedHash):
"""
name = "django_salted_md5"
django_name = "md5"
- ident = u("md5$")
+ ident = u"md5$"
checksum_size = 32
def _calc_checksum(self, secret):
@@ -166,7 +166,7 @@ class django_salted_md5(DjangoSaltedHash):
#=============================================================================
django_bcrypt = uh.PrefixWrapper("django_bcrypt", bcrypt,
- prefix=u('bcrypt$'), ident=u("bcrypt$"),
+ prefix=u'bcrypt$', ident=u"bcrypt$",
# NOTE: this docstring is duplicated in the docs, since sphinx
# seems to be having trouble reading it via autodata::
doc="""This class implements Django 1.4's BCrypt wrapper, and follows the :ref:`password-hash-api`.
@@ -209,7 +209,7 @@ class django_bcrypt_sha256(_wrapped_bcrypt):
# XXX: we can't use .ident attr due to bcrypt code using it.
# working around that via django_prefix
- django_prefix = u('bcrypt_sha256$')
+ django_prefix = u'bcrypt_sha256$'
@classmethod
def identify(cls, hash):
@@ -280,7 +280,7 @@ class django_pbkdf2_sha256(DjangoVariableHash):
"""
name = "django_pbkdf2_sha256"
django_name = "pbkdf2_sha256"
- ident = u('pbkdf2_sha256$')
+ ident = u'pbkdf2_sha256$'
min_salt_size = 1
max_rounds = 0xffffffff # setting at 32-bit limit for now
checksum_chars = uh.PADDED_BASE64_CHARS
@@ -331,7 +331,7 @@ class django_pbkdf2_sha1(django_pbkdf2_sha256):
"""
name = "django_pbkdf2_sha1"
django_name = "pbkdf2_sha1"
- ident = u('pbkdf2_sha1$')
+ ident = u'pbkdf2_sha1$'
checksum_size = 28 # 20 bytes -> base64
default_rounds = pbkdf2_sha1.default_rounds # NOTE: django 1.6 uses 12000
_digest = "sha1"
@@ -341,7 +341,7 @@ class django_pbkdf2_sha1(django_pbkdf2_sha256):
#=============================================================================
django_argon2 = uh.PrefixWrapper("django_argon2", argon2,
- prefix=u('argon2'), ident=u('argon2$argon2i$'),
+ prefix=u'argon2', ident=u'argon2$argon2i$',
# NOTE: this docstring is duplicated in the docs, since sphinx
# seems to be having trouble reading it via autodata::
doc="""This class implements Django 1.10's Argon2 wrapper, and follows the :ref:`password-hash-api`.
@@ -396,7 +396,7 @@ class django_des_crypt(uh.TruncateMixin, uh.HasSalt, uh.GenericHandler):
name = "django_des_crypt"
django_name = "crypt"
setting_kwds = ("salt", "salt_size", "truncate_error")
- ident = u("crypt$")
+ ident = u"crypt$"
checksum_chars = salt_chars = uh.HASH64_CHARS
checksum_size = 11
min_salt_size = default_salt_size = 2
@@ -481,7 +481,7 @@ class django_disabled(uh.ifc.DisabledHash, uh.StaticHandler):
.. versionchanged:: 1.7 started appending an alphanumeric string.
"""
name = "django_disabled"
- _hash_prefix = u("!")
+ _hash_prefix = u"!"
suffix_length = 40
# XXX: move this to StaticHandler, or wherever _hash_prefix is being used?
diff --git a/passlib/handlers/fshp.py b/passlib/handlers/fshp.py
index db13e74..62e0fad 100644
--- a/passlib/handlers/fshp.py
+++ b/passlib/handlers/fshp.py
@@ -12,8 +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, iteritems, u,\
- unicode
+from passlib.utils.compat import bascii_to_str, iteritems, u, unicode
from passlib.crypto.digest import pbkdf1
# local
__all__ = [
@@ -67,7 +66,7 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
name = "fshp"
setting_kwds = ("salt", "salt_size", "rounds", "variant")
checksum_chars = uh.PADDED_BASE64_CHARS
- ident = u("{FSHP")
+ ident = u"{FSHP"
# checksum_size is property() that depends on variant
#--HasRawSalt--
diff --git a/passlib/handlers/ldap_digests.py b/passlib/handlers/ldap_digests.py
index 4356f07..b54e830 100644
--- a/passlib/handlers/ldap_digests.py
+++ b/passlib/handlers/ldap_digests.py
@@ -106,7 +106,7 @@ class ldap_md5(_Base64DigestHelper):
The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods have no optional keywords.
"""
name = "ldap_md5"
- ident = u("{MD5}")
+ ident = u"{MD5}"
_hash_func = md5
_hash_regex = re.compile(u(r"^\{MD5\}(?P<chk>[+/a-zA-Z0-9]{22}==)$"))
@@ -116,7 +116,7 @@ class ldap_sha1(_Base64DigestHelper):
The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods have no optional keywords.
"""
name = "ldap_sha1"
- ident = u("{SHA}")
+ ident = u"{SHA}"
_hash_func = sha1
_hash_regex = re.compile(u(r"^\{SHA\}(?P<chk>[+/a-zA-Z0-9]{27}=)$"))
@@ -154,7 +154,7 @@ class ldap_salted_md5(_SaltedBase64DigestHelper):
This format now supports variable length salts, instead of a fix 4 bytes.
"""
name = "ldap_salted_md5"
- ident = u("{SMD5}")
+ ident = u"{SMD5}"
checksum_size = 16
_hash_func = md5
_hash_regex = re.compile(u(r"^\{SMD5\}(?P<tmp>[+/a-zA-Z0-9]{27,}={0,2})$"))
@@ -193,7 +193,7 @@ class ldap_salted_sha1(_SaltedBase64DigestHelper):
This format now supports variable length salts, instead of a fix 4 bytes.
"""
name = "ldap_salted_sha1"
- ident = u("{SSHA}")
+ ident = u"{SSHA}"
checksum_size = 20
_hash_func = sha1
_hash_regex = re.compile(u(r"^\{SSHA\}(?P<tmp>[+/a-zA-Z0-9]{32,}={0,2})$"))
@@ -250,7 +250,7 @@ def _init_ldap_crypt_handlers():
g = globals()
for wname in unix_crypt_schemes:
name = 'ldap_' + wname
- g[name] = uh.PrefixWrapper(name, wname, prefix=u("{CRYPT}"), lazy=True)
+ g[name] = uh.PrefixWrapper(name, wname, prefix=u"{CRYPT}", lazy=True)
del g
_init_ldap_crypt_handlers()
diff --git a/passlib/handlers/md5_crypt.py b/passlib/handlers/md5_crypt.py
index 993db4d..faaf889 100644
--- a/passlib/handlers/md5_crypt.py
+++ b/passlib/handlers/md5_crypt.py
@@ -9,7 +9,7 @@ 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, u
+from passlib.utils.compat import unicode
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -255,7 +255,7 @@ class md5_crypt(uh.HasManyBackends, _MD5_Common):
# class attrs
#===================================================================
name = "md5_crypt"
- ident = u("$1$")
+ ident = u"$1$"
#===================================================================
# methods
@@ -329,7 +329,7 @@ class apr_md5_crypt(_MD5_Common):
# class attrs
#===================================================================
name = "apr_md5_crypt"
- ident = u("$apr1$")
+ ident = u"$apr1$"
#===================================================================
# methods
diff --git a/passlib/handlers/misc.py b/passlib/handlers/misc.py
index ecd2e78..8644fee 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, u, unicode_or_bytes_types
+from passlib.utils.compat import unicode, unicode_or_bytes_types
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -22,7 +22,7 @@ __all__ = [
# handler
#=============================================================================
-_MARKER_CHARS = u("*!")
+_MARKER_CHARS = u"*!"
_MARKER_BYTES = b"*!"
class unix_disabled(uh.ifc.DisabledHash, uh.MinimalHandler):
@@ -56,12 +56,12 @@ class unix_disabled(uh.ifc.DisabledHash, uh.MinimalHandler):
# TODO: rename attr to 'marker'...
if 'bsd' in sys.platform: # pragma: no cover -- runtime detection
- default_marker = u("*")
+ default_marker = u"*"
else:
# use the linux default for other systems
# (glibc also supports adding old hash after the marker
# so it can be restored later).
- default_marker = u("!")
+ default_marker = u"!"
@classmethod
def using(cls, marker=None, **kwds):
diff --git a/passlib/handlers/mssql.py b/passlib/handlers/mssql.py
index b060b36..d6a2bca 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, u
+from passlib.utils.compat import bascii_to_str, unicode
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -61,7 +61,7 @@ def _raw_mssql(secret, salt):
BIDENT = b"0x0100"
##BIDENT2 = b("\x01\x00")
-UIDENT = u("0x0100")
+UIDENT = u"0x0100"
def _ident_mssql(hash, csize, bsize):
"""common identify for mssql 2000/2005"""
diff --git a/passlib/handlers/mysql.py b/passlib/handlers/mysql.py
index 4a71253..087b08d 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, u, \
+from passlib.utils.compat import bascii_to_str, unicode, \
byte_elem_value, str_to_uascii
import passlib.utils.handlers as uh
# local
@@ -82,7 +82,7 @@ class mysql323(uh.StaticHandler):
nr1 ^= ((((nr1 & 63)+add)*tmp) + (nr1 << 8)) & MASK_32
nr2 = (nr2+((nr2 << 8) ^ nr1)) & MASK_32
add = (add+tmp) & MASK_32
- return u("%08x%08x") % (nr1 & MASK_31, nr2 & MASK_31)
+ return u"%08x%08x" % (nr1 & MASK_31, nr2 & MASK_31)
#===================================================================
# eoc
@@ -102,7 +102,7 @@ class mysql41(uh.StaticHandler):
# class attrs
#===================================================================
name = "mysql41"
- _hash_prefix = u("*")
+ _hash_prefix = u"*"
checksum_chars = uh.HEX_CHARS
checksum_size = 40
diff --git a/passlib/handlers/oracle.py b/passlib/handlers/oracle.py
index a094f37..46b2260 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 irange, u, \
+from passlib.utils.compat import irange, \
uascii_to_str, unicode, str_to_uascii
from passlib.crypto.des import des_encrypt_block
import passlib.utils.handlers as uh
@@ -141,7 +141,7 @@ class oracle11(uh.HasSalt, uh.GenericHandler):
#===================================================================
# methods
#===================================================================
- _hash_regex = re.compile(u("^S:(?P<chk>[0-9a-f]{40})(?P<salt>[0-9a-f]{20})$"), re.I)
+ _hash_regex = re.compile(u"^S:(?P<chk>[0-9a-f]{40})(?P<salt>[0-9a-f]{20})$", re.I)
@classmethod
def from_string(cls, hash):
@@ -154,7 +154,7 @@ class oracle11(uh.HasSalt, uh.GenericHandler):
def to_string(self):
chk = self.checksum
- hash = u("S:%s%s") % (chk.upper(), self.salt.upper())
+ hash = u"S:%s%s" % (chk.upper(), self.salt.upper())
return uascii_to_str(hash)
def _calc_checksum(self, secret):
diff --git a/passlib/handlers/pbkdf2.py b/passlib/handlers/pbkdf2.py
index 274278d..bf930c3 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, u, uascii_to_str, unicode
+from passlib.utils.compat import str_to_bascii, uascii_to_str, unicode
from passlib.crypto.digest import pbkdf2_hmac
import passlib.utils.handlers as uh
# local
@@ -81,7 +81,7 @@ def create_pbkdf2_hash(hash_name, digest_size, rounds=12000, ident=None, module=
"""create new Pbkdf2DigestHandler subclass for a specific hash"""
name = 'pbkdf2_' + hash_name
if ident is None:
- ident = u("$pbkdf2-%s$") % (hash_name,)
+ ident = u"$pbkdf2-%s$" % (hash_name,)
base = Pbkdf2DigestHandler
return type(name, (base,), dict(
__module__=module, # so ABCMeta won't clobber it.
@@ -128,7 +128,7 @@ def create_pbkdf2_hash(hash_name, digest_size, rounds=12000, ident=None, module=
#------------------------------------------------------------------------
# derived handlers
#------------------------------------------------------------------------
-pbkdf2_sha1 = create_pbkdf2_hash("sha1", 20, 131000, ident=u("$pbkdf2$"))
+pbkdf2_sha1 = create_pbkdf2_hash("sha1", 20, 131000, ident=u"$pbkdf2$")
pbkdf2_sha256 = create_pbkdf2_hash("sha256", 32, 29000)
pbkdf2_sha512 = create_pbkdf2_hash("sha512", 64, 25000)
@@ -183,7 +183,7 @@ class cta_pbkdf2_sha1(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Generic
#--GenericHandler--
name = "cta_pbkdf2_sha1"
setting_kwds = ("salt", "salt_size", "rounds")
- ident = u("$p5k2$")
+ ident = u"$p5k2$"
checksum_size = 20
# NOTE: max_salt_size and max_rounds are arbitrarily chosen to provide a
@@ -279,8 +279,8 @@ class dlitz_pbkdf2_sha1(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
#--GenericHandler--
name = "dlitz_pbkdf2_sha1"
setting_kwds = ("salt", "salt_size", "rounds")
- ident = u("$p5k2$")
- _stub_checksum = u("0" * 48 + "=")
+ ident = u"$p5k2$"
+ _stub_checksum = u"0" * 48 + "="
# NOTE: max_salt_size and max_rounds are arbitrarily chosen to provide a
# sanity check. underlying algorithm (and reference implementation)
@@ -370,7 +370,7 @@ class atlassian_pbkdf2_sha1(uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler)
#--GenericHandler--
name = "atlassian_pbkdf2_sha1"
setting_kwds =("salt",)
- ident = u("{PKCS5S2}")
+ ident = u"{PKCS5S2}"
checksum_size = 32
#--HasRawSalt--
@@ -436,7 +436,7 @@ class grub_pbkdf2_sha512(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Gene
name = "grub_pbkdf2_sha512"
setting_kwds = ("salt", "salt_size", "rounds")
- ident = u("grub.pbkdf2.sha512.")
+ ident = u"grub.pbkdf2.sha512."
checksum_size = 64
# NOTE: max_salt_size and max_rounds are arbitrarily chosen to provide a
@@ -453,7 +453,7 @@ class grub_pbkdf2_sha512(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Gene
@classmethod
def from_string(cls, hash):
- rounds, salt, chk = uh.parse_mc3(hash, cls.ident, sep=u("."),
+ rounds, salt, chk = uh.parse_mc3(hash, cls.ident, sep=u".",
handler=cls)
salt = unhexlify(salt.encode("ascii"))
if chk:
@@ -463,7 +463,7 @@ class grub_pbkdf2_sha512(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Gene
def to_string(self):
salt = hexlify(self.salt).decode("ascii").upper()
chk = hexlify(self.checksum).decode("ascii").upper()
- return uh.render_mc3(self.ident, self.rounds, salt, chk, sep=u("."))
+ return uh.render_mc3(self.ident, self.rounds, salt, chk, sep=u".")
def _calc_checksum(self, secret):
# TODO: find out what grub's policy is re: unicode
diff --git a/passlib/handlers/phpass.py b/passlib/handlers/phpass.py
index 6736f0f..10e9877 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 u, uascii_to_str, unicode
+from passlib.utils.compat import uascii_to_str, unicode
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -79,9 +79,9 @@ class phpass(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.GenericHandler):
rounds_cost = "log2"
#--HasManyIdents--
- default_ident = u("$P$")
- ident_values = (u("$P$"), u("$H$"))
- ident_aliases = {u("P"):u("$P$"), u("H"):u("$H$")}
+ default_ident = u"$P$"
+ ident_values = (u"$P$", u"$H$")
+ ident_aliases = {u"P":u"$P$", u"H":u"$H$"}
#===================================================================
# formatting
@@ -105,10 +105,10 @@ class phpass(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.GenericHandler):
)
def to_string(self):
- hash = u("%s%s%s%s") % (self.ident,
+ hash = u"%s%s%s%s" % (self.ident,
h64.encode_int6(self.rounds).decode("ascii"),
self.salt,
- self.checksum or u(''))
+ self.checksum or u'')
return uascii_to_str(hash)
#===================================================================
diff --git a/passlib/handlers/postgres.py b/passlib/handlers/postgres.py
index 17156fa..e832c47 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, u
+from passlib.utils.compat import str_to_uascii, unicode
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -33,7 +33,7 @@ class postgres_md5(uh.HasUserContext, uh.StaticHandler):
# algorithm information
#===================================================================
name = "postgres_md5"
- _hash_prefix = u("md5")
+ _hash_prefix = u"md5"
checksum_chars = uh.HEX_CHARS
checksum_size = 32
diff --git a/passlib/handlers/roundup.py b/passlib/handlers/roundup.py
index c7f99c1..bb00cf6 100644
--- a/passlib/handlers/roundup.py
+++ b/passlib/handlers/roundup.py
@@ -7,7 +7,6 @@ import logging; log = logging.getLogger(__name__)
# site
# pkg
import passlib.utils.handlers as uh
-from passlib.utils.compat import u
# local
__all__ = [
"roundup_plaintext",
@@ -18,11 +17,11 @@ __all__ = [
#
#=============================================================================
roundup_plaintext = uh.PrefixWrapper("roundup_plaintext", "plaintext",
- prefix=u("{plaintext}"), lazy=True)
+ prefix=u"{plaintext}", lazy=True)
# NOTE: these are here because they're currently only known to be used by roundup
-ldap_hex_md5 = uh.PrefixWrapper("ldap_hex_md5", "hex_md5", u("{MD5}"), lazy=True)
-ldap_hex_sha1 = uh.PrefixWrapper("ldap_hex_sha1", "hex_sha1", u("{SHA}"), lazy=True)
+ldap_hex_md5 = uh.PrefixWrapper("ldap_hex_md5", "hex_md5", u"{MD5}", lazy=True)
+ldap_hex_sha1 = uh.PrefixWrapper("ldap_hex_sha1", "hex_sha1", u"{SHA}", lazy=True)
#=============================================================================
# eof
diff --git a/passlib/handlers/scram.py b/passlib/handlers/scram.py
index 87bfabd..57bf101 100644
--- a/passlib/handlers/scram.py
+++ b/passlib/handlers/scram.py
@@ -8,7 +8,7 @@ import logging; log = logging.getLogger(__name__)
# pkg
from passlib.utils import consteq, saslprep, to_native_str, splitcomma
from passlib.utils.binary import ab64_decode, ab64_encode
-from passlib.utils.compat import bascii_to_str, iteritems, u, native_string_types
+from passlib.utils.compat import bascii_to_str, iteritems, native_string_types
from passlib.crypto.digest import pbkdf2_hmac, norm_hash_name
import passlib.utils.handlers as uh
# local
@@ -87,7 +87,7 @@ class scram(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
#--GenericHandler--
name = "scram"
setting_kwds = ("salt", "salt_size", "rounds", "algs")
- ident = u("$scram$")
+ ident = u"$scram$"
#--HasSalt--
default_salt_size = 12
@@ -435,7 +435,7 @@ class scram(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
## alg="sha-1",
## salt='QSXCR+Q6sek8bf92'.decode("base64"),
## rounds=4096,
-## password=u("pencil"),
+## password=u"pencil",
## )
## print_(engine.digest.encode("base64").rstrip())
##
diff --git a/passlib/handlers/scrypt.py b/passlib/handlers/scrypt.py
index 1686fda..ff59433 100644
--- a/passlib/handlers/scrypt.py
+++ b/passlib/handlers/scrypt.py
@@ -10,7 +10,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 u, bascii_to_str, suppress_cause
+from passlib.utils.compat import bascii_to_str, suppress_cause
from passlib.utils.decor import classproperty
import passlib.utils.handlers as uh
# local
@@ -22,10 +22,10 @@ __all__ = [
# scrypt format identifiers
#=============================================================================
-IDENT_SCRYPT = u("$scrypt$") # identifier used by passlib
-IDENT_7 = u("$7$") # used by official scrypt spec
+IDENT_SCRYPT = u"$scrypt$" # identifier used by passlib
+IDENT_7 = u"$7$" # used by official scrypt spec
-_UDOLLAR = u("$")
+_UDOLLAR = u"$"
#=============================================================================
# handler
diff --git a/passlib/handlers/sha1_crypt.py b/passlib/handlers/sha1_crypt.py
index d3e972c..03265f3 100644
--- a/passlib/handlers/sha1_crypt.py
+++ b/passlib/handlers/sha1_crypt.py
@@ -11,7 +11,7 @@ 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 u, unicode, irange
+from passlib.utils.compat import unicode, irange
from passlib.crypto.digest import compile_hmac
import passlib.utils.handlers as uh
# local
@@ -62,7 +62,7 @@ class sha1_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler
#--GenericHandler--
name = "sha1_crypt"
setting_kwds = ("salt", "salt_size", "rounds")
- ident = u("$sha1$")
+ ident = u"$sha1$"
checksum_size = 28
checksum_chars = uh.HASH64_CHARS
@@ -132,7 +132,7 @@ class sha1_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler
raise uh.exc.NullPasswordError(self)
rounds = self.rounds
# NOTE: this seed value is NOT the same as the config string
- result = (u("%s$sha1$%s") % (self.salt, rounds)).encode("ascii")
+ result = (u"%s$sha1$%s" % (self.salt, rounds)).encode("ascii")
# NOTE: this algorithm is essentially PBKDF1, modified to use HMAC.
keyed_hmac = compile_hmac("sha1", secret)
for _ in irange(rounds):
diff --git a/passlib/handlers/sha2_crypt.py b/passlib/handlers/sha2_crypt.py
index 807de5e..b259586 100644
--- a/passlib/handlers/sha2_crypt.py
+++ b/passlib/handlers/sha2_crypt.py
@@ -10,7 +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, u, \
+from passlib.utils.compat import byte_elem_value, \
uascii_to_str, unicode
import passlib.utils.handlers as uh
# local
@@ -246,9 +246,9 @@ def _raw_sha2_crypt(pwd, salt, rounds, use_512=False):
#=============================================================================
# handlers
#=============================================================================
-_UROUNDS = u("rounds=")
-_UDOLLAR = u("$")
-_UZERO = u("0")
+_UROUNDS = u"rounds="
+_UDOLLAR = u"$"
+_UZERO = u"0"
class _SHA2_Common(uh.HasManyBackends, uh.HasRounds, uh.HasSalt,
uh.GenericHandler):
@@ -339,11 +339,11 @@ class _SHA2_Common(uh.HasManyBackends, uh.HasRounds, uh.HasSalt,
def to_string(self):
if self.rounds == 5000 and self.implicit_rounds:
- hash = u("%s%s$%s") % (self.ident, self.salt,
- self.checksum or u(''))
+ hash = u"%s%s$%s" % (self.ident, self.salt,
+ self.checksum or u'')
else:
- hash = u("%srounds=%d$%s$%s") % (self.ident, self.rounds,
- self.salt, self.checksum or u(''))
+ hash = u"%srounds=%d$%s$%s" % (self.ident, self.rounds,
+ self.salt, self.checksum or u'')
return uascii_to_str(hash)
#===================================================================
@@ -436,7 +436,7 @@ class sha256_crypt(_SHA2_Common):
# class attrs
#===================================================================
name = "sha256_crypt"
- ident = u("$5$")
+ ident = u"$5$"
checksum_size = 43
# NOTE: using 25/75 weighting of builtin & os_crypt backends
default_rounds = 535000
@@ -496,7 +496,7 @@ class sha512_crypt(_SHA2_Common):
# class attrs
#===================================================================
name = "sha512_crypt"
- ident = u("$6$")
+ ident = u"$6$"
checksum_size = 86
_cdb_use_512 = True
# NOTE: using 25/75 weighting of builtin & os_crypt backends
diff --git a/passlib/handlers/sun_md5_crypt.py b/passlib/handlers/sun_md5_crypt.py
index 0eeb4e7..40875fe 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, irange, u, \
+from passlib.utils.compat import byte_elem_value, irange, \
uascii_to_str, unicode, str_to_bascii
import passlib.utils.handlers as uh
# local
@@ -237,7 +237,7 @@ class sun_md5_crypt(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
# XXX: ^ not sure what it does if past this bound... does 32 int roll over?
rounds_cost = "linear"
- ident_values = (u("$md5$"), u("$md5,"))
+ ident_values = (u"$md5$", u"$md5,")
#===================================================================
# instance attrs
@@ -268,11 +268,11 @@ class sun_md5_crypt(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
# if so, parse and validate it.
# by end, set 'rounds' to int value, and 'tail' containing salt+chk
#
- if hash.startswith(u("$md5$")):
+ if hash.startswith(u"$md5$"):
rounds = 0
salt_idx = 5
- elif hash.startswith(u("$md5,rounds=")):
- idx = hash.find(u("$"), 12)
+ elif hash.startswith(u"$md5,rounds="):
+ idx = hash.find(u"$", 12)
if idx == -1:
raise uh.exc.MalformedHashError(cls, "unexpected end of rounds")
rstr = hash[12:idx]
@@ -296,20 +296,20 @@ class sun_md5_crypt(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
# to deal cleanly with some backward-compatible workarounds
# implemented by original implementation.
#
- chk_idx = hash.rfind(u("$"), salt_idx)
+ chk_idx = hash.rfind(u"$", salt_idx)
if chk_idx == -1:
# ''-config for $-hash
salt = hash[salt_idx:]
chk = None
bare_salt = True
elif chk_idx == len(hash)-1:
- if chk_idx > salt_idx and hash[-2] == u("$"):
+ if chk_idx > salt_idx and hash[-2] == u"$":
raise uh.exc.MalformedHashError(cls, "too many '$' separators")
# $-config for $$-hash
salt = hash[salt_idx:-1]
chk = None
bare_salt = False
- elif chk_idx > 0 and hash[chk_idx-1] == u("$"):
+ elif chk_idx > 0 and hash[chk_idx-1] == u"$":
# $$-hash
salt = hash[salt_idx:chk_idx-1]
chk = hash[chk_idx+1:]
@@ -328,15 +328,15 @@ class sun_md5_crypt(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
)
def to_string(self, _withchk=True):
- ss = u('') if self.bare_salt else u('$')
+ ss = u'' if self.bare_salt else u'$'
rounds = self.rounds
if rounds > 0:
- hash = u("$md5,rounds=%d$%s%s") % (rounds, self.salt, ss)
+ hash = u"$md5,rounds=%d$%s%s" % (rounds, self.salt, ss)
else:
- hash = u("$md5$%s%s") % (self.salt, ss)
+ hash = u"$md5$%s%s" % (self.salt, ss)
if _withchk:
chk = self.checksum
- hash = u("%s$%s") % (hash, chk)
+ hash = u"%s$%s" % (hash, chk)
return uascii_to_str(hash)
#===================================================================
diff --git a/passlib/tests/test_apache.py b/passlib/tests/test_apache.py
index f4f91b4..0649c8c 100644
--- a/passlib/tests/test_apache.py
+++ b/passlib/tests/test_apache.py
@@ -12,7 +12,6 @@ from passlib import apache
from passlib.exc import MissingBackendError
from passlib.utils.compat import irange
from passlib.tests.utils import TestCase, get_file, set_file, ensure_mtime_changed
-from passlib.utils.compat import u
from passlib.utils import to_bytes
# module
log = getLogger(__name__)
@@ -265,7 +264,7 @@ class HtpasswdFileTest(TestCase):
# check sample utf-8
ht = apache.HtpasswdFile.from_string(self.sample_04_utf8, encoding="utf-8",
return_unicode=True)
- self.assertEqual(ht.users(), [ u("user\u00e6") ])
+ self.assertEqual(ht.users(), [ u"user\u00e6" ])
# encoding=None should throw error
self.assertRaises(TypeError, apache.HtpasswdFile.from_string,
@@ -274,7 +273,7 @@ class HtpasswdFileTest(TestCase):
# check sample latin-1
ht = apache.HtpasswdFile.from_string(self.sample_04_latin1,
encoding="latin-1", return_unicode=True)
- self.assertEqual(ht.users(), [ u("user\u00e6") ])
+ self.assertEqual(ht.users(), [ u"user\u00e6" ])
def test_08_get_hash(self):
"""test get_hash()"""
@@ -569,13 +568,13 @@ class HtdigestFileTest(TestCase):
# check sample utf-8
ht = apache.HtdigestFile.from_string(self.sample_04_utf8, encoding="utf-8", return_unicode=True)
- self.assertEqual(ht.realms(), [ u("realm\u00e6") ])
- self.assertEqual(ht.users(u("realm\u00e6")), [ u("user\u00e6") ])
+ self.assertEqual(ht.realms(), [ u"realm\u00e6" ])
+ self.assertEqual(ht.users(u"realm\u00e6"), [ u"user\u00e6" ])
# check sample latin-1
ht = apache.HtdigestFile.from_string(self.sample_04_latin1, encoding="latin-1", return_unicode=True)
- self.assertEqual(ht.realms(), [ u("realm\u00e6") ])
- self.assertEqual(ht.users(u("realm\u00e6")), [ u("user\u00e6") ])
+ self.assertEqual(ht.realms(), [ u"realm\u00e6" ])
+ self.assertEqual(ht.users(u"realm\u00e6"), [ u"user\u00e6" ])
def test_10_to_string(self):
"""test to_string()"""
diff --git a/passlib/tests/test_context.py b/passlib/tests/test_context.py
index c679c3a..68603ba 100644
--- a/passlib/tests/test_context.py
+++ b/passlib/tests/test_context.py
@@ -20,7 +20,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 irange, u, unicode, str_to_uascii, PY2, PY26
+from passlib.utils.compat import irange, unicode, str_to_uascii, PY2, PY26
import passlib.utils.handlers as uh
from passlib.tests.utils import (TestCase, set_file, TICK_RESOLUTION,
quicksleep, time_call, handler_derived_from)
@@ -75,7 +75,7 @@ class CryptContextTest(TestCase):
sample_1_resolved_dict = merge_dicts(sample_1_dict,
schemes = sample_1_handlers)
- sample_1_unnormalized = u("""\
+ sample_1_unnormalized = u"""\
[passlib]
schemes = des_crypt, md5_crypt, bsdi_crypt, sha512_crypt
default = md5_crypt
@@ -85,9 +85,9 @@ bsdi_crypt__default_rounds = 25001
bsdi_crypt__max_rounds = 30001
sha512_crypt__max_rounds = 50000
sha512_crypt__min_rounds = 40000
-""")
+"""
- sample_1_unicode = u("""\
+ sample_1_unicode = u"""\
[passlib]
schemes = des_crypt, md5_crypt, bsdi_crypt, sha512_crypt
default = md5_crypt
@@ -97,7 +97,7 @@ bsdi_crypt__max_rounds = 30001
sha512_crypt__max_rounds = 50000
sha512_crypt__min_rounds = 40000
-""")
+"""
#---------------------------------------------------------------
# sample 1 external files
@@ -107,12 +107,12 @@ sha512_crypt__min_rounds = 40000
sample_1_path = os.path.join(here, "sample1.cfg")
# sample 1 with '\r\n' linesep
- sample_1b_unicode = sample_1_unicode.replace(u("\n"), u("\r\n"))
+ sample_1b_unicode = sample_1_unicode.replace(u"\n", u"\r\n")
sample_1b_path = os.path.join(here, "sample1b.cfg")
# sample 1 using UTF-16 and alt section
- sample_1c_bytes = sample_1_unicode.replace(u("[passlib]"),
- u("[mypolicy]")).encode("utf-16")
+ sample_1c_bytes = sample_1_unicode.replace(u"[passlib]",
+ u"[mypolicy]").encode("utf-16")
sample_1c_path = os.path.join(here, "sample1c.cfg")
# enable to regenerate sample files
@@ -207,7 +207,7 @@ sha512_crypt__min_rounds = 45000
self.assertEqual(ctx.to_dict(), self.sample_3_dict)
# test unicode scheme names (issue 54)
- ctx = CryptContext(schemes=[u("sha256_crypt")])
+ ctx = CryptContext(schemes=[u"sha256_crypt"])
self.assertEqual(ctx.schemes(), ("sha256_crypt",))
def test_02_from_string(self):
@@ -750,8 +750,8 @@ sha512_crypt__min_rounds = 45000
# test unicode category strings are accepted under py2
if PY2:
- self.assertEqual(ctx.handler(category=u("staff"), unconfigured=True), hash.sha256_crypt)
- self.assertEqual(ctx.handler(category=u("admin"), unconfigured=True), hash.md5_crypt)
+ self.assertEqual(ctx.handler(category=u"staff", unconfigured=True), hash.sha256_crypt)
+ self.assertEqual(ctx.handler(category=u"admin", unconfigured=True), hash.md5_crypt)
def test_33_options(self):
"""test internal _get_record_options() method"""
@@ -938,8 +938,8 @@ sha512_crypt__min_rounds = 45000
# we have to omit scheme=xxx so codepath is tested fully
if PY2:
c2 = cc.copy(default="phpass")
- self.assertTrue(c2.genconfig(category=u("admin")).startswith("$P$5"))
- self.assertTrue(c2.genconfig(category=u("staff")).startswith("$H$5"))
+ self.assertTrue(c2.genconfig(category=u"admin").startswith("$P$5"))
+ self.assertTrue(c2.genconfig(category=u"staff").startswith("$H$5"))
# throws error without schemes
self.assertRaises(KeyError, CryptContext().genconfig)
@@ -1726,7 +1726,7 @@ class DelayHash(uh.StaticHandler):
checksum_chars = uh.LOWER_HEX_CHARS
checksum_size = 40
delay = 0
- _hash_prefix = u("$x$")
+ _hash_prefix = u"$x$"
def _calc_checksum(self, secret):
time.sleep(self.delay)
diff --git a/passlib/tests/test_crypto_builtin_md4.py b/passlib/tests/test_crypto_builtin_md4.py
index 0aca1eb..8cdf39a 100644
--- a/passlib/tests/test_crypto_builtin_md4.py
+++ b/passlib/tests/test_crypto_builtin_md4.py
@@ -9,7 +9,7 @@ import hashlib
# site
# pkg
# module
-from passlib.utils.compat import bascii_to_str, PY3, u
+from passlib.utils.compat import bascii_to_str, PY3
from passlib.crypto.digest import lookup_hash
from passlib.tests.utils import TestCase, skipUnless
# local
@@ -65,12 +65,12 @@ class _Common_MD4_Test(TestCase):
if PY3:
# reject unicode, hash should return digest of b''
h = md4()
- self.assertRaises(TypeError, h.update, u('a'))
+ self.assertRaises(TypeError, h.update, u'a')
self.assertEqual(h.hexdigest(), "31d6cfe0d16ae931b73c59d7e0c089c0")
else:
# coerce unicode to ascii, hash should return digest of b'a'
h = md4()
- h.update(u('a'))
+ h.update(u'a')
self.assertEqual(h.hexdigest(), "bde52cb31de33e46245e05fbdbd6fb24")
def test_md4_hexdigest(self):
diff --git a/passlib/tests/test_crypto_digest.py b/passlib/tests/test_crypto_digest.py
index 65b4a4d..a675ca8 100644
--- a/passlib/tests/test_crypto_digest.py
+++ b/passlib/tests/test_crypto_digest.py
@@ -10,7 +10,7 @@ import warnings
# site
# pkg
# module
-from passlib.utils.compat import PY3, u, JYTHON
+from passlib.utils.compat import PY3, JYTHON
from passlib.tests.utils import TestCase, TEST_MODE, skipUnless, hb
#=============================================================================
@@ -52,7 +52,7 @@ class HashInfoTest(TestCase):
warnings.filterwarnings("ignore", '.*unknown hash')
# test string types
- self.assertEqual(norm_hash_name(u("MD4")), "md4")
+ self.assertEqual(norm_hash_name(u"MD4"), "md4")
self.assertEqual(norm_hash_name(b"MD4"), "md4")
self.assertRaises(TypeError, norm_hash_name, None)
diff --git a/passlib/tests/test_crypto_scrypt.py b/passlib/tests/test_crypto_scrypt.py
index 9666667..6266ab1 100644
--- a/passlib/tests/test_crypto_scrypt.py
+++ b/passlib/tests/test_crypto_scrypt.py
@@ -13,7 +13,7 @@ warnings.filterwarnings("ignore", ".*using builtin scrypt backend.*")
# pkg
from passlib import exc
from passlib.utils import getrandbytes
-from passlib.utils.compat import PYPY, u, bascii_to_str
+from passlib.utils.compat import PYPY, bascii_to_str
from passlib.utils.decor import classproperty
from passlib.tests.utils import TestCase, skipUnless, TEST_MODE, hb
# subject
@@ -450,7 +450,7 @@ class _CommonScryptTest(TestCase):
return hexstr(scrypt_mod.scrypt(secret, "salt", 2, 2, 2, 16))
# unicode
- TEXT = u("abc\u00defg")
+ TEXT = u"abc\u00defg"
self.assertEqual(run_scrypt(TEXT), '05717106997bfe0da42cf4779a2f8bd8')
# utf8 bytes
@@ -475,7 +475,7 @@ class _CommonScryptTest(TestCase):
return hexstr(scrypt_mod.scrypt("secret", salt, 2, 2, 2, 16))
# unicode
- TEXT = u("abc\u00defg")
+ TEXT = u"abc\u00defg"
self.assertEqual(run_scrypt(TEXT), 'a748ec0f4613929e9e5f03d1ab741d88')
# utf8 bytes
diff --git a/passlib/tests/test_ext_django.py b/passlib/tests/test_ext_django.py
index f566d13..b884330 100644
--- a/passlib/tests/test_ext_django.py
+++ b/passlib/tests/test_ext_django.py
@@ -14,7 +14,7 @@ from passlib.context import CryptContext
from passlib.ext.django.utils import (
DJANGO_VERSION, MIN_DJANGO_VERSION, DjangoTranslator,
)
-from passlib.utils.compat import iteritems, get_method_function, u
+from passlib.utils.compat import iteritems, get_method_function
from passlib.utils.decor import memoized_property
# tests
from passlib.tests.utils import TestCase, TEST_MODE, handler_derived_from
@@ -689,9 +689,9 @@ class DjangoExtensionTest(_ExtensionTest):
"v2RWkZQzctPdejyRqmmTDQpZN6wTh7.RUy9zF2LftT6")
self.assertEqual(hasher.safe_summary(encoded),
{'algorithm': 'sha256_crypt',
- 'salt': u('abcdab**********'),
+ 'salt': u'abcdab**********',
'rounds': 1234,
- 'hash': u('v2RWkZ*************************************'),
+ 'hash': u'v2RWkZ*************************************',
})
#===================================================================
diff --git a/passlib/tests/test_handlers.py b/passlib/tests/test_handlers.py
index c90ebc3..5e613fb 100644
--- a/passlib/tests/test_handlers.py
+++ b/passlib/tests/test_handlers.py
@@ -12,7 +12,7 @@ import warnings
# pkg
from passlib import hash
from passlib.utils import repeat_string
-from passlib.utils.compat import irange, PY3, u, get_method_function
+from passlib.utils.compat import irange, PY3, get_method_function
from passlib.tests.utils import TestCase, HandlerCase, skipUnless, \
TEST_MODE, UserHandlerMixin, EncodingHandlerMixin
# module
@@ -22,9 +22,9 @@ from passlib.tests.utils import TestCase, HandlerCase, skipUnless, \
#=============================================================================
# some common unicode passwords which used as test cases
-UPASS_WAV = u('\u0399\u03c9\u03b1\u03bd\u03bd\u03b7\u03c2')
-UPASS_USD = u("\u20AC\u00A5$")
-UPASS_TABLE = u("t\u00e1\u0411\u2113\u0259")
+UPASS_WAV = u'\u0399\u03c9\u03b1\u03bd\u03bd\u03b7\u03c2'
+UPASS_USD = u"\u20AC\u00A5$"
+UPASS_TABLE = u"t\u00e1\u0411\u2113\u0259"
PASS_TABLE_UTF8 = b't\xc3\xa1\xd0\x91\xe2\x84\x93\xc9\x99' # utf-8
@@ -130,7 +130,7 @@ class bigcrypt_test(HandlerCase):
# check that _norm_checksum() also validates checksum size.
# (current code uses regex in parser)
self.assertRaises(ValueError, hash.bigcrypt, use_defaults=True,
- checksum=u('yh4XPJGsOZ'))
+ checksum=u'yh4XPJGsOZ')
#=============================================================================
# bsdi crypt
@@ -263,7 +263,7 @@ class _des_crypt_test(HandlerCase):
('AlOtBsOl', 'cEpWz5IUCShqM'),
# ensures utf-8 used for unicode
- (u('hell\u00D6'), 'saykDgk3BPZ9E'),
+ (u'hell\u00D6', 'saykDgk3BPZ9E'),
]
known_unidentified_hashes = [
# bad char in otherwise correctly formatted hash
@@ -348,11 +348,11 @@ class fshp_test(HandlerCase):
handler(variant=1, **kwds)
# accepts bytes or unicode
- handler(variant=u('1'), **kwds)
+ handler(variant=u'1', **kwds)
handler(variant=b'1', **kwds)
# aliases
- handler(variant=u('sha256'), **kwds)
+ handler(variant=u'sha256', **kwds)
handler(variant=b'sha256', **kwds)
# rejects None
@@ -612,14 +612,14 @@ class lmhash_test(EncodingHandlerMixin, HandlerCase):
('Yokohama', '5ecd9236d21095ce7584248b8d2c9f9e'),
# ensures cp437 used for unicode
- (u('ENCYCLOP\xC6DIA'), 'fed6416bffc9750d48462b9d7aaac065'),
- (u('encyclop\xE6dia'), 'fed6416bffc9750d48462b9d7aaac065'),
+ (u'ENCYCLOP\xC6DIA', 'fed6416bffc9750d48462b9d7aaac065'),
+ (u'encyclop\xE6dia', 'fed6416bffc9750d48462b9d7aaac065'),
# test various encoding values
- ((u("\xC6"), None), '25d8ab4a0659c97aaad3b435b51404ee'),
- ((u("\xC6"), "cp437"), '25d8ab4a0659c97aaad3b435b51404ee'),
- ((u("\xC6"), "latin-1"), '184eecbbe9991b44aad3b435b51404ee'),
- ((u("\xC6"), "utf-8"), '00dd240fcfab20b8aad3b435b51404ee'),
+ ((u"\xC6", None), '25d8ab4a0659c97aaad3b435b51404ee'),
+ ((u"\xC6", "cp437"), '25d8ab4a0659c97aaad3b435b51404ee'),
+ ((u"\xC6", "latin-1"), '184eecbbe9991b44aad3b435b51404ee'),
+ ((u"\xC6", "utf-8"), '00dd240fcfab20b8aad3b435b51404ee'),
]
known_unidentified_hashes = [
@@ -669,7 +669,7 @@ class _md5_crypt_test(HandlerCase):
('4lpHa N|_|M3r1K W/ Cur5Es: #$%(*)(*%#', '$1$jQS7o98J$V6iTcr71CGgwW2laf17pi1'),
('test', '$1$SuMrG47N$ymvzYjr7QcEQjaK5m1PGx1'),
(b'test', '$1$SuMrG47N$ymvzYjr7QcEQjaK5m1PGx1'),
- (u('s'), '$1$ssssssss$YgmLTApYTv12qgTwBoj8i/'),
+ (u's', '$1$ssssssss$YgmLTApYTv12qgTwBoj8i/'),
# ensures utf-8 used for unicode
(UPASS_TABLE, '$1$d6/Ky1lU$/xpf8m7ftmWLF.TjHCqel0'),
@@ -735,9 +735,9 @@ class msdcc_test(UserHandlerMixin, HandlerCase):
(("", "root"), "176a4c2bd45ac73687676c2f09045353"),
(("test1", "TEST1"), "64cd29e36a8431a2b111378564a10631"),
(("okolada", "nineteen_characters"), "290efa10307e36a79b3eebf2a6b29455"),
- ((u("\u00FC"), u("\u00FC")), "48f84e6f73d6d5305f6558a33fa2c9bb"),
- ((u("\u00FC\u00FC"), u("\u00FC\u00FC")), "593246a8335cf0261799bda2a2a9c623"),
- ((u("\u20AC\u20AC"), "user"), "9121790702dda0fa5d353014c334c2ce"),
+ ((u"\u00FC", u"\u00FC"), "48f84e6f73d6d5305f6558a33fa2c9bb"),
+ ((u"\u00FC\u00FC", u"\u00FC\u00FC"), "593246a8335cf0261799bda2a2a9c623"),
+ ((u"\u20AC\u20AC", "user"), "9121790702dda0fa5d353014c334c2ce"),
#
# custom
@@ -773,9 +773,9 @@ class msdcc2_test(UserHandlerMixin, HandlerCase):
(("test2", "TEST2"), "c6758e5be7fc943d00b97972a8a97620"),
(("test3", "test3"), "360e51304a2d383ea33467ab0b639cc4"),
(("test4", "test4"), "6f79ee93518306f071c47185998566ae"),
- ((u("\u00FC"), "joe"), "bdb80f2c4656a8b8591bd27d39064a54"),
- ((u("\u20AC\u20AC"), "joe"), "1e1e20f482ff748038e47d801d0d1bda"),
- ((u("\u00FC\u00FC"), "admin"), "0839e4a07c00f18a8c65cf5b985b9e73"),
+ ((u"\u00FC", "joe"), "bdb80f2c4656a8b8591bd27d39064a54"),
+ ((u"\u20AC\u20AC", "joe"), "1e1e20f482ff748038e47d801d0d1bda"),
+ ((u"\u00FC\u00FC", "admin"), "0839e4a07c00f18a8c65cf5b985b9e73"),
#
# custom
@@ -868,7 +868,7 @@ class mssql2000_test(HandlerCase):
known_malformed_hashes = [
# non-hex char -----\/
b'0x01005B200543327G2E1BC2E7C5DF0F9EBFE486E9BEE063E8D3B332752E1BC2E7C5DF0F9EBFE486E9BEE063E8D3B3',
- u('0x01005B200543327G2E1BC2E7C5DF0F9EBFE486E9BEE063E8D3B332752E1BC2E7C5DF0F9EBFE486E9BEE063E8D3B3'),
+ u'0x01005B200543327G2E1BC2E7C5DF0F9EBFE486E9BEE063E8D3B332752E1BC2E7C5DF0F9EBFE486E9BEE063E8D3B3',
]
class mssql2005_test(HandlerCase):
@@ -1029,8 +1029,8 @@ class nthash_test(HandlerCase):
#
# http://msdn.microsoft.com/en-us/library/cc245828(v=prot.10).aspx
#
- ("OLDPASSWORD", u("6677b2c394311355b54f25eec5bfacf5")),
- ("NEWPASSWORD", u("256781a62031289d3c2c98c14f1efc8c")),
+ ("OLDPASSWORD", u"6677b2c394311355b54f25eec5bfacf5"),
+ ("NEWPASSWORD", u"256781a62031289d3c2c98c14f1efc8c"),
#
# from JTR 1.7.9
@@ -1086,7 +1086,7 @@ class oracle10_test(UserHandlerMixin, HandlerCase):
# http://www.petefinnigan.com/default/default_password_list.htm
#
(('tiger', 'scott'), 'F894844C34402B67'),
- ((u('ttTiGGeR'), u('ScO')), '7AA1A84E31ED7771'),
+ ((u'ttTiGGeR', u'ScO'), '7AA1A84E31ED7771'),
(("d_syspw", "SYSTEM"), '1B9F1F9A5CB9EB31'),
(("strat_passwd", "strat_user"), 'AEBEDBB4EFB5225B'),
@@ -1324,7 +1324,7 @@ class _sha256_crypt_test(HandlerCase):
('test', '$5$rounds=11858$WH1ABM5sKhxbkgCK$aTQsjPkz0rBsH3lQlJxw9HDTDXPKBxC0LlVeV69P.t1'),
('Compl3X AlphaNu3meric', '$5$rounds=10350$o.pwkySLCzwTdmQX$nCMVsnF3TXWcBPOympBUUSQi6LGGloZoOsVJMGJ09UB'),
('4lpHa N|_|M3r1K W/ Cur5Es: #$%(*)(*%#', '$5$rounds=11944$9dhlu07dQMRWvTId$LyUI5VWkGFwASlzntk1RLurxX54LUhgAcJZIt0pYGT7'),
- (u('with unic\u00D6de'), '$5$rounds=1000$IbG0EuGQXw5EkMdP$LQ5AfPf13KufFsKtmazqnzSGZ4pxtUNw3woQ.ELRDF4'),
+ (u'with unic\u00D6de', '$5$rounds=1000$IbG0EuGQXw5EkMdP$LQ5AfPf13KufFsKtmazqnzSGZ4pxtUNw3woQ.ELRDF4'),
]
if TEST_MODE("full"):
diff --git a/passlib/tests/test_handlers_cisco.py b/passlib/tests/test_handlers_cisco.py
index ea6594b..f2c990e 100644
--- a/passlib/tests/test_handlers_cisco.py
+++ b/passlib/tests/test_handlers_cisco.py
@@ -11,7 +11,6 @@ log = logging.getLogger(__name__)
# site
# pkg
from passlib import hash, exc
-from passlib.utils.compat import u
from .utils import UserHandlerMixin, HandlerCase, repeat_string
from .test_handlers import UPASS_TABLE
# module
@@ -151,8 +150,8 @@ class _PixAsaSharedTest(UserHandlerMixin, HandlerCase):
# observed behaviors include:
# * ssh cli stripping non-ascii chars entirely
# * ASDM web iface double-encoding utf-8 strings
- ((u("t\xe1ble").encode("utf-8"), 'user'), 'Og8fB4NyF0m5Ed9c'),
- ((u("t\xe1ble").encode("utf-8").decode("latin-1").encode("utf-8"),
+ ((u"t\xe1ble".encode("utf-8"), 'user'), 'Og8fB4NyF0m5Ed9c'),
+ ((u"t\xe1ble".encode("utf-8").decode("latin-1").encode("utf-8"),
'user'), 'cMvFC2XVBmK/68yB'), # confirmed ASA 9.6 when typed into ASDM
]
diff --git a/passlib/tests/test_handlers_django.py b/passlib/tests/test_handlers_django.py
index 72e42a4..5333b7c 100644
--- a/passlib/tests/test_handlers_django.py
+++ b/passlib/tests/test_handlers_django.py
@@ -10,7 +10,6 @@ import warnings
# pkg
from passlib import hash
from passlib.utils import repeat_string
-from passlib.utils.compat import u
from passlib.tests.utils import TestCase, HandlerCase, skipUnless, SkipTest
from passlib.tests.test_handlers import UPASS_USD, UPASS_TABLE
from passlib.tests.test_ext_django import DJANGO_VERSION, MIN_DJANGO_VERSION
@@ -21,7 +20,7 @@ from passlib.tests.test_ext_django import DJANGO_VERSION, MIN_DJANGO_VERSION
#=============================================================================
# standard string django uses
-UPASS_LETMEIN = u('l\xe8tmein')
+UPASS_LETMEIN = u'l\xe8tmein'
def vstr(version):
return ".".join(str(e) for e in version)
@@ -136,7 +135,7 @@ class django_des_crypt_test(HandlerCase, _DjangoHelper):
# ensures utf-8 used for unicode
(UPASS_USD, 'crypt$c2e86$c2hN1Bxd6ZiWs'),
(UPASS_TABLE, 'crypt$0.aQs$0.wB.TT0Czvlo'),
- (u("hell\u00D6"), "crypt$sa$saykDgk3BPZ9E"),
+ (u"hell\u00D6", "crypt$sa$saykDgk3BPZ9E"),
# prevent regression of issue 22
("foo", 'crypt$MNVY.9ajgdvDQ$MNVY.9ajgdvDQ'),
diff --git a/passlib/tests/test_handlers_pbkdf2.py b/passlib/tests/test_handlers_pbkdf2.py
index 4d2f048..e1fa0c9 100644
--- a/passlib/tests/test_handlers_pbkdf2.py
+++ b/passlib/tests/test_handlers_pbkdf2.py
@@ -9,7 +9,6 @@ import warnings
# site
# pkg
from passlib import hash
-from passlib.utils.compat import u
from passlib.tests.utils import TestCase, HandlerCase
from passlib.tests.test_handlers import UPASS_WAV
# module
@@ -123,7 +122,7 @@ class cta_pbkdf2_sha1_test(HandlerCase):
#
# test vectors from original implementation
#
- (u("hashy the \N{SNOWMAN}"), '$p5k2$1000$ZxK4ZBJCfQg=$jJZVscWtO--p1-xIZl6jhO2LKR0='),
+ (u"hashy the \N{SNOWMAN}", '$p5k2$1000$ZxK4ZBJCfQg=$jJZVscWtO--p1-xIZl6jhO2LKR0='),
#
# custom
@@ -201,11 +200,11 @@ class scram_test(HandlerCase):
# test unicode passwords & saslprep (all the passwords below
# should normalize to the same value: 'IX \xE0')
- (u('IX \xE0'), '$scram$6400$0BojBCBE6P2/N4bQ$'
+ (u'IX \xE0', '$scram$6400$0BojBCBE6P2/N4bQ$'
'sha-1=YniLes.b8WFMvBhtSACZyyvxeCc'),
- (u('\u2168\u3000a\u0300'), '$scram$6400$0BojBCBE6P2/N4bQ$'
+ (u'\u2168\u3000a\u0300', '$scram$6400$0BojBCBE6P2/N4bQ$'
'sha-1=YniLes.b8WFMvBhtSACZyyvxeCc'),
- (u('\u00ADIX \xE0'), '$scram$6400$0BojBCBE6P2/N4bQ$'
+ (u'\u00ADIX \xE0', '$scram$6400$0BojBCBE6P2/N4bQ$'
'sha-1=YniLes.b8WFMvBhtSACZyyvxeCc'),
]
@@ -287,7 +286,7 @@ class scram_test(HandlerCase):
"""test internal parsing of 'checksum' keyword"""
# check non-bytes checksum values are rejected
self.assertRaises(TypeError, self.handler, use_defaults=True,
- checksum={'sha-1': u('X')*20})
+ checksum={'sha-1': u'X'*20})
# check sha-1 is required
self.assertRaises(ValueError, self.handler, use_defaults=True,
@@ -340,9 +339,9 @@ class scram_test(HandlerCase):
# check various encodings of password work.
s1 = b'\x01\x02\x03'
d1 = b'\xb2\xfb\xab\x82[tNuPnI\x8aZZ\x19\x87\xcen\xe9\xd3'
- self.assertEqual(hash(u("\u2168"), s1, 1000, 'sha-1'), d1)
+ self.assertEqual(hash(u"\u2168", s1, 1000, 'sha-1'), d1)
self.assertEqual(hash(b"\xe2\x85\xa8", s1, 1000, 'SHA-1'), d1)
- self.assertEqual(hash(u("IX"), s1, 1000, 'sha1'), d1)
+ self.assertEqual(hash(u"IX", s1, 1000, 'sha1'), d1)
self.assertEqual(hash(b"IX", s1, 1000, 'SHA1'), d1)
# check algs
@@ -354,7 +353,7 @@ class scram_test(HandlerCase):
self.assertRaises(ValueError, hash, "IX", s1, 0, 'sha-1')
# unicode salts accepted as of passlib 1.7 (previous caused TypeError)
- self.assertEqual(hash(u("IX"), s1.decode("latin-1"), 1000, 'sha1'), d1)
+ self.assertEqual(hash(u"IX", s1.decode("latin-1"), 1000, 'sha1'), d1)
def test_94_saslprep(self):
"""test hash/verify use saslprep"""
@@ -363,18 +362,18 @@ class scram_test(HandlerCase):
# to verify full normalization behavior.
# hash unnormalized
- h = self.do_encrypt(u("I\u00ADX"))
- self.assertTrue(self.do_verify(u("IX"), h))
- self.assertTrue(self.do_verify(u("\u2168"), h))
+ h = self.do_encrypt(u"I\u00ADX")
+ self.assertTrue(self.do_verify(u"IX", h))
+ self.assertTrue(self.do_verify(u"\u2168", h))
# hash normalized
- h = self.do_encrypt(u("\xF3"))
- self.assertTrue(self.do_verify(u("o\u0301"), h))
- self.assertTrue(self.do_verify(u("\u200Do\u0301"), h))
+ h = self.do_encrypt(u"\xF3")
+ self.assertTrue(self.do_verify(u"o\u0301", h))
+ self.assertTrue(self.do_verify(u"\u200Do\u0301", h))
# throws error if forbidden char provided
- self.assertRaises(ValueError, self.do_encrypt, u("\uFDD0"))
- self.assertRaises(ValueError, self.do_verify, u("\uFDD0"), h)
+ self.assertRaises(ValueError, self.do_encrypt, u"\uFDD0")
+ self.assertRaises(ValueError, self.do_verify, u"\uFDD0", h)
def test_94_using_w_default_algs(self, param="default_algs"):
"""using() -- 'default_algs' parameter"""
diff --git a/passlib/tests/test_totp.py b/passlib/tests/test_totp.py
index 1229da7..b2afa72 100644
--- a/passlib/tests/test_totp.py
+++ b/passlib/tests/test_totp.py
@@ -11,7 +11,7 @@ import time as _time
# site
# pkg
from passlib import exc
-from passlib.utils.compat import unicode, u
+from passlib.utils.compat import unicode
from passlib.tests.utils import TestCase, time_call
# subject
from passlib import totp as totp_module
@@ -174,7 +174,7 @@ class AppWalletTest(TestCase):
self.assertEqual(wallet._secrets, ref)
# accept unicode
- wallet = AppWallet({u("1"): b"aaa", u("02"): b"bbb", u("C"): b"ccc"})
+ wallet = AppWallet({u"1": b"aaa", u"02": b"bbb", u"C": b"ccc"})
self.assertEqual(wallet._secrets, ref)
# normalize int tags
@@ -192,7 +192,7 @@ class AppWalletTest(TestCase):
self.assertRaises(ValueError, AppWallet, {"ab*$": "aaa"})
# coerce value to bytes
- wallet = AppWallet({"1": u("aaa"), "02": "bbb", "C": b"ccc"})
+ wallet = AppWallet({"1": u"aaa", "02": "bbb", "C": b"ccc"})
self.assertEqual(wallet._secrets, ref)
# forbid invalid value types
@@ -747,7 +747,7 @@ class TotpTest(TestCase):
otp = self.randotp(digits=7)
# unicode & bytes
- self.assertEqual(otp.normalize_token(u('1234567')), '1234567')
+ self.assertEqual(otp.normalize_token(u'1234567'), '1234567')
self.assertEqual(otp.normalize_token(b'1234567'), '1234567')
# int
@@ -1202,8 +1202,8 @@ class TotpTest(TestCase):
from_source = TOTP.from_source
# uri (unicode)
- otp = from_source(u("otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&"
- "issuer=Example"))
+ otp = from_source(u"otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&"
+ "issuer=Example")
self.assertEqual(otp.key, KEY4_RAW)
# uri (bytes)
@@ -1216,7 +1216,7 @@ class TotpTest(TestCase):
self.assertEqual(otp.key, KEY4_RAW)
# json (unicode)
- otp = from_source(u('{"v": 1, "type": "totp", "key": "JBSWY3DPEHPK3PXP"}'))
+ otp = from_source(u'{"v": 1, "type": "totp", "key": "JBSWY3DPEHPK3PXP"}')
self.assertEqual(otp.key, KEY4_RAW)
# json (bytes)
@@ -1237,7 +1237,7 @@ class TotpTest(TestCase):
self.assertIs(otp2, otp1)
# random string
- self.assertRaises(ValueError, from_source, u("foo"))
+ self.assertRaises(ValueError, from_source, u"foo")
self.assertRaises(ValueError, from_source, b"foo")
#=============================================================================
diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py
index 3fd0001..59e7c01 100644
--- a/passlib/tests/test_utils.py
+++ b/passlib/tests/test_utils.py
@@ -10,7 +10,7 @@ import warnings
# pkg
# module
from passlib.utils import is_ascii_safe
-from passlib.utils.compat import irange, PY2, PY3, u, unicode, join_bytes, PYPY
+from passlib.utils.compat import irange, PY2, PY3, unicode, join_bytes, PYPY
from passlib.tests.utils import TestCase, hb, run_with_fixed_seeds
#=============================================================================
@@ -124,11 +124,11 @@ class MiscTest(TestCase):
# and hope that they're sufficient to test the range of behavior.
# letters
- x = wrapper(u('abc'), 32)
- y = wrapper(u('abc'), 32)
+ x = wrapper(u'abc', 32)
+ y = wrapper(u'abc', 32)
self.assertIsInstance(x, unicode)
self.assertNotEqual(x,y)
- self.assertEqual(sorted(set(x)), [u('a'),u('b'),u('c')])
+ self.assertEqual(sorted(set(x)), [u'a',u'b',u'c'])
# bytes
x = wrapper(b'abc', 32)
@@ -136,7 +136,7 @@ class MiscTest(TestCase):
self.assertIsInstance(x, bytes)
self.assertNotEqual(x,y)
# NOTE: decoding this due to py3 bytes
- self.assertEqual(sorted(set(x.decode("ascii"))), [u('a'),u('b'),u('c')])
+ self.assertEqual(sorted(set(x.decode("ascii"))), [u'a',u'b',u'c'])
def test_generate_password(self):
"""generate_password()"""
@@ -180,16 +180,16 @@ class MiscTest(TestCase):
# if this fails for some platform, this test will need modifying.
# test return type
- self.assertIsInstance(safe_crypt(u("test"), u("aa")), unicode)
+ self.assertIsInstance(safe_crypt(u"test", u"aa"), unicode)
# test ascii password
- h1 = u('aaqPiZY5xR5l.')
- self.assertEqual(safe_crypt(u('test'), u('aa')), h1)
+ h1 = u'aaqPiZY5xR5l.'
+ self.assertEqual(safe_crypt(u'test', u'aa'), h1)
self.assertEqual(safe_crypt(b'test', b'aa'), h1)
# test utf-8 / unicode password
- h2 = u('aahWwbrUsKZk.')
- self.assertEqual(safe_crypt(u('test\u1234'), 'aa'), h2)
+ h2 = u'aahWwbrUsKZk.'
+ self.assertEqual(safe_crypt(u'test\u1234', 'aa'), h2)
self.assertEqual(safe_crypt(b'test\xe1\x88\xb4', 'aa'), h2)
# test latin-1 password
@@ -197,7 +197,7 @@ class MiscTest(TestCase):
if PY3: # py3 supports utf-8 bytes only.
self.assertEqual(hash, None)
else: # but py2 is fine.
- self.assertEqual(hash, u('aaOx.5nbTU/.M'))
+ self.assertEqual(hash, u'aaOx.5nbTU/.M')
# test rejects null chars in password
self.assertRaises(ValueError, safe_crypt, '\x00', 'aa')
@@ -230,17 +230,17 @@ class MiscTest(TestCase):
from passlib.utils import consteq, str_consteq
# ensure error raises for wrong types
- self.assertRaises(TypeError, consteq, u(''), b'')
- self.assertRaises(TypeError, consteq, u(''), 1)
- self.assertRaises(TypeError, consteq, u(''), None)
+ self.assertRaises(TypeError, consteq, u'', b'')
+ self.assertRaises(TypeError, consteq, u'', 1)
+ self.assertRaises(TypeError, consteq, u'', None)
- self.assertRaises(TypeError, consteq, b'', u(''))
+ self.assertRaises(TypeError, consteq, b'', u'')
self.assertRaises(TypeError, consteq, b'', 1)
self.assertRaises(TypeError, consteq, b'', None)
- self.assertRaises(TypeError, consteq, None, u(''))
+ self.assertRaises(TypeError, consteq, None, u'')
self.assertRaises(TypeError, consteq, None, b'')
- self.assertRaises(TypeError, consteq, 1, u(''))
+ self.assertRaises(TypeError, consteq, 1, u'')
self.assertRaises(TypeError, consteq, 1, b'')
def consteq_supports_string(value):
@@ -251,9 +251,9 @@ class MiscTest(TestCase):
# check equal inputs compare correctly
for value in [
- u("a"),
- u("abc"),
- u("\xff\xa2\x12\x00")*10,
+ u"a",
+ u"abc",
+ u"\xff\xa2\x12\x00"*10,
]:
if consteq_supports_string(value):
self.assertTrue(consteq(value, value), "value %r:" % (value,))
@@ -267,18 +267,18 @@ class MiscTest(TestCase):
# check non-equal inputs compare correctly
for l,r in [
# check same-size comparisons with differing contents fail.
- (u("a"), u("c")),
- (u("abcabc"), u("zbaabc")),
- (u("abcabc"), u("abzabc")),
- (u("abcabc"), u("abcabz")),
- ((u("\xff\xa2\x12\x00")*10)[:-1] + u("\x01"),
- u("\xff\xa2\x12\x00")*10),
+ (u"a", u"c"),
+ (u"abcabc", u"zbaabc"),
+ (u"abcabc", u"abzabc"),
+ (u"abcabc", u"abcabz"),
+ ((u"\xff\xa2\x12\x00"*10)[:-1] + u"\x01",
+ u"\xff\xa2\x12\x00"*10),
# check different-size comparisons fail.
- (u(""), u("a")),
- (u("abc"), u("abcdef")),
- (u("abc"), u("defabc")),
- (u("qwertyuiopasdfghjklzxcvbnm"), u("abc")),
+ (u"", u"a"),
+ (u"abc", u"abcdef"),
+ (u"abc", u"defabc"),
+ (u"qwertyuiopasdfghjklzxcvbnm", u"abc"),
]:
if consteq_supports_string(l) and consteq_supports_string(r):
self.assertFalse(consteq(l, r), "values %r %r:" % (l,r))
@@ -336,73 +336,73 @@ class MiscTest(TestCase):
self.assertRaises(TypeError, sp, b'')
# empty strings
- self.assertEqual(sp(u('')), u(''))
- self.assertEqual(sp(u('\u00AD')), u(''))
+ self.assertEqual(sp(u''), u'')
+ self.assertEqual(sp(u'\u00AD'), u'')
# verify B.1 chars are stripped,
- self.assertEqual(sp(u("$\u00AD$\u200D$")), u("$$$"))
+ self.assertEqual(sp(u"$\u00AD$\u200D$"), u"$$$")
# verify C.1.2 chars are replaced with space
- self.assertEqual(sp(u("$ $\u00A0$\u3000$")), u("$ $ $ $"))
+ self.assertEqual(sp(u"$ $\u00A0$\u3000$"), u"$ $ $ $")
# verify normalization to KC
- self.assertEqual(sp(u("a\u0300")), u("\u00E0"))
- self.assertEqual(sp(u("\u00E0")), u("\u00E0"))
+ self.assertEqual(sp(u"a\u0300"), u"\u00E0")
+ self.assertEqual(sp(u"\u00E0"), u"\u00E0")
# verify various forbidden characters
# control chars
- self.assertRaises(ValueError, sp, u("\u0000"))
- self.assertRaises(ValueError, sp, u("\u007F"))
- self.assertRaises(ValueError, sp, u("\u180E"))
- self.assertRaises(ValueError, sp, u("\uFFF9"))
+ self.assertRaises(ValueError, sp, u"\u0000")
+ self.assertRaises(ValueError, sp, u"\u007F")
+ self.assertRaises(ValueError, sp, u"\u180E")
+ self.assertRaises(ValueError, sp, u"\uFFF9")
# private use
- self.assertRaises(ValueError, sp, u("\uE000"))
+ self.assertRaises(ValueError, sp, u"\uE000")
# non-characters
- self.assertRaises(ValueError, sp, u("\uFDD0"))
+ self.assertRaises(ValueError, sp, u"\uFDD0")
# surrogates
- self.assertRaises(ValueError, sp, u("\uD800"))
+ self.assertRaises(ValueError, sp, u"\uD800")
# non-plaintext chars
- self.assertRaises(ValueError, sp, u("\uFFFD"))
+ self.assertRaises(ValueError, sp, u"\uFFFD")
# non-canon
- self.assertRaises(ValueError, sp, u("\u2FF0"))
+ self.assertRaises(ValueError, sp, u"\u2FF0")
# change display properties
- self.assertRaises(ValueError, sp, u("\u200E"))
- self.assertRaises(ValueError, sp, u("\u206F"))
+ self.assertRaises(ValueError, sp, u"\u200E")
+ self.assertRaises(ValueError, sp, u"\u206F")
# unassigned code points (as of unicode 3.2)
- self.assertRaises(ValueError, sp, u("\u0900"))
- self.assertRaises(ValueError, sp, u("\uFFF8"))
+ self.assertRaises(ValueError, sp, u"\u0900")
+ self.assertRaises(ValueError, sp, u"\uFFF8")
# tagging characters
- self.assertRaises(ValueError, sp, u("\U000e0001"))
+ self.assertRaises(ValueError, sp, u"\U000e0001")
# verify bidi behavior
# if starts with R/AL -- must end with R/AL
- self.assertRaises(ValueError, sp, u("\u0627\u0031"))
- self.assertEqual(sp(u("\u0627")), u("\u0627"))
- self.assertEqual(sp(u("\u0627\u0628")), u("\u0627\u0628"))
- self.assertEqual(sp(u("\u0627\u0031\u0628")), u("\u0627\u0031\u0628"))
+ self.assertRaises(ValueError, sp, u"\u0627\u0031")
+ self.assertEqual(sp(u"\u0627"), u"\u0627")
+ self.assertEqual(sp(u"\u0627\u0628"), u"\u0627\u0628")
+ self.assertEqual(sp(u"\u0627\u0031\u0628"), u"\u0627\u0031\u0628")
# if starts with R/AL -- cannot contain L
- self.assertRaises(ValueError, sp, u("\u0627\u0041\u0628"))
+ self.assertRaises(ValueError, sp, u"\u0627\u0041\u0628")
# if doesn't start with R/AL -- can contain R/AL, but L & EN allowed
- self.assertRaises(ValueError, sp, u("x\u0627z"))
- self.assertEqual(sp(u("x\u0041z")), u("x\u0041z"))
+ self.assertRaises(ValueError, sp, u"x\u0627z")
+ self.assertEqual(sp(u"x\u0041z"), u"x\u0041z")
#------------------------------------------------------
# examples pulled from external sources, to be thorough
#------------------------------------------------------
# rfc 4031 section 3 examples
- self.assertEqual(sp(u("I\u00ADX")), u("IX")) # strip SHY
- self.assertEqual(sp(u("user")), u("user")) # unchanged
- self.assertEqual(sp(u("USER")), u("USER")) # case preserved
- self.assertEqual(sp(u("\u00AA")), u("a")) # normalize to KC form
- self.assertEqual(sp(u("\u2168")), u("IX")) # normalize to KC form
- self.assertRaises(ValueError, sp, u("\u0007")) # forbid control chars
- self.assertRaises(ValueError, sp, u("\u0627\u0031")) # invalid bidi
+ self.assertEqual(sp(u"I\u00ADX"), u"IX") # strip SHY
+ self.assertEqual(sp(u"user"), u"user") # unchanged
+ self.assertEqual(sp(u"USER"), u"USER") # case preserved
+ self.assertEqual(sp(u"\u00AA"), u"a") # normalize to KC form
+ self.assertEqual(sp(u"\u2168"), u"IX") # normalize to KC form
+ self.assertRaises(ValueError, sp, u"\u0007") # forbid control chars
+ self.assertRaises(ValueError, sp, u"\u0627\u0031") # invalid bidi
# rfc 3454 section 6 examples
# starts with RAL char, must end with RAL char
- self.assertRaises(ValueError, sp, u("\u0627\u0031"))
- self.assertEqual(sp(u("\u0627\u0031\u0628")), u("\u0627\u0031\u0628"))
+ self.assertRaises(ValueError, sp, u"\u0627\u0031")
+ self.assertEqual(sp(u"\u0627\u0031\u0628"), u"\u0627\u0031\u0628")
def test_splitcomma(self):
from passlib.utils import splitcomma
@@ -440,12 +440,12 @@ class CodecTest(TestCase):
from passlib.utils import to_bytes
# check unicode inputs
- self.assertEqual(to_bytes(u('abc')), b'abc')
- self.assertEqual(to_bytes(u('\x00\xff')), b'\x00\xc3\xbf')
+ self.assertEqual(to_bytes(u'abc'), b'abc')
+ self.assertEqual(to_bytes(u'\x00\xff'), b'\x00\xc3\xbf')
# check unicode w/ encodings
- self.assertEqual(to_bytes(u('\x00\xff'), 'latin-1'), b'\x00\xff')
- self.assertRaises(ValueError, to_bytes, u('\x00\xff'), 'ascii')
+ self.assertEqual(to_bytes(u'\x00\xff', 'latin-1'), b'\x00\xff')
+ self.assertRaises(ValueError, to_bytes, u'\x00\xff', 'ascii')
# check bytes inputs
self.assertEqual(to_bytes(b'abc'), b'abc')
@@ -469,17 +469,17 @@ class CodecTest(TestCase):
from passlib.utils import to_unicode
# check unicode inputs
- self.assertEqual(to_unicode(u('abc')), u('abc'))
- self.assertEqual(to_unicode(u('\x00\xff')), u('\x00\xff'))
+ self.assertEqual(to_unicode(u'abc'), u'abc')
+ self.assertEqual(to_unicode(u'\x00\xff'), u'\x00\xff')
# check unicode input ignores encoding
- self.assertEqual(to_unicode(u('\x00\xff'), "ascii"), u('\x00\xff'))
+ self.assertEqual(to_unicode(u'\x00\xff', "ascii"), u'\x00\xff')
# check bytes input
- self.assertEqual(to_unicode(b'abc'), u('abc'))
- self.assertEqual(to_unicode(b'\x00\xc3\xbf'), u('\x00\xff'))
+ self.assertEqual(to_unicode(b'abc'), u'abc')
+ self.assertEqual(to_unicode(b'\x00\xc3\xbf'), u'\x00\xff')
self.assertEqual(to_unicode(b'\x00\xff', 'latin-1'),
- u('\x00\xff'))
+ u'\x00\xff')
self.assertRaises(ValueError, to_unicode, b'\x00\xff')
# check other
@@ -491,25 +491,25 @@ class CodecTest(TestCase):
from passlib.utils import to_native_str
# test plain ascii
- self.assertEqual(to_native_str(u('abc'), 'ascii'), 'abc')
+ self.assertEqual(to_native_str(u'abc', 'ascii'), 'abc')
self.assertEqual(to_native_str(b'abc', 'ascii'), 'abc')
# test invalid ascii
if PY3:
- self.assertEqual(to_native_str(u('\xE0'), 'ascii'), '\xE0')
+ self.assertEqual(to_native_str(u'\xE0', 'ascii'), '\xE0')
self.assertRaises(UnicodeDecodeError, to_native_str, b'\xC3\xA0',
'ascii')
else:
- self.assertRaises(UnicodeEncodeError, to_native_str, u('\xE0'),
+ self.assertRaises(UnicodeEncodeError, to_native_str, u'\xE0',
'ascii')
self.assertEqual(to_native_str(b'\xC3\xA0', 'ascii'), '\xC3\xA0')
# test latin-1
- self.assertEqual(to_native_str(u('\xE0'), 'latin-1'), '\xE0')
+ self.assertEqual(to_native_str(u'\xE0', 'latin-1'), '\xE0')
self.assertEqual(to_native_str(b'\xE0', 'latin-1'), '\xE0')
# test utf-8
- self.assertEqual(to_native_str(u('\xE0'), 'utf-8'),
+ self.assertEqual(to_native_str(u'\xE0', 'utf-8'),
'\xE0' if PY3 else '\xC3\xA0')
self.assertEqual(to_native_str(b'\xC3\xA0', 'utf-8'),
'\xE0' if PY3 else '\xC3\xA0')
@@ -521,9 +521,9 @@ class CodecTest(TestCase):
"""test is_ascii_safe()"""
from passlib.utils import is_ascii_safe
self.assertTrue(is_ascii_safe(b"\x00abc\x7f"))
- self.assertTrue(is_ascii_safe(u("\x00abc\x7f")))
+ self.assertTrue(is_ascii_safe(u"\x00abc\x7f"))
self.assertFalse(is_ascii_safe(b"\x00abc\x80"))
- self.assertFalse(is_ascii_safe(u("\x00abc\x80")))
+ self.assertFalse(is_ascii_safe(u"\x00abc\x80"))
def test_is_same_codec(self):
"""test is_same_codec()"""
@@ -566,15 +566,15 @@ class Base64EngineTest(TestCase):
# accept bytes or unicode
self.assertEqual(ab64_decode(b"abc"), hb("69b7"))
- self.assertEqual(ab64_decode(u("abc")), hb("69b7"))
+ self.assertEqual(ab64_decode(u"abc"), hb("69b7"))
# reject non-ascii unicode
- self.assertRaises(ValueError, ab64_decode, u("ab\xff"))
+ self.assertRaises(ValueError, ab64_decode, u"ab\xff")
# underlying a2b_ascii treats non-base64 chars as "Incorrect padding"
self.assertRaises(TypeError, ab64_decode, b"ab\xff")
self.assertRaises(TypeError, ab64_decode, b"ab!")
- self.assertRaises(TypeError, ab64_decode, u("ab!"))
+ self.assertRaises(TypeError, ab64_decode, u"ab!")
# insert correct padding, handle dirty padding bits
self.assertEqual(ab64_decode(b"abcd"), hb("69b71d")) # 0 mod 4
@@ -613,15 +613,15 @@ class Base64EngineTest(TestCase):
# accept bytes or unicode
self.assertEqual(b64s_decode(b"abc"), hb("69b7"))
- self.assertEqual(b64s_decode(u("abc")), hb("69b7"))
+ self.assertEqual(b64s_decode(u"abc"), hb("69b7"))
# reject non-ascii unicode
- self.assertRaises(ValueError, b64s_decode, u("ab\xff"))
+ self.assertRaises(ValueError, b64s_decode, u"ab\xff")
# underlying a2b_ascii treats non-base64 chars as "Incorrect padding"
self.assertRaises(TypeError, b64s_decode, b"ab\xff")
self.assertRaises(TypeError, b64s_decode, b"ab!")
- self.assertRaises(TypeError, b64s_decode, u("ab!"))
+ self.assertRaises(TypeError, b64s_decode, u"ab!")
# insert correct padding, handle dirty padding bits
self.assertEqual(b64s_decode(b"abcd"), hb("69b71d")) # 0 mod 4
@@ -687,7 +687,7 @@ class _Base64Test(TestCase):
"""test encode_bytes() with bad input"""
engine = self.engine
encode = engine.encode_bytes
- self.assertRaises(TypeError, encode, u('\x00'))
+ self.assertRaises(TypeError, encode, u'\x00')
self.assertRaises(TypeError, encode, None)
#===================================================================
@@ -851,7 +851,7 @@ class _Base64Test(TestCase):
out = engine.decode_bytes(tmp)
self.assertEqual(out, result)
- self.assertRaises(TypeError, engine.encode_transposed_bytes, u("a"), [])
+ self.assertRaises(TypeError, engine.encode_transposed_bytes, u"a", [])
def test_decode_transposed_bytes(self):
"""test decode_transposed_bytes()"""
diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py
index 4f67006..967dbf4 100644
--- a/passlib/tests/test_utils_handlers.py
+++ b/passlib/tests/test_utils_handlers.py
@@ -16,7 +16,6 @@ from passlib.utils.compat import str_to_uascii, \
uascii_to_str, unicode
import passlib.utils.handlers as uh
from passlib.tests.utils import HandlerCase, TestCase
-from passlib.utils.compat import u
# module
log = getLogger(__name__)
@@ -50,8 +49,8 @@ class SkeletonTest(TestCase):
class d1(uh.StaticHandler):
name = "d1"
context_kwds = ("flag",)
- _hash_prefix = u("_")
- checksum_chars = u("ab")
+ _hash_prefix = u"_"
+ checksum_chars = u"ab"
checksum_size = 1
def __init__(self, flag=False, **kwds):
@@ -59,18 +58,18 @@ class SkeletonTest(TestCase):
self.flag = flag
def _calc_checksum(self, secret):
- return u('b') if self.flag else u('a')
+ return u'b' if self.flag else u'a'
# check default identify method
- self.assertTrue(d1.identify(u('_a')))
+ self.assertTrue(d1.identify(u'_a'))
self.assertTrue(d1.identify(b'_a'))
- self.assertTrue(d1.identify(u('_b')))
+ self.assertTrue(d1.identify(u'_b'))
- self.assertFalse(d1.identify(u('_c')))
+ self.assertFalse(d1.identify(u'_c'))
self.assertFalse(d1.identify(b'_c'))
- self.assertFalse(d1.identify(u('a')))
- self.assertFalse(d1.identify(u('b')))
- self.assertFalse(d1.identify(u('c')))
+ self.assertFalse(d1.identify(u'a'))
+ self.assertFalse(d1.identify(u'b'))
+ self.assertFalse(d1.identify(u'c'))
self.assertRaises(TypeError, d1.identify, None)
self.assertRaises(TypeError, d1.identify, 1)
@@ -79,12 +78,12 @@ class SkeletonTest(TestCase):
# check default verify method
self.assertTrue(d1.verify('s', b'_a'))
- self.assertTrue(d1.verify('s',u('_a')))
+ self.assertTrue(d1.verify('s',u'_a'))
self.assertFalse(d1.verify('s', b'_b'))
- self.assertFalse(d1.verify('s',u('_b')))
+ self.assertFalse(d1.verify('s',u'_b'))
self.assertTrue(d1.verify('s', b'_b', flag=True))
self.assertRaises(ValueError, d1.verify, 's', b'_c')
- self.assertRaises(ValueError, d1.verify, 's', u('_c'))
+ self.assertRaises(ValueError, d1.verify, 's', u'_c')
# check default hash method
self.assertEqual(d1.hash('s'), '_a')
@@ -100,7 +99,7 @@ class SkeletonTest(TestCase):
def from_string(cls, hash):
if isinstance(hash, bytes):
hash = hash.decode("ascii")
- if hash == u('a'):
+ if hash == u'a':
return cls(checksum=hash)
else:
raise ValueError
@@ -113,7 +112,7 @@ class SkeletonTest(TestCase):
self.assertFalse(d1.identify('b'))
# check regexp
- d1._hash_regex = re.compile(u('@.'))
+ d1._hash_regex = re.compile(u'@.')
self.assertRaises(TypeError, d1.identify, None)
self.assertRaises(TypeError, d1.identify, 1)
self.assertTrue(d1.identify('@a'))
@@ -121,7 +120,7 @@ class SkeletonTest(TestCase):
del d1._hash_regex
# check ident-based
- d1.ident = u('!')
+ d1.ident = u'!'
self.assertRaises(TypeError, d1.identify, None)
self.assertRaises(TypeError, d1.identify, 1)
self.assertTrue(d1.identify('!a'))
@@ -134,23 +133,23 @@ class SkeletonTest(TestCase):
class d1(uh.GenericHandler):
name = 'd1'
checksum_size = 4
- checksum_chars = u('xz')
+ checksum_chars = u'xz'
def norm_checksum(checksum=None, **k):
return d1(checksum=checksum, **k).checksum
# too small
- self.assertRaises(ValueError, norm_checksum, u('xxx'))
+ self.assertRaises(ValueError, norm_checksum, u'xxx')
# right size
- self.assertEqual(norm_checksum(u('xxxx')), u('xxxx'))
- self.assertEqual(norm_checksum(u('xzxz')), u('xzxz'))
+ self.assertEqual(norm_checksum(u'xxxx'), u'xxxx')
+ self.assertEqual(norm_checksum(u'xzxz'), u'xzxz')
# too large
- self.assertRaises(ValueError, norm_checksum, u('xxxxx'))
+ self.assertRaises(ValueError, norm_checksum, u'xxxxx')
# wrong chars
- self.assertRaises(ValueError, norm_checksum, u('xxyx'))
+ self.assertRaises(ValueError, norm_checksum, u'xxyx')
# wrong type
self.assertRaises(TypeError, norm_checksum, b'xxyx')
@@ -158,11 +157,11 @@ class SkeletonTest(TestCase):
# relaxed
# NOTE: this could be turned back on if we test _norm_checksum() directly...
#with self.assertWarningList("checksum should be unicode"):
- # self.assertEqual(norm_checksum(b'xxzx', relaxed=True), u('xxzx'))
+ # self.assertEqual(norm_checksum(b'xxzx', relaxed=True), u'xxzx')
#self.assertRaises(TypeError, norm_checksum, 1, relaxed=True)
# test _stub_checksum behavior
- self.assertEqual(d1()._stub_checksum, u('xxxx'))
+ self.assertEqual(d1()._stub_checksum, u'xxxx')
def test_12_norm_checksum_raw(self):
"""test GenericHandler + HasRawChecksum mixin"""
@@ -177,10 +176,10 @@ class SkeletonTest(TestCase):
self.assertEqual(norm_checksum(b'1234'), b'1234')
# test unicode
- self.assertRaises(TypeError, norm_checksum, u('xxyx'))
+ self.assertRaises(TypeError, norm_checksum, u'xxyx')
# NOTE: this could be turned back on if we test _norm_checksum() directly...
- # self.assertRaises(TypeError, norm_checksum, u('xxyx'), relaxed=True)
+ # self.assertRaises(TypeError, norm_checksum, u'xxyx', relaxed=True)
# test _stub_checksum behavior
self.assertEqual(d1()._stub_checksum, b'\x00'*4)
@@ -439,9 +438,9 @@ class SkeletonTest(TestCase):
class d1(uh.HasManyIdents, uh.GenericHandler):
name = 'd1'
setting_kwds = ('ident',)
- default_ident = u("!A")
- ident_values = (u("!A"), u("!B"))
- ident_aliases = { u("A"): u("!A")}
+ default_ident = u"!A"
+ ident_values = (u"!A", u"!B")
+ ident_aliases = { u"A": u"!A"}
def norm_ident(**k):
return d1(**k).ident
@@ -449,25 +448,25 @@ class SkeletonTest(TestCase):
# check ident=None
self.assertRaises(TypeError, norm_ident)
self.assertRaises(TypeError, norm_ident, ident=None)
- self.assertEqual(norm_ident(use_defaults=True), u('!A'))
+ self.assertEqual(norm_ident(use_defaults=True), u'!A')
# check valid idents
- self.assertEqual(norm_ident(ident=u('!A')), u('!A'))
- self.assertEqual(norm_ident(ident=u('!B')), u('!B'))
- self.assertRaises(ValueError, norm_ident, ident=u('!C'))
+ self.assertEqual(norm_ident(ident=u'!A'), u'!A')
+ self.assertEqual(norm_ident(ident=u'!B'), u'!B')
+ self.assertRaises(ValueError, norm_ident, ident=u'!C')
# check aliases
- self.assertEqual(norm_ident(ident=u('A')), u('!A'))
+ self.assertEqual(norm_ident(ident=u'A'), u'!A')
# check invalid idents
- self.assertRaises(ValueError, norm_ident, ident=u('B'))
+ self.assertRaises(ValueError, norm_ident, ident=u'B')
# check identify is honoring ident system
- self.assertTrue(d1.identify(u("!Axxx")))
- self.assertTrue(d1.identify(u("!Bxxx")))
- self.assertFalse(d1.identify(u("!Cxxx")))
- self.assertFalse(d1.identify(u("A")))
- self.assertFalse(d1.identify(u("")))
+ self.assertTrue(d1.identify(u"!Axxx"))
+ self.assertTrue(d1.identify(u"!Bxxx"))
+ self.assertFalse(d1.identify(u"!Cxxx"))
+ self.assertFalse(d1.identify(u"A"))
+ self.assertFalse(d1.identify(u""))
self.assertRaises(TypeError, d1.identify, None)
self.assertRaises(TypeError, d1.identify, 1)
@@ -490,12 +489,12 @@ class SkeletonTest(TestCase):
# simple hash w/ salt
result = hash.des_crypt.parsehash("OgAwTx2l6NADI")
- self.assertEqual(result, {'checksum': u('AwTx2l6NADI'), 'salt': u('Og')})
+ self.assertEqual(result, {'checksum': u'AwTx2l6NADI', 'salt': u'Og'})
# parse rounds and extra implicit_rounds flag
h = '$5$LKO/Ute40T3FNF95$U0prpBQd4PloSGU0pnpM4z9wKn4vZ1.jsrzQfPqxph9'
- s = u('LKO/Ute40T3FNF95')
- c = u('U0prpBQd4PloSGU0pnpM4z9wKn4vZ1.jsrzQfPqxph9')
+ s = u'LKO/Ute40T3FNF95'
+ c = u'U0prpBQd4PloSGU0pnpM4z9wKn4vZ1.jsrzQfPqxph9'
result = hash.sha256_crypt.parsehash(h)
self.assertEqual(result, dict(salt=s, rounds=5000,
implicit_rounds=True, checksum=c))
@@ -507,14 +506,14 @@ class SkeletonTest(TestCase):
# sanitize
result = hash.sha256_crypt.parsehash(h, sanitize=True)
self.assertEqual(result, dict(rounds=5000, implicit_rounds=True,
- salt=u('LK**************'),
- checksum=u('U0pr***************************************')))
+ salt=u'LK**************',
+ checksum=u'U0pr***************************************'))
# parse w/o implicit rounds flag
result = hash.sha256_crypt.parsehash('$5$rounds=10428$uy/jIAhCetNCTtb0$YWvUOXbkqlqhyoPMpN8BMe.ZGsGx2aBvxTvDFI613c3')
self.assertEqual(result, dict(
- checksum=u('YWvUOXbkqlqhyoPMpN8BMe.ZGsGx2aBvxTvDFI613c3'),
- salt=u('uy/jIAhCetNCTtb0'),
+ checksum=u'YWvUOXbkqlqhyoPMpN8BMe.ZGsGx2aBvxTvDFI613c3',
+ salt=u'uy/jIAhCetNCTtb0',
rounds=10428,
))
@@ -530,9 +529,9 @@ class SkeletonTest(TestCase):
# sanitizing of raw checksums & salts
result = hash.pbkdf2_sha1.parsehash(h1, sanitize=True)
self.assertEqual(result, dict(
- checksum=u('O26************************'),
+ checksum=u'O26************************',
rounds=60000,
- salt=u('Do********************'),
+ salt=u'Do********************',
))
def test_92_bitsize(self):
@@ -674,7 +673,7 @@ class PrefixWrapperTest(TestCase):
def test_12_ident(self):
# test ident is proxied
h = uh.PrefixWrapper("h2", "ldap_md5", "{XXX}")
- self.assertEqual(h.ident, u("{XXX}{MD5}"))
+ self.assertEqual(h.ident, u"{XXX}{MD5}")
self.assertIs(h.ident_values, None)
# test lack of ident means no proxy
@@ -689,7 +688,7 @@ class PrefixWrapperTest(TestCase):
# test custom ident overrides default
h = uh.PrefixWrapper("h3", "ldap_md5", "{XXX}", ident="{X")
- self.assertEqual(h.ident, u("{X"))
+ self.assertEqual(h.ident, u"{X")
self.assertIs(h.ident_values, None)
# test custom ident must match
@@ -702,11 +701,11 @@ class PrefixWrapperTest(TestCase):
# test ident_values is proxied
h = uh.PrefixWrapper("h4", "phpass", "{XXX}")
self.assertIs(h.ident, None)
- self.assertEqual(h.ident_values, (u("{XXX}$P$"), u("{XXX}$H$")))
+ self.assertEqual(h.ident_values, (u"{XXX}$P$", u"{XXX}$H$"))
# test ident=True means use prefix even if hash has no ident.
h = uh.PrefixWrapper("h5", "des_crypt", "{XXX}", ident=True)
- self.assertEqual(h.ident, u("{XXX}"))
+ self.assertEqual(h.ident, u"{XXX}")
self.assertIs(h.ident_values, None)
# ... but requires prefix
@@ -715,7 +714,7 @@ class PrefixWrapperTest(TestCase):
# orig_prefix + HasManyIdent - warning
with self.assertWarningList("orig_prefix.*may not work correctly"):
h = uh.PrefixWrapper("h7", "phpass", orig_prefix="$", prefix="?")
- self.assertEqual(h.ident_values, None) # TODO: should output (u("?P$"), u("?H$")))
+ self.assertEqual(h.ident_values, None) # TODO: should output (u"?P$", u"?H$"))
self.assertEqual(h.ident, None)
def test_13_repr(self):
@@ -763,7 +762,7 @@ class SaltedHash(uh.HasSalt, uh.GenericHandler):
checksum_size = 40
salt_chars = checksum_chars = uh.LOWER_HEX_CHARS
- _hash_regex = re.compile(u("^@salt[0-9a-f]{42,44}$"))
+ _hash_regex = re.compile(u"^@salt[0-9a-f]{42,44}$")
@classmethod
def from_string(cls, hash):
@@ -774,7 +773,7 @@ class SaltedHash(uh.HasSalt, uh.GenericHandler):
return cls(salt=hash[5:-40], checksum=hash[-40:])
def to_string(self):
- hash = u("@salt%s%s") % (self.salt, self.checksum)
+ hash = u"@salt%s%s" % (self.salt, self.checksum)
return uascii_to_str(hash)
def _calc_checksum(self, secret):
@@ -790,7 +789,7 @@ class SaltedHash(uh.HasSalt, uh.GenericHandler):
# TODO: provide data samples for algorithms
# (positive knowns, negative knowns, invalid identify)
-UPASS_TEMP = u('\u0399\u03c9\u03b1\u03bd\u03bd\u03b7\u03c2')
+UPASS_TEMP = u'\u0399\u03c9\u03b1\u03bd\u03bd\u03b7\u03c2'
class UnsaltedHashTest(HandlerCase):
handler = UnsaltedHash
diff --git a/passlib/tests/test_utils_pbkdf2.py b/passlib/tests/test_utils_pbkdf2.py
index 0be9752..33d195a 100644
--- a/passlib/tests/test_utils_pbkdf2.py
+++ b/passlib/tests/test_utils_pbkdf2.py
@@ -19,7 +19,7 @@ import warnings
# site
# pkg
# module
-from passlib.utils.compat import u, JYTHON
+from passlib.utils.compat import JYTHON
from passlib.tests.utils import TestCase, hb
#=============================================================================
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index 1ac52fd..3f8cea8 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -29,7 +29,7 @@ from passlib.tests.backports import TestCase as _TestCase, skip, skipIf, skipUnl
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 iteritems, irange, u, unicode, PY2
+from passlib.utils.compat import iteritems, irange, unicode, PY2
from passlib.utils.decor import classproperty
import passlib.utils.handlers as uh
# local
@@ -738,8 +738,8 @@ class HandlerCase(TestCase):
# passwords used to test basic hash behavior - generally
# don't need to be overidden.
stock_passwords = [
- u("test"),
- u("\u20AC\u00A5$"),
+ u"test",
+ u"\u20AC\u00A5$",
b'\xe2\x82\xac\xc2\xa5$'
]
@@ -1383,7 +1383,7 @@ class HandlerCase(TestCase):
self.do_stub_encrypt(salt=salt)
# check some invalid salt chars, make sure they're rejected
- source = u('\x00\xff')
+ source = u'\x00\xff'
if raw:
source = source.encode("latin-1")
chunk = max(mn, 1)
@@ -1414,7 +1414,7 @@ class HandlerCase(TestCase):
# unicode should be accepted only if salt_type is unicode.
if salt_type is not unicode:
- self.assertRaises(TypeError, self.do_encrypt, 'stub', salt=u('x') * salt_size)
+ self.assertRaises(TypeError, self.do_encrypt, 'stub', salt=u'x' * salt_size)
# bytes should be accepted only if salt_type is bytes,
# OR if salt type is unicode and running PY2 - to allow native strings.
@@ -2230,7 +2230,7 @@ class HandlerCase(TestCase):
chars = self.forbidden_characters
if not chars:
raise self.skipTest("none listed")
- base = u('stub')
+ base = u'stub'
if isinstance(chars, bytes):
from passlib.utils.compat import iter_byte_chars
chars = iter_byte_chars(chars)
@@ -2461,7 +2461,7 @@ class HandlerCase(TestCase):
#
# test hash='' is rejected for all but the plaintext hashes
#
- for hash in [u(''), b'']:
+ for hash in [u'', b'']:
if self.accepts_all_hashes:
# then it accepts empty string as well.
self.assertTrue(self.do_identify(hash))
@@ -2732,7 +2732,7 @@ class HandlerCase(TestCase):
#==========================================================
# alphabet for randomly generated passwords
- password_alphabet = u('qwertyASDF1234<>.@*#! \u00E1\u0259\u0411\u2113')
+ password_alphabet = u'qwertyASDF1234<>.@*#! \u00E1\u0259\u0411\u2113'
# encoding when testing bytes
password_encoding = "utf-8"
@@ -2843,7 +2843,7 @@ class HandlerCase(TestCase):
# occasionally try an empty password
rng = self.rng
if rng.random() < .0001:
- return u('')
+ return u''
# check if truncate size needs to be considered
handler = self.handler
@@ -3295,7 +3295,7 @@ class UserHandlerMixin(HandlerCase):
context_map = HandlerCase.FuzzHashGenerator.context_map.copy()
context_map.update(user="random_user")
- user_alphabet = u("asdQWE123")
+ user_alphabet = u"asdQWE123"
def random_user(self):
rng = self.rng
@@ -3323,14 +3323,14 @@ class EncodingHandlerMixin(HandlerCase):
# restrict stock passwords & fuzz alphabet to latin-1,
# so different encodings can be tested safely.
stock_passwords = [
- u("test"),
+ u"test",
b"test",
- u("\u00AC\u00BA"),
+ u"\u00AC\u00BA",
]
class FuzzHashGenerator(HandlerCase.FuzzHashGenerator):
- password_alphabet = u('qwerty1234<>.@*#! \u00AC')
+ password_alphabet = u'qwerty1234<>.@*#! \u00AC'
def populate_context(self, secret, kwds):
"""insert encoding into kwds"""
diff --git a/passlib/totp.py b/passlib/totp.py
index c2e8891..e9edf59 100644
--- a/passlib/totp.py
+++ b/passlib/totp.py
@@ -1046,10 +1046,10 @@ class TOTP(object):
"""
digits = self_or_cls.digits
if isinstance(token, int_types):
- token = u("%0*d") % (digits, token)
+ token = u"%0*d" % (digits, token)
else:
token = to_unicode(token, param="token")
- token = _clean_re.sub(u(""), token)
+ token = _clean_re.sub(u"", token)
if not token.isdigit():
raise MalformedTokenError("Token must contain only the digits 0-9")
if len(token) != digits:
@@ -1132,7 +1132,7 @@ class TOTP(object):
# if 31-bit mask removed (which breaks spec), would only get values 0-4.
digits = self.digits
assert 0 < digits < 11, "digits: sanity check failed"
- return (u("%0*d") % (digits, value))[-digits:]
+ return (u"%0*d" % (digits, value))[-digits:]
#=============================================================================
# token verification
@@ -1541,12 +1541,12 @@ class TOTP(object):
# NOTE: not using urllib.urlencode() because it encodes ' ' as '+';
# but spec says to use '%20', and not sure how fragile
# the various totp clients' parsers are.
- argstr = u("&").join(u("%s=%s") % (key, quote(value, ''))
+ argstr = u"&".join(u"%s=%s" % (key, quote(value, ''))
for key, value in args)
assert argstr, "argstr should never be empty"
# render uri
- return u("otpauth://totp/%s?%s") % (label, argstr)
+ return u"otpauth://totp/%s?%s" % (label, argstr)
def _to_uri_params(self):
"""return list of (key, param) entries for URI"""
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index 3a65616..e879118 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -50,7 +50,7 @@ from passlib.utils.decor import (
)
from passlib.exc import ExpectedStringError
from passlib.utils.compat import (add_doc, join_bytes, join_byte_values,
- join_byte_elems, irange, imap, PY3, u,
+ join_byte_elems, irange, imap, PY3,
join_unicode, unicode, byte_elem_value, nextgetter,
unicode_or_bytes_types,
get_method_function, suppress_cause)
@@ -118,8 +118,8 @@ rounds_cost_values = [ "linear", "log2" ]
# internal helpers
_BEMPTY = b''
-_UEMPTY = u("")
-_USPACE = u(" ")
+_UEMPTY = u""
+_USPACE = u" "
# maximum password size which passlib will allow; see exc.PasswordSizeError
MAX_PASSWORD_SIZE = int(os.environ.get("PASSLIB_MAX_PASSWORD_SIZE") or 4096)
@@ -569,7 +569,7 @@ def repeat_string(source, size):
return source[:size]
_BNULL = b"\x00"
-_UNULL = u("\x00")
+_UNULL = u"\x00"
def right_pad_string(source, size, pad=None):
"""right-pad or truncate <source> string, so it has length <size>"""
@@ -600,7 +600,7 @@ def is_same_codec(left, right):
return _lookup_codec(left).name == _lookup_codec(right).name
_B80 = b'\x80'[0]
-_U80 = u('\x80')
+_U80 = u'\x80'
def is_ascii_safe(source):
"""Check if string (bytes or unicode) contains only 7-bit ascii"""
r = _B80 if isinstance(source, bytes) else _U80
@@ -758,7 +758,7 @@ else:
# returning NULL / None. examples include ":", ":0", "*0", etc.
# safe_crypt() returns None for any string starting with one of the
# chars in this string...
- _invalid_prefixes = u("*:!")
+ _invalid_prefixes = u"*:!"
if PY3:
def safe_crypt(secret, hash):
@@ -886,7 +886,7 @@ def genseed(value=None):
# this method throws error for e.g. SystemRandom instances,
# so fall back to extracting 4k of state
value = value.getrandbits(1 << 15)
- text = u("%s %s %s %.15f %.15f %s") % (
+ text = u"%s %s %s %.15f %.15f %s" % (
# if caller specified a seed value, mix it in
value,
diff --git a/passlib/utils/binary.py b/passlib/utils/binary.py
index 521b64a..68d0512 100644
--- a/passlib/utils/binary.py
+++ b/passlib/utils/binary.py
@@ -22,7 +22,7 @@ from passlib.utils.compat import (
PY3, bascii_to_str,
irange, imap, iter_byte_chars, join_byte_values, join_byte_elems,
nextgetter, suppress_cause,
- u, unicode, unicode_or_bytes_types,
+ unicode, unicode_or_bytes_types,
)
from passlib.utils.decor import memoized_property
# from passlib.utils import BASE64_CHARS, HASH64_CHARS
@@ -64,28 +64,28 @@ __all__ = [
#-------------------------------------------------------------
#: standard base64 charmap
-BASE64_CHARS = u("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
+BASE64_CHARS = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
#: alt base64 charmap -- "." instead of "+"
-AB64_CHARS = u("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./")
+AB64_CHARS = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./"
#: charmap used by HASH64 encoding.
-HASH64_CHARS = u("./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
+HASH64_CHARS = u"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
#: charmap used by BCrypt
-BCRYPT_CHARS = u("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
+BCRYPT_CHARS = u"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
#: std base64 chars + padding char
-PADDED_BASE64_CHARS = BASE64_CHARS + u("=")
+PADDED_BASE64_CHARS = BASE64_CHARS + u"="
#: all hex chars
-HEX_CHARS = u("0123456789abcdefABCDEF")
+HEX_CHARS = u"0123456789abcdefABCDEF"
#: upper case hex chars
-UPPER_HEX_CHARS = u("0123456789ABCDEF")
+UPPER_HEX_CHARS = u"0123456789ABCDEF"
#: lower case hex chars
-LOWER_HEX_CHARS = u("0123456789abcdef")
+LOWER_HEX_CHARS = u"0123456789abcdef"
#-------------------------------------------------------------
# byte strings
diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py
index 41bef5a..4dba91f 100644
--- a/passlib/utils/compat/__init__.py
+++ b/passlib/utils/compat/__init__.py
@@ -93,7 +93,8 @@ _lazy_attrs = dict()
if PY3:
unicode = str
- # TODO: once we drop python 3.2 support, can use u'' again!
+ # 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)
def u(s):
assert isinstance(s, str)
return s
@@ -106,7 +107,7 @@ else:
def u(s):
assert isinstance(s, str)
- return s.decode("unicode_escape")
+ return s.decode("ascii")
unicode_or_bytes_types = (basestring,)
native_string_types = (basestring,)
@@ -125,7 +126,7 @@ unicode_or_str = native_string_types
# unicode & bytes helpers
#=============================================================================
# function to join list of unicode strings
-join_unicode = u('').join
+join_unicode = u''.join
# function to join list of byte strings
join_bytes = b''.join
@@ -337,13 +338,13 @@ else:
# pick default end sequence
if end is None:
- end = u("\n") if want_unicode else "\n"
+ end = u"\n" if want_unicode else "\n"
elif not isinstance(end, unicode_or_bytes_types):
raise TypeError("end must be None or a string")
# pick default separator
if sep is None:
- sep = u(" ") if want_unicode else " "
+ sep = u" " if want_unicode else " "
elif not isinstance(sep, unicode_or_bytes_types):
raise TypeError("sep must be None or a string")
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index ef37061..cc9d151 100644
--- a/passlib/utils/handlers.py
+++ b/passlib/utils/handlers.py
@@ -27,7 +27,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, irange, u, native_string_types, \
+from passlib.utils.compat import join_byte_values, irange, native_string_types, \
uascii_to_str, join_unicode, unicode, str_to_uascii, \
join_unicode, unicode_or_bytes_types, PY2, int_types
from passlib.utils.decor import classproperty, deprecated_method
@@ -113,8 +113,8 @@ def extract_settings_kwds(handler, kwds):
#=============================================================================
# parsing helpers
#=============================================================================
-_UDOLLAR = u("$")
-_UZERO = u("0")
+_UDOLLAR = u"$"
+_UZERO = u"0"
def validate_secret(secret):
"""ensure secret has correct type & size"""
@@ -266,7 +266,7 @@ def parse_int(source, base=10, default=None, param="value", handler=None):
#=============================================================================
# formatting helpers
#=============================================================================
-def render_mc2(ident, salt, checksum, sep=u("$")):
+def render_mc2(ident, salt, checksum, sep=u"$"):
"""format hash using 2-part modular crypt format; inverse of parse_mc2()
returns native string with format :samp:`{ident}{salt}[${checksum}]`,
@@ -286,7 +286,7 @@ def render_mc2(ident, salt, checksum, sep=u("$")):
parts = [ident, salt]
return uascii_to_str(join_unicode(parts))
-def render_mc3(ident, rounds, salt, checksum, sep=u("$"), rounds_base=10):
+def render_mc3(ident, rounds, salt, checksum, sep=u"$", rounds_base=10):
"""format hash using 3-part modular crypt format; inverse of parse_mc3()
returns native string with format :samp:`{ident}[{rounds}$]{salt}[${checksum}]`,
@@ -303,9 +303,9 @@ def render_mc3(ident, rounds, salt, checksum, sep=u("$"), rounds_base=10):
config or hash (native str)
"""
if rounds is None:
- rounds = u('')
+ rounds = u''
elif rounds_base == 16:
- rounds = u("%x") % rounds
+ rounds = u"%x" % rounds
else:
assert rounds_base == 10
rounds = unicode(rounds)
@@ -821,7 +821,7 @@ class GenericHandler(MinimalHandler):
# XXX: make this a global function?
@staticmethod
- def _sanitize(value, char=u("*")):
+ def _sanitize(value, char=u"*"):
"""default method to obscure sensitive fields"""
if value is None:
return None
@@ -908,7 +908,7 @@ class StaticHandler(GenericHandler):
setting_kwds = ()
# optional constant prefix subclasses can specify
- _hash_prefix = u("")
+ _hash_prefix = u""
@classmethod
def from_string(cls, hash, **context):
@@ -2414,7 +2414,7 @@ class PrefixWrapper(object):
#: list of attributes which should be cloned by .using()
_using_clone_attrs = ()
- def __init__(self, name, wrapped, prefix=u(''), orig_prefix=u(''), lazy=False,
+ def __init__(self, name, wrapped, prefix=u'', orig_prefix=u'', lazy=False,
doc=None, ident=None):
self.name = name
if isinstance(prefix, bytes):