summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-10-06 15:11:54 -0400
committerEli Collins <elic@assurancetechnologies.com>2020-10-06 15:11:54 -0400
commitea6e35700e799777d24295dd9d9af2d66f6ec8fc (patch)
treecc56ae104172b441368d6f3c6d7f16a14dff7a70
parent3709566d41523e5bc31e1063b647e90f1469744a (diff)
downloadpasslib-ea6e35700e799777d24295dd9d9af2d66f6ec8fc.tar.gz
cleanup old python compat -- removed u() wrapper from some regexes
-rw-r--r--passlib/handlers/des_crypt.py18
-rw-r--r--passlib/handlers/fshp.py6
-rw-r--r--passlib/handlers/ldap_digests.py16
-rw-r--r--passlib/totp.py5
-rw-r--r--passlib/utils/compat/__init__.py10
5 files changed, 22 insertions, 33 deletions
diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py
index 4f3d0a0..d4dc3dc 100644
--- a/passlib/handlers/des_crypt.py
+++ b/passlib/handlers/des_crypt.py
@@ -10,7 +10,7 @@ from warnings import warn
# pkg
from passlib.utils import safe_crypt, test_crypt, to_unicode
from passlib.utils.binary import h64, h64big
-from passlib.utils.compat import byte_elem_value, u, uascii_to_str
+from passlib.utils.compat import byte_elem_value, uascii_to_str
from passlib.crypto.des import des_encrypt_int_block
import passlib.utils.handlers as uh
# local
@@ -171,11 +171,11 @@ class des_crypt(uh.TruncateMixin, uh.HasManyBackends, uh.HasSalt, uh.GenericHand
#===================================================================
# FORMAT: 2 chars of H64-encoded salt + 11 chars of H64-encoded checksum
- _hash_regex = re.compile(u(r"""
+ _hash_regex = re.compile(r"""
^
(?P<salt>[./a-z0-9]{2})
(?P<chk>[./a-z0-9]{11})?
- $"""), re.X|re.I)
+ $""", re.X|re.I)
@classmethod
def from_string(cls, hash):
@@ -297,13 +297,13 @@ class bsdi_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler
#===================================================================
# parsing
#===================================================================
- _hash_regex = re.compile(u(r"""
+ _hash_regex = re.compile(r"""
^
_
(?P<rounds>[./a-z0-9]{4})
(?P<salt>[./a-z0-9]{4})
(?P<chk>[./a-z0-9]{11})?
- $"""), re.X|re.I)
+ $""", re.X|re.I)
@classmethod
def from_string(cls, hash):
@@ -442,11 +442,11 @@ class bigcrypt(uh.HasSalt, uh.GenericHandler):
#===================================================================
# internal helpers
#===================================================================
- _hash_regex = re.compile(u(r"""
+ _hash_regex = re.compile(r"""
^
(?P<salt>[./a-z0-9]{2})
(?P<chk>([./a-z0-9]{11})+)?
- $"""), re.X|re.I)
+ $""", re.X|re.I)
@classmethod
def from_string(cls, hash):
@@ -546,11 +546,11 @@ class crypt16(uh.TruncateMixin, uh.HasSalt, uh.GenericHandler):
#===================================================================
# internal helpers
#===================================================================
- _hash_regex = re.compile(u(r"""
+ _hash_regex = re.compile(r"""
^
(?P<salt>[./a-z0-9]{2})
(?P<chk>[./a-z0-9]{22})?
- $"""), re.X|re.I)
+ $""", re.X|re.I)
@classmethod
def from_string(cls, hash):
diff --git a/passlib/handlers/fshp.py b/passlib/handlers/fshp.py
index 8df4845..5a28b29 100644
--- a/passlib/handlers/fshp.py
+++ b/passlib/handlers/fshp.py
@@ -12,7 +12,7 @@ import logging; log = logging.getLogger(__name__)
# pkg
from passlib.utils import to_unicode
import passlib.utils.handlers as uh
-from passlib.utils.compat import bascii_to_str, u
+from passlib.utils.compat import bascii_to_str
from passlib.crypto.digest import pbkdf1
# local
__all__ = [
@@ -153,14 +153,14 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
# formatting
#===================================================================
- _hash_regex = re.compile(u(r"""
+ _hash_regex = re.compile(r"""
^
\{FSHP
(\d+)\| # variant
(\d+)\| # salt size
(\d+)\} # rounds
([a-zA-Z0-9+/]+={0,3}) # digest
- $"""), re.X)
+ $""", re.X)
@classmethod
def from_string(cls, hash):
diff --git a/passlib/handlers/ldap_digests.py b/passlib/handlers/ldap_digests.py
index bcd5961..499ca6e 100644
--- a/passlib/handlers/ldap_digests.py
+++ b/passlib/handlers/ldap_digests.py
@@ -12,7 +12,7 @@ import re
# pkg
from passlib.handlers.misc import plaintext
from passlib.utils import unix_crypt_schemes, to_unicode
-from passlib.utils.compat import uascii_to_str, u
+from passlib.utils.compat import uascii_to_str
from passlib.utils.decor import classproperty
import passlib.utils.handlers as uh
# local
@@ -110,7 +110,7 @@ class ldap_md5(_Base64DigestHelper):
name = "ldap_md5"
ident = u"{MD5}"
_hash_func = md5
- _hash_regex = re.compile(u(r"^\{MD5\}(?P<chk>[+/a-zA-Z0-9]{22}==)$"))
+ _hash_regex = re.compile(r"^\{MD5\}(?P<chk>[+/a-zA-Z0-9]{22}==)$")
class ldap_sha1(_Base64DigestHelper):
"""This class stores passwords using LDAP's plain SHA1 format, and follows the :ref:`password-hash-api`.
@@ -120,7 +120,7 @@ class ldap_sha1(_Base64DigestHelper):
name = "ldap_sha1"
ident = u"{SHA}"
_hash_func = sha1
- _hash_regex = re.compile(u(r"^\{SHA\}(?P<chk>[+/a-zA-Z0-9]{27}=)$"))
+ _hash_regex = re.compile(r"^\{SHA\}(?P<chk>[+/a-zA-Z0-9]{27}=)$")
class ldap_salted_md5(_SaltedBase64DigestHelper):
"""This class stores passwords using LDAP's salted MD5 format, and follows the :ref:`password-hash-api`.
@@ -159,7 +159,7 @@ class ldap_salted_md5(_SaltedBase64DigestHelper):
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})$"))
+ _hash_regex = re.compile(r"^\{SMD5\}(?P<tmp>[+/a-zA-Z0-9]{27,}={0,2})$")
class ldap_salted_sha1(_SaltedBase64DigestHelper):
"""
@@ -201,7 +201,7 @@ class ldap_salted_sha1(_SaltedBase64DigestHelper):
checksum_size = 20
_hash_func = sha1
# NOTE: 32 = ceil((20 + 4) * 4/3)
- _hash_regex = re.compile(u(r"^\{SSHA\}(?P<tmp>[+/a-zA-Z0-9]{32,}={0,2})$"))
+ _hash_regex = re.compile(r"^\{SSHA\}(?P<tmp>[+/a-zA-Z0-9]{32,}={0,2})$")
@@ -242,7 +242,7 @@ class ldap_salted_sha256(_SaltedBase64DigestHelper):
default_salt_size = 8
_hash_func = sha256
# NOTE: 48 = ceil((32 + 4) * 4/3)
- _hash_regex = re.compile(u(r"^\{SSHA256\}(?P<tmp>[+/a-zA-Z0-9]{48,}={0,2})$"))
+ _hash_regex = re.compile(r"^\{SSHA256\}(?P<tmp>[+/a-zA-Z0-9]{48,}={0,2})$")
class ldap_salted_sha512(_SaltedBase64DigestHelper):
@@ -282,7 +282,7 @@ class ldap_salted_sha512(_SaltedBase64DigestHelper):
default_salt_size = 8
_hash_func = sha512
# NOTE: 91 = ceil((64 + 4) * 4/3)
- _hash_regex = re.compile(u(r"^\{SSHA512\}(?P<tmp>[+/a-zA-Z0-9]{91,}={0,2})$"))
+ _hash_regex = re.compile(r"^\{SSHA512\}(?P<tmp>[+/a-zA-Z0-9]{91,}={0,2})$")
class ldap_plaintext(plaintext):
@@ -309,7 +309,7 @@ class ldap_plaintext(plaintext):
# is override identify()
name = "ldap_plaintext"
- _2307_pat = re.compile(u(r"^\{\w+\}.*$"))
+ _2307_pat = re.compile(r"^\{\w+\}.*$")
@uh.deprecated_method(deprecated="1.7", removed="2.0")
@classmethod
diff --git a/passlib/totp.py b/passlib/totp.py
index 822f724..9149503 100644
--- a/passlib/totp.py
+++ b/passlib/totp.py
@@ -31,8 +31,7 @@ from passlib.exc import TokenError, MalformedTokenError, InvalidTokenError, Used
from passlib.utils import (to_unicode, to_bytes, consteq,
getrandbytes, rng, SequenceMixin, xor_bytes, getrandstr)
from passlib.utils.binary import BASE64_CHARS, b32encode, b32decode
-from passlib.utils.compat import (u, bascii_to_str, int_types, num_types,
- byte_elem_value)
+from passlib.utils.compat import bascii_to_str, int_types, num_types, byte_elem_value
from passlib.utils.decor import hybrid_method, memoized_property
from passlib.crypto.digest import lookup_hash, compile_hmac, pbkdf2_hmac
from passlib.hash import pbkdf2_sha256
@@ -62,7 +61,7 @@ __all__ = [
#-----------------------------------------------------------------------------
#: regex used to clean whitespace from tokens & keys
-_clean_re = re.compile(u(r"\s|[-=]"), re.U)
+_clean_re = re.compile(r"\s|[-=]", re.U)
_chunk_sizes = [4,6,5]
diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py
index f81c6ad..0996377 100644
--- a/passlib/utils/compat/__init__.py
+++ b/passlib/utils/compat/__init__.py
@@ -40,10 +40,8 @@ __all__ = [
'int_types',
'num_types',
'unicode_or_bytes',
- 'str',
# unicode/bytes types & helpers
- 'u',
'uascii_to_str', 'bascii_to_str',
'str_to_uascii', 'str_to_bascii',
'join_unicode', 'join_bytes',
@@ -66,14 +64,6 @@ _lazy_attrs = dict()
# unicode & bytes types
#=============================================================================
-if True: # legacy PY3 indent
-
- # 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
-
#: alias for isinstance() tests to detect any string type
unicode_or_bytes = (str, bytes)