Commits

Gora Khargosh committed ecfd725

Clean up EMPTY_BYTE references.

Signed-off-by: Gora Khargosh <gora.khargosh@gmail.com>

Comments (0)

Files changed (8)

mom/_alt_builtins.py

 from __future__ import absolute_import
 
 from struct import pack
-from mom._compat import ZERO_BYTE, get_word_alignment
+from mom._compat import ZERO_BYTE, get_word_alignment, EMPTY_BYTE
 from mom.builtins import b, byte_ord
 
 
     # Do not change this to `not num` otherwise a TypeError will not
     # be raised when `None` is passed in as a value.
     if num == 0:
-        return b('')
+        return EMPTY_BYTE
     if num < 0:
         num = -num
-    raw_bytes = b('')
+    raw_bytes = EMPTY_BYTE
     word_bits, num_bytes, max_uint, pack_type = _get_machine_alignment(num)
     pack_format = ">" + pack_type
     while num > 0:

mom/codec/__init__.py

 from __future__ import absolute_import
 
 import binascii
-from mom._compat import have_python3, ZERO_BYTE
+from mom._compat import have_python3, ZERO_BYTE, EMPTY_BYTE
 from mom.builtins import is_bytes, b
 from mom.functional import leading, chunks
 from mom.codec.integer import bytes_to_uint, uint_to_bytes
     if not is_bytes(raw_bytes):
         raise TypeError("argument must be raw bytes: got %r" %
                         type(raw_bytes).__name__)
-    return b('').join(_HEX_TO_BIN_LOOKUP[hex_char]
+    return EMPTY_BYTE.join(_HEX_TO_BIN_LOOKUP[hex_char]
                    for hex_char in hex_encode(raw_bytes))
 
     # Prefixed zero-bytes destructive. '\x00\x00' treated as '\x00'
     if not is_bytes(encoded):
         raise TypeError("argument must be bytes: got %r" %
                         type(encoded).__name__)
-    return hex_decode(b('').join(_BIN_TO_HEX_LOOKUP[nibble]
+    return hex_decode(EMPTY_BYTE.join(_BIN_TO_HEX_LOOKUP[nibble]
                               for nibble in chunks(encoded, 4)))
 
     # Prefixed zero-bytes destructive. '\x00\x00\x00' treated as '\x00'

mom/codec/_alt_base.py

 from array import array
 
 import re
-from mom._compat import ZERO_BYTE, UINT128_MAX
+from mom._compat import ZERO_BYTE, UINT128_MAX, EMPTY_BYTE
 from mom.builtins import is_bytes, b
 from mom.codec import uint_to_bytes
 from mom.codec.base58 import ASCII58_BYTES, ASCII58_ORDS
         raise TypeError("data must be raw bytes: got %r" %
                         type(raw_bytes).__name__)
     number = bytes_to_uint(raw_bytes)
-    encoded = b('')
+    encoded = EMPTY_BYTE
     while number > 0:
         encoded = base_bytes[number % 58] + encoded
         number //= 58
         raise TypeError("data must be raw bytes: got %r" %
                         type(raw_bytes).__name__)
     number = bytes_to_uint(raw_bytes)
-    encoded = b('')
+    encoded = EMPTY_BYTE
     while number > 0:
         encoded = base_bytes[number % 62] + encoded
         number //= 62
                         type(encoded).__name__)
 
     # Ignore whitespace.
-    encoded = re.sub(WHITESPACE_PATTERN, b(''), encoded)
+    encoded = re.sub(WHITESPACE_PATTERN, EMPTY_BYTE, encoded)
 
     # Convert to big integer.
     number = 0
     else:
         # We don't want to convert to b'\x00' when we get number == 0.
         # That would add an off-by-one extra zero byte in the result.
-        raw_bytes = b('')
+        raw_bytes = EMPTY_BYTE
 
     # Add prefixed padding if required.
     # 0 byte is represented using the first character in the character set.
                         type(encoded).__name__)
 
     # Ignore whitespace.
-    encoded = re.sub(WHITESPACE_PATTERN, b(''), encoded)
+    encoded = re.sub(WHITESPACE_PATTERN, EMPTY_BYTE, encoded)
 
     # Convert to big integer.
     number = 0
     else:
         # We don't want to convert to b'\x00' when we get number == 0.
         # That would add an off-by-one extra zero byte in the result.
-        raw_bytes = b('')
+        raw_bytes = EMPTY_BYTE
 
     # Add prefixed padding if required.
     # 0 byte is represented using the first character in the character set.
             "Encoded sequence must be bytes: got %r" % type(encoded).__name__
         )
     # Ignore whitespace.
-    encoded = b('').join(encoded.split())
+    encoded = EMPTY_BYTE.join(encoded.split())
     if len(encoded) != 20:
         raise ValueError("Not 20 encoded bytes: %r" % encoded)
     uint128 = 0

mom/codec/_alt_integer.py

 
 from array import array
 from struct import pack, pack_into, unpack
-from mom._compat import range, ZERO_BYTE, get_word_alignment
+from mom._compat import range, ZERO_BYTE, get_word_alignment, EMPTY_BYTE
 from mom.builtins import integer_byte_length, b, byte, is_bytes
 
 
             padding_size -= 1
         padding =  ZERO_BYTE * padding_size
     else:
-        padding = b('')
-    return padding + b('').join(raw_bytes)
+        padding = EMPTY_BYTE
+    return padding + EMPTY_BYTE.join(raw_bytes)
 
 
 # From pycrypto (for verification only).
     blocksize.
     """
     # after much testing, this algorithm was deemed to be the fastest
-    s = b('')
+    s = EMPTY_BYTE
     n = int(n)
     while n > 0:
         s = pack('>I', n & 0xffffffff) + s
     if number < 0:
         raise ValueError('Number must be unsigned integer: %d' % number)
 
-    raw_bytes = b('')
+    raw_bytes = EMPTY_BYTE
     if not number:
         raw_bytes = ZERO_BYTE
 
 #    if number < 0:
 #        raise ValueError('Number must be unsigned integer: %d' % number)
 #
-#    raw_bytes = b('')
+#    raw_bytes = EMPTY_BYTE
 #    # Align packing to machine word size.
 #    num = number
 #    word_bits, word_bytes, max_uint, pack_type = get_word_alignment(num)

mom/codec/base85.py

 from struct import unpack, pack
 from mom import string
 from mom.builtins import is_bytes, b, byte_ord, byte
-from mom._compat import range, ZERO_BYTE, UINT128_MAX, UINT32_MAX, have_little_endian, have_python3
+from mom._compat import range, ZERO_BYTE, UINT128_MAX, UINT32_MAX, have_little_endian, have_python3, EMPTY_BYTE
 
 
 __all__ = [
     #uint32s = [0] * num_uint32s
     uint32s = array('I', [0] * num_uint32s)
     j = 0
-    chunk = b('')
+    chunk = EMPTY_BYTE
     try:
         for i in range(0, length, 5):
             chunk = encoded[i:i+5]
     :returns:
         ASCII-85 encoded bytes.
     """
-    prefix = prefix or b("")
-    suffix = suffix or b("")
+    prefix = prefix or EMPTY_BYTE
+    suffix = suffix or EMPTY_BYTE
     if not (is_bytes(prefix) and is_bytes(suffix)):
         raise TypeError(
             "Prefix/suffix must be bytes: got prefix %r, %r" %
     :returns:
         ASCII85-decoded raw bytes.
     """
-    prefix = prefix or b("")
-    suffix = suffix or b("")
+    prefix = prefix or EMPTY_BYTE
+    suffix = suffix or EMPTY_BYTE
 
     if not (is_bytes(prefix) and is_bytes(suffix)):
         raise TypeError(
         )
 
     # ASCII-85 ignores whitespace.
-    encoded = b('').join(encoded.split())
+    encoded = EMPTY_BYTE.join(encoded.split())
 
     # Strip the prefix and suffix.
     if prefix and encoded.startswith(prefix):
             "Encoded sequence must be bytes: got %r" % type(encoded).__name__
         )
     # Ignore whitespace.
-    encoded = b('').join(encoded.split())
+    encoded = EMPTY_BYTE.join(encoded.split())
     return _b85decode_chunks(encoded, RFC1924_BYTES, RFC1924_ORDS)
 
 
         )
 
     # Ignore whitespace.
-    encoded = b('').join(encoded.split())
+    encoded = EMPTY_BYTE.join(encoded.split())
 
     if len(encoded) != 20:
         raise ValueError("Not 20 encoded bytes: %r" % encoded)

mom/codec/integer.py

 import binascii
 from struct import pack
 
-from mom._compat import get_word_alignment, ZERO_BYTE
+from mom._compat import get_word_alignment, ZERO_BYTE, EMPTY_BYTE
 from mom.builtins import is_bytes, b, bytes_leading
 
 
     # Ensure these are integers.
     number & 1 and chunk_size & 1 and fill_size & 1
 
-    raw_bytes = b('')
+    raw_bytes = EMPTY_BYTE
 
     # Pack the integer one machine word at a time into bytes.
     num = number

mom/net/mimeparse.py

  - best_match():        Choose the mime-type with the highest quality ('q')
                           from a list of candidates.
 """
+from mom._compat import EMPTY_BYTE
 
 from mom.builtins import b
 
         pos += 1
     weighted_matches.sort()
 
-    return weighted_matches[-1][0][1] and weighted_matches[-1][2] or b('')
+    return weighted_matches[-1][0][1] and weighted_matches[-1][2] or EMPTY_BYTE
 
 
 def _filter_blank(i):

mom/net/scheme/data.py

 
 
 from __future__ import absolute_import
+from mom._compat import EMPTY_BYTE
 
 try:
     # Python 3.
         # We want ASCII bytes.
         encode = lambda data: quote(data).encode('ascii')
         codec = b(",")
-    mime_type = mime_type or b("")
+    mime_type = mime_type or EMPTY_BYTE
 
-    charset = b(";charset=") + charset if charset else b("")
+    charset = b(";charset=") + charset if charset else EMPTY_BYTE
     encoded = encode(raw_bytes)
-    return b('').join((b("data:"), mime_type, charset, codec, encoded))
+    return EMPTY_BYTE.join((b("data:"), mime_type, charset, codec, encoded))
 
 
 def data_urlparse(data_url):