summaryrefslogtreecommitdiff
path: root/passlib/utils/__init__.py
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2015-01-10 18:52:34 -0500
committerEli Collins <elic@assurancetechnologies.com>2015-01-10 18:52:34 -0500
commitcf8fce4325d259490ada92caa624cb1a1c8e21b5 (patch)
treef52587a6308cf389dbadf56492dfbeb592c9ee47 /passlib/utils/__init__.py
parent55062360b26ace8d2521fe67a518ebf434f7847f (diff)
downloadpasslib-cf8fce4325d259490ada92caa624cb1a1c8e21b5.tar.gz
removed a LOT of compatibility shims -- dropped python 2.5, 3.0, and 3.1 support;
as well as PyPy 1.x and Jython 2.5. shims removed ------------- * b() shim replaced with b'' (py25) * 'bytes' alias no longer needed (py25) * callable() shim no longer needed (py30,31) * PY_MIN_32 flag replaced with PY3 flag (py30,31) * removed 'abc' module stub used by passlib.ifc (py25) * removed chain_from_iterable() backport (py25) * tests: removed catch_warnings() backport, replaced refs with real warnings.catch_warnings() (py25) * tests: removed unittest2 backports (py25, py30, py31) -- now throw hard error if unittest2 not present under py26 (the only release remaining which lacks the unittest2 features) * removed SUPPORTS_DIR_METHOD conditional (py25, pypy 1.x) * some other minor workarounds other ----- * added check in passlib.compat which now throws error telling user version isn't supported (to prevent spurious errors later)
Diffstat (limited to 'passlib/utils/__init__.py')
-rw-r--r--passlib/utils/__init__.py35
1 files changed, 15 insertions, 20 deletions
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index de3e9f2..70b7873 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -2,7 +2,7 @@
#=============================================================================
# imports
#=============================================================================
-from passlib.utils.compat import PYPY, JYTHON
+from passlib.utils.compat import JYTHON
# core
from base64 import b64encode, b64decode
from codecs import lookup as _lookup_codec
@@ -30,13 +30,12 @@ from warnings import warn
# site
# pkg
from passlib.exc import ExpectedStringError
-from passlib.utils.compat import add_doc, b, bytes, join_bytes, join_byte_values, \
+from passlib.utils.compat import add_doc, join_bytes, join_byte_values, \
join_byte_elems, exc_err, irange, imap, PY3, u, \
- join_unicode, unicode, byte_elem_value, PY_MIN_32, next_method_attr
+ join_unicode, unicode, byte_elem_value, next_method_attr
# local
__all__ = [
# constants
- 'PYPY',
'JYTHON',
'sys_bits',
'unix_crypt_schemes',
@@ -110,7 +109,7 @@ rounds_cost_values = [ "linear", "log2" ]
from passlib.exc import MissingBackendError
# internal helpers
-_BEMPTY = b('')
+_BEMPTY = b''
_UEMPTY = u("")
_USPACE = u(" ")
@@ -482,7 +481,8 @@ def render_bytes(source, *args):
else arg for arg in args)
return result.encode("latin-1")
-if PY_MIN_32:
+if PY3:
+ # new in py32
def bytes_to_int(value):
return int.from_bytes(value, 'big')
def int_to_bytes(value, count):
@@ -492,13 +492,8 @@ else:
from binascii import hexlify, unhexlify
def bytes_to_int(value):
return int(hexlify(value),16)
- if PY3:
- # grr, why did py3 have to break % for bytes?
- def int_to_bytes(value, count):
- return unhexlify((('%%0%dx' % (count<<1)) % value).encode("ascii"))
- else:
- def int_to_bytes(value, count):
- return unhexlify(('%%0%dx' % (count<<1)) % value)
+ def int_to_bytes(value, count):
+ return unhexlify(('%%0%dx' % (count<<1)) % value)
add_doc(bytes_to_int, "decode byte string as single big-endian integer")
add_doc(int_to_bytes, "encode integer as single big-endian byte string")
@@ -516,7 +511,7 @@ def repeat_string(source, size):
else:
return source[:size]
-_BNULL = b("\x00")
+_BNULL = b"\x00"
_UNULL = u("\x00")
def right_pad_string(source, size, pad=None):
@@ -532,7 +527,7 @@ def right_pad_string(source, size, pad=None):
#=============================================================================
# encoding helpers
#=============================================================================
-_ASCII_TEST_BYTES = b("\x00\n aA:#!\x7f")
+_ASCII_TEST_BYTES = b"\x00\n aA:#!\x7f"
_ASCII_TEST_UNICODE = _ASCII_TEST_BYTES.decode("ascii")
def is_ascii_codec(codec):
@@ -547,7 +542,7 @@ def is_same_codec(left, right):
return False
return _lookup_codec(left).name == _lookup_codec(right).name
-_B80 = b('\x80')[0]
+_B80 = b'\x80'[0]
_U80 = u('\x80')
def is_ascii_safe(source):
"""Check if string (bytes or unicode) contains only 7-bit ascii"""
@@ -1290,10 +1285,10 @@ bcrypt64 = LazyBase64Engine(BCRYPT_CHARS, big=True)
#=============================================================================
# adapted-base64 encoding
#=============================================================================
-_A64_ALTCHARS = b("./")
-_A64_STRIP = b("=\n")
-_A64_PAD1 = b("=")
-_A64_PAD2 = b("==")
+_A64_ALTCHARS = b"./"
+_A64_STRIP = b"=\n"
+_A64_PAD1 = b"="
+_A64_PAD2 = b"=="
def ab64_encode(data):
"""encode using variant of base64