diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 15:39:55 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 15:39:55 -0400 |
commit | 61e6523d815b3c69b4cb978828d7df7e909aee81 (patch) | |
tree | a197bc31aac29c981efc5d497695a920ba5ebb90 | |
parent | 034adeef2a3e8582135002ee61b38fe7063b4f6e (diff) | |
download | passlib-61e6523d815b3c69b4cb978828d7df7e909aee81.tar.gz |
cleanup old python compat - assorted minor cleanups & fixes from conversion
-rw-r--r-- | docs/history/1.8.rst | 4 | ||||
-rw-r--r-- | passlib/apache.py | 1 | ||||
-rw-r--r-- | passlib/crypto/digest.py | 9 | ||||
-rw-r--r-- | passlib/handlers/misc.py | 2 | ||||
-rw-r--r-- | passlib/tests/test_crypto_builtin_md4.py | 3 | ||||
-rw-r--r-- | passlib/tests/test_crypto_digest.py | 3 | ||||
-rw-r--r-- | passlib/tests/test_crypto_scrypt.py | 3 | ||||
-rw-r--r-- | passlib/tests/test_handlers.py | 8 | ||||
-rw-r--r-- | passlib/tests/utils.py | 3 | ||||
-rw-r--r-- | passlib/utils/decor.py | 3 |
10 files changed, 24 insertions, 15 deletions
diff --git a/docs/history/1.8.rst b/docs/history/1.8.rst index f13a130..9de5b7b 100644 --- a/docs/history/1.8.rst +++ b/docs/history/1.8.rst @@ -88,3 +88,7 @@ for a number of years / releases: * The deprecated :func:`passlib.utils.des.mdes_encrypt_int_block` method was removed. * The :func:`passlib.utils.pbkdf2.norm_hash_name` alias was removed, use :func:`passlib.crypto.digest.norm_hash_name` instead. + + .. py:currentmodule:: passlib.utils + + * Many PY2 compatibility helper inside :mod:`!passlib.utils.compat` have been removed. diff --git a/passlib/apache.py b/passlib/apache.py index 9ac14cd..8373c67 100644 --- a/passlib/apache.py +++ b/passlib/apache.py @@ -15,7 +15,6 @@ from passlib.context import CryptContext from passlib.exc import ExpectedStringError from passlib.hash import htdigest from passlib.utils import render_bytes, to_bytes, is_ascii_codec -from passlib.utils.decor import deprecated_method from passlib.utils.compat import join_bytes # local __all__ = [ diff --git a/passlib/crypto/digest.py b/passlib/crypto/digest.py index bbcace1..fce6e19 100644 --- a/passlib/crypto/digest.py +++ b/passlib/crypto/digest.py @@ -890,7 +890,12 @@ if _force_backend in ["any", "from-bytes"]: _builtin_backend = "from-bytes" -elif _force_backend in ["any", "unpack", "from-bytes"]: +elif _force_backend in ["unpack"]: + + # XXX: should run bench_pbkdf2() to verify; + # but think this can be removed now that we're always on python 3 + # (the from_bytes method should always be faster) + from struct import Struct from passlib.utils import sys_bits @@ -1004,7 +1009,7 @@ elif _force_backend in ["any", "unpack", "from-bytes"]: _builtin_backend = "unpack" else: - assert _force_backend in ["any", "hexlify"] + assert _force_backend in ["hexlify"] # XXX: older & slower approach that used int(hexlify()), # keeping it around for a little while just for benchmarking. diff --git a/passlib/handlers/misc.py b/passlib/handlers/misc.py index 0a46197..58366ba 100644 --- a/passlib/handlers/misc.py +++ b/passlib/handlers/misc.py @@ -88,7 +88,7 @@ class unix_disabled(uh.ifc.DisabledHash, uh.MinimalHandler): # * linux may use "!" + hash to disable but preserve original hash # * linux counts empty string as "any password"; # this code recognizes it, but treats it the same as "!" - if isinstance(hash, unicode): + if isinstance(hash, str): start = _MARKER_CHARS elif isinstance(hash, bytes): start = _MARKER_BYTES diff --git a/passlib/tests/test_crypto_builtin_md4.py b/passlib/tests/test_crypto_builtin_md4.py index 0610cb9..4f5b798 100644 --- a/passlib/tests/test_crypto_builtin_md4.py +++ b/passlib/tests/test_crypto_builtin_md4.py @@ -5,12 +5,13 @@ # core from binascii import hexlify import hashlib +from unittest import skipUnless # site # pkg # module from passlib.utils.compat import bascii_to_str from passlib.crypto.digest import lookup_hash -from passlib.tests.utils import TestCase, skipUnless +from passlib.tests.utils import TestCase # local __all__ = [ "_Common_MD4_Test", diff --git a/passlib/tests/test_crypto_digest.py b/passlib/tests/test_crypto_digest.py index 5f0dd40..66f781c 100644 --- a/passlib/tests/test_crypto_digest.py +++ b/passlib/tests/test_crypto_digest.py @@ -5,13 +5,14 @@ # core from binascii import hexlify import hashlib +from unittest import skipUnless import warnings # site # pkg # module from passlib.exc import UnknownHashError from passlib.utils.compat import JYTHON -from passlib.tests.utils import TestCase, TEST_MODE, skipUnless, hb +from passlib.tests.utils import TestCase, TEST_MODE, hb #============================================================================= # test assorted crypto helpers diff --git a/passlib/tests/test_crypto_scrypt.py b/passlib/tests/test_crypto_scrypt.py index 683ef2b..04efdd9 100644 --- a/passlib/tests/test_crypto_scrypt.py +++ b/passlib/tests/test_crypto_scrypt.py @@ -7,6 +7,7 @@ from binascii import hexlify import hashlib import logging; log = logging.getLogger(__name__) import struct +from unittest import skipUnless import warnings warnings.filterwarnings("ignore", ".*using builtin scrypt backend.*") # site @@ -15,7 +16,7 @@ from passlib import exc from passlib.utils import getrandbytes 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 +from passlib.tests.utils import TestCase, TEST_MODE, hb # subject from passlib.crypto import scrypt as scrypt_mod # local diff --git a/passlib/tests/test_handlers.py b/passlib/tests/test_handlers.py index 757c089..14623e1 100644 --- a/passlib/tests/test_handlers.py +++ b/passlib/tests/test_handlers.py @@ -3,16 +3,14 @@ # imports #============================================================================= # core -import logging; log = logging.getLogger(__name__) -import os +import logging +log = logging.getLogger(__name__) import sys import warnings # site # pkg from passlib import exc, hash -from passlib.utils import repeat_string -from passlib.utils.compat import range, get_method_function -from passlib.tests.utils import TestCase, HandlerCase, skipUnless, \ +from passlib.tests.utils import TestCase, HandlerCase, \ TEST_MODE, UserHandlerMixin, EncodingHandlerMixin # module diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index 28ddf49..c01decf 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -360,7 +360,8 @@ class TestCase(unittest.TestCase): self.addCleanup(ctx.__exit__) # ignore security warnings, tests may deliberately cause these - warnings.filterwarnings("ignore", category=exc.PasslibSecurityWarning) + # TODO: may want to filter out a few of this, but not blanket filter... + # warnings.filterwarnings("ignore", category=exc.PasslibSecurityWarning) # ignore warnings about PasswordHash features deprecated in 1.7 # TODO: should be cleaned in 2.0, when support will be dropped. diff --git a/passlib/utils/decor.py b/passlib/utils/decor.py index bd4c290..aa40925 100644 --- a/passlib/utils/decor.py +++ b/passlib/utils/decor.py @@ -162,8 +162,7 @@ def deprecated_function(msg=None, deprecated=None, removed=None, updoc=True, def build(func): is_classmethod = _is_method and isinstance(func, classmethod) if is_classmethod: - # NOTE: PY26 doesn't support "classmethod().__func__" directly... - func = func.__get__(None, type).__func__ + func = func.__func__ opts = dict( mod=func_module or func.__module__, name=func.__name__, |