summaryrefslogtreecommitdiff
path: root/passlib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'passlib/utils')
-rw-r--r--passlib/utils/__init__.py8
-rw-r--r--passlib/utils/binary.py20
-rw-r--r--passlib/utils/compat/__init__.py9
-rw-r--r--passlib/utils/handlers.py4
4 files changed, 15 insertions, 26 deletions
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index aede331..94833ad 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -61,8 +61,7 @@ from passlib.utils.decor import (
hybrid_method,
)
from passlib.exc import ExpectedStringError, ExpectedTypeError
-from passlib.utils.compat import (add_doc, join_bytes, join_byte_values,
- join_byte_elems,
+from passlib.utils.compat import (add_doc, join_bytes,
join_unicode,
unicode_or_bytes,
get_method_function, PYPY)
@@ -1059,7 +1058,8 @@ def getrandbytes(rng, count):
yield value & 0xff
value >>= 3
i += 1
- return join_byte_values(helper())
+ return bytes(helper())
+
def getrandstr(rng, charset, count):
"""return string containing *count* number of chars/bytes, whose elements are drawn from specified charset, using specified rng"""
@@ -1088,7 +1088,7 @@ def getrandstr(rng, charset, count):
if isinstance(charset, str):
return join_unicode(helper())
else:
- return join_byte_elems(helper())
+ return bytes(helper())
_52charset = '2346789ABCDEFGHJKMNPQRTUVWXYZabcdefghjkmnpqrstuvwxyz'
diff --git a/passlib/utils/binary.py b/passlib/utils/binary.py
index 37bfefa..745366f 100644
--- a/passlib/utils/binary.py
+++ b/passlib/utils/binary.py
@@ -19,7 +19,7 @@ log = logging.getLogger(__name__)
from passlib import exc
from passlib.utils.compat import (
bascii_to_str,
- iter_byte_chars, join_byte_values, join_byte_elems,
+ iter_byte_chars,
unicode_or_bytes,
)
from passlib.utils.decor import memoized_property
@@ -91,7 +91,7 @@ LOWER_HEX_CHARS = u"0123456789abcdef"
#: special byte string containing all possible byte values
#: NOTE: for efficiency, this is treated as singleton by some of the code
-ALL_BYTE_VALUES = join_byte_values(range(256))
+ALL_BYTE_VALUES = bytes(range(256))
#: some string constants we reuse
B_EMPTY = b''
@@ -385,7 +385,7 @@ class Base64Engine(object):
chunks, tail = divmod(len(source), 3)
next_value = iter(source).__next__
gen = self._encode_bytes(next_value, chunks, tail)
- out = join_byte_elems(map(self._encode64, gen))
+ out = bytes(map(self._encode64, gen))
##if tail:
## padding = self.padding
## if padding:
@@ -492,7 +492,7 @@ class Base64Engine(object):
raise ValueError("input string length cannot be == 1 mod 4")
next_value = map(self._decode64, source).__next__
try:
- return join_byte_values(self._decode_bytes(next_value, chunks, tail))
+ return bytes(self._decode_bytes(next_value, chunks, tail))
except KeyError as err:
raise ValueError("invalid character: %r" % (err.args[0],))
@@ -655,19 +655,19 @@ class Base64Engine(object):
"""encode byte string, first transposing source using offset list"""
if not isinstance(source, bytes):
raise TypeError("source must be bytes, not %s" % (type(source),))
- tmp = join_byte_elems(source[off] for off in offsets)
+ tmp = bytes(source[off] for off in offsets)
return self.encode_bytes(tmp)
def decode_transposed_bytes(self, source, offsets):
"""decode byte string, then reverse transposition described by offset list"""
# NOTE: if transposition does not use all bytes of source,
- # the original can't be recovered... and join_byte_elems() will throw
+ # the original can't be recovered... and bytes() will throw
# an error because 1+ values in <buf> will be None.
tmp = self.decode_bytes(source)
buf = [None] * len(offsets)
for off, char in zip(offsets, tmp):
buf[off] = char
- return join_byte_elems(buf)
+ return bytes(buf)
#===================================================================
# integer decoding helpers - mainly used by des_crypt family
@@ -791,7 +791,7 @@ class Base64Engine(object):
else:
itr = range(0, bits, 6)
# padding is msb, so no change needed.
- return join_byte_elems(map(self._encode64,
+ return bytes(map(self._encode64,
((value>>off) & 0x3f for off in itr)))
#---------------------------------------------------------------
@@ -811,7 +811,7 @@ class Base64Engine(object):
raw = [value & 0x3f, (value>>6) & 0x3f]
if self.big:
raw = reversed(raw)
- return join_byte_elems(map(self._encode64, raw))
+ return bytes(map(self._encode64, raw))
def encode_int24(self, value):
"""encodes 24-bit integer -> 4 char string"""
@@ -821,7 +821,7 @@ class Base64Engine(object):
(value>>12) & 0x3f, (value>>18) & 0x3f]
if self.big:
raw = reversed(raw)
- return join_byte_elems(map(self._encode64, raw))
+ return bytes(map(self._encode64, raw))
def encode_int30(self, value):
"""decode 5 char string -> 30 bit integer"""
diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py
index f4ea2a6..f90d914 100644
--- a/passlib/utils/compat/__init__.py
+++ b/passlib/utils/compat/__init__.py
@@ -45,7 +45,6 @@ __all__ = [
'bascii_to_str',
'str_to_bascii',
'join_unicode', 'join_bytes',
- 'join_byte_values', 'join_byte_elems',
# context helpers
'nullcontext',
@@ -84,8 +83,6 @@ if True: # legacy PY3 indent
assert isinstance(s, str)
return s.encode("ascii")
- join_byte_values = join_byte_elems = bytes
-
def iter_byte_chars(s):
assert isinstance(s, bytes)
# FIXME: there has to be a better way to do this
@@ -95,12 +92,6 @@ if True: # legacy PY3 indent
add_doc(bascii_to_str, "helper to convert ascii bytes -> native str")
add_doc(str_to_bascii, "helper to convert ascii native str -> bytes")
-# join_byte_values -- function to convert list of ordinal integers to byte string.
-
-# join_byte_elems -- function to convert list of byte elements to byte string;
-# i.e. what's returned by ``b('a')[0]``...
-# this is 97 under PY3.
-
# byte_elem_value -- function to convert byte element to integer -- a noop under PY3
add_doc(iter_byte_chars, "iterate over byte string as sequence of 1-byte strings")
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index d16b7e5..8c02e69 100644
--- a/passlib/utils/handlers.py
+++ b/passlib/utils/handlers.py
@@ -26,9 +26,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, \
- join_unicode, \
- join_unicode, unicode_or_bytes, int_types
+from passlib.utils.compat import join_unicode, unicode_or_bytes, int_types
from passlib.utils.decor import classproperty, deprecated_method
# local
__all__ = [