diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 14:45:01 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 14:45:01 -0400 |
commit | 2cabd30db6306316c7a193585ea1cec5235d5209 (patch) | |
tree | ee3464797c4038491113b52f156a6a0aade625c5 | |
parent | ab0b14e8b2178160b1279d2a0679b8d9149cfe55 (diff) | |
download | passlib-2cabd30db6306316c7a193585ea1cec5235d5209.tar.gz |
cleanup old python compat -- removed IO aliases (BytesIO etc)
-rw-r--r-- | passlib/apache.py | 3 | ||||
-rw-r--r-- | passlib/context.py | 13 | ||||
-rw-r--r-- | passlib/crypto/_blowfish/__init__.py | 2 | ||||
-rw-r--r-- | passlib/tests/test_utils.py | 3 | ||||
-rw-r--r-- | passlib/totp.py | 2 | ||||
-rw-r--r-- | passlib/utils/compat/__init__.py | 15 |
6 files changed, 14 insertions, 24 deletions
diff --git a/passlib/apache.py b/passlib/apache.py index 1507cf5..2868fa1 100644 --- a/passlib/apache.py +++ b/passlib/apache.py @@ -4,6 +4,7 @@ # imports #============================================================================= # core +from io import BytesIO import logging; log = logging.getLogger(__name__) import os from warnings import warn @@ -15,7 +16,7 @@ from passlib.exc import ExpectedStringError from passlib.hash import htdigest from passlib.utils import render_bytes, to_bytes, is_ascii_codec from passlib.utils.decor import deprecated_method -from passlib.utils.compat import join_bytes, unicode, BytesIO +from passlib.utils.compat import join_bytes, unicode # local __all__ = [ 'HtpasswdFile', diff --git a/passlib/context.py b/passlib/context.py index 6576cba..bafb4f4 100644 --- a/passlib/context.py +++ b/passlib/context.py @@ -3,6 +3,8 @@ # imports #============================================================================= # core +from configparser import ConfigParser +from io import StringIO import re import logging; log = logging.getLogger(__name__) import threading @@ -18,8 +20,7 @@ from passlib.utils import (handlers as uh, to_bytes, ) from passlib.utils.binary import BASE64_CHARS from passlib.utils.compat import (num_types, - unicode, SafeConfigParser, - NativeStringIO, BytesIO, + unicode, unicode_or_bytes_types, native_string_types, ) from passlib.utils.decor import deprecated_method, memoized_property @@ -878,7 +879,7 @@ class CryptContext(object): """helper read INI from stream, extract passlib section as dict""" # NOTE: this expects a unicode stream, # and resulting dict will always use native strings. - p = SafeConfigParser() + p = ConfigParser() p.read_file(stream, filename) # XXX: could change load() to accept list of items, # and skip intermediate dict creation @@ -966,7 +967,7 @@ class CryptContext(object): parse_keys = True if isinstance(source, unicode_or_bytes_types): source = to_unicode(source, encoding, param="source") - source = self._parse_ini_stream(NativeStringIO(source), section, + source = self._parse_ini_stream(StringIO(source), section, "<string passed to CryptContext.load()>") elif isinstance(source, CryptContext): # extract dict directly from config, so it can be merged later @@ -1360,9 +1361,9 @@ class CryptContext(object): .. seealso:: the :ref:`context-serialization-example` example in the tutorial. """ - parser = SafeConfigParser() + parser = ConfigParser() self._write_to_parser(parser, section) - buf = NativeStringIO() + buf = StringIO() parser.write(buf) unregistered = self._get_unregistered_handlers() if unregistered: diff --git a/passlib/crypto/_blowfish/__init__.py b/passlib/crypto/_blowfish/__init__.py index 9a9d378..988918b 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, native_string_types +from passlib.utils.compat import unicode, native_string_types from passlib.crypto._blowfish.unrolled import BlowfishEngine # local __all__ = [ diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py index 39f69bd..e954422 100644 --- a/passlib/tests/test_utils.py +++ b/passlib/tests/test_utils.py @@ -29,7 +29,8 @@ class MiscTest(TestCase): # test synthentic dir() dir(compat) - self.assertTrue('UnicodeIO' in dir(compat)) + # FIXME: find another lazy-loaded attr to check, all current ones removed after py2 comapt gone. + # self.assertTrue('UnicodeIO' in dir(compat)) def test_classproperty(self): from passlib.utils.decor import classproperty diff --git a/passlib/totp.py b/passlib/totp.py index b60284b..480abe7 100644 --- a/passlib/totp.py +++ b/passlib/totp.py @@ -32,7 +32,7 @@ from passlib.utils import (to_unicode, to_bytes, consteq, getrandbytes, rng, SequenceMixin, xor_bytes, getrandstr) from passlib.utils.binary import BASE64_CHARS, b32encode, b32decode from passlib.utils.compat import (u, unicode, native_string_types, bascii_to_str, int_types, num_types, - byte_elem_value, UnicodeIO) + 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 diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py index 32cd777..1a206e8 100644 --- a/passlib/utils/compat/__init__.py +++ b/passlib/utils/compat/__init__.py @@ -40,9 +40,6 @@ def add_doc(obj, doc): # the default exported vars #============================================================================= __all__ = [ - # io - 'BytesIO', 'StringIO', 'NativeStringIO', 'SafeConfigParser', - # type detection ## 'is_mapping', 'int_types', @@ -179,17 +176,6 @@ def get_method_function(func): return getattr(func, "__func__", func) #============================================================================= -# input/output -#============================================================================= - -_lazy_attrs = dict( - BytesIO="io.BytesIO", - UnicodeIO="io.StringIO", - NativeStringIO="io.StringIO", - SafeConfigParser="configparser.ConfigParser", -) - -#============================================================================= # context managers #============================================================================= @@ -280,6 +266,7 @@ class _LazyOverlayModule(ModuleType): return list(attrs) # replace this module with overlay that will lazily import attributes. +_lazy_attrs = dict() _LazyOverlayModule.replace_module(__name__, _lazy_attrs) #============================================================================= |