eric7/DebugClients/Python/coverage/numbits.py

branch
eric7
changeset 8775
0802ae193343
parent 8312
800c432b34c8
--- a/eric7/DebugClients/Python/coverage/numbits.py	Fri Nov 19 19:28:47 2021 +0100
+++ b/eric7/DebugClients/Python/coverage/numbits.py	Sat Nov 20 16:47:38 2021 +0100
@@ -15,22 +15,15 @@
 """
 import json
 
-from coverage import env
-from coverage.backward import byte_to_int, bytes_to_ints, binary_bytes, zip_longest
+from itertools import zip_longest
+
 from coverage.misc import contract, new_contract
 
-if env.PY3:
-    def _to_blob(b):
-        """Convert a bytestring into a type SQLite will accept for a blob."""
-        return b
+def _to_blob(b):
+    """Convert a bytestring into a type SQLite will accept for a blob."""
+    return b
 
-    new_contract('blob', lambda v: isinstance(v, bytes))
-else:
-    def _to_blob(b):
-        """Convert a bytestring into a type SQLite will accept for a blob."""
-        return buffer(b)                                    # pylint: disable=undefined-variable
-
-    new_contract('blob', lambda v: isinstance(v, buffer))   # pylint: disable=undefined-variable
+new_contract('blob', lambda v: isinstance(v, bytes))
 
 
 @contract(nums='Iterable', returns='blob')
@@ -69,7 +62,7 @@
 
     """
     nums = []
-    for byte_i, byte in enumerate(bytes_to_ints(numbits)):
+    for byte_i, byte in enumerate(numbits):
         for bit_i in range(8):
             if (byte & (1 << bit_i)):
                 nums.append(byte_i * 8 + bit_i)
@@ -83,8 +76,8 @@
     Returns:
         A new numbits, the union of `numbits1` and `numbits2`.
     """
-    byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0)
-    return _to_blob(binary_bytes(b1 | b2 for b1, b2 in byte_pairs))
+    byte_pairs = zip_longest(numbits1, numbits2, fillvalue=0)
+    return _to_blob(bytes(b1 | b2 for b1, b2 in byte_pairs))
 
 
 @contract(numbits1='blob', numbits2='blob', returns='blob')
@@ -94,8 +87,8 @@
     Returns:
         A new numbits, the intersection `numbits1` and `numbits2`.
     """
-    byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0)
-    intersection_bytes = binary_bytes(b1 & b2 for b1, b2 in byte_pairs)
+    byte_pairs = zip_longest(numbits1, numbits2, fillvalue=0)
+    intersection_bytes = bytes(b1 & b2 for b1, b2 in byte_pairs)
     return _to_blob(intersection_bytes.rstrip(b'\0'))
 
 
@@ -109,7 +102,7 @@
     Returns:
         A bool, True if there is any number in both `numbits1` and `numbits2`.
     """
-    byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0)
+    byte_pairs = zip_longest(numbits1, numbits2, fillvalue=0)
     return any(b1 & b2 for b1, b2 in byte_pairs)
 
 
@@ -123,7 +116,7 @@
     nbyte, nbit = divmod(num, 8)
     if nbyte >= len(numbits):
         return False
-    return bool(byte_to_int(numbits[nbyte]) & (1 << nbit))
+    return bool(numbits[nbyte] & (1 << nbit))
 
 
 def register_sqlite_functions(connection):

eric ide

mercurial