예제 #1
0
def numbits_union(numbits1, numbits2):
    """Compute the union of two numbits.

    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))
예제 #2
0
def numbits_intersection(numbits1, numbits2):
    """Compute the intersection of two numbits.

    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)
    return _to_blob(intersection_bytes.rstrip(b'\0'))
예제 #3
0
    def test_running_pyc_from_wrong_python(self):
        pycfile = self.make_pyc()

        # Jam Python 2.1 magic number into the .pyc file.
        with open(pycfile, "r+b") as fpyc:
            fpyc.seek(0)
            fpyc.write(binary_bytes([0x2a, 0xeb, 0x0d, 0x0a]))

        with self.assertRaisesRegex(NoCode, "Bad magic number in .pyc file"):
            run_python_file(pycfile, [pycfile])
예제 #4
0
    def test_running_pyc_from_wrong_python(self):
        pycfile = self.make_pyc()

        # Jam Python 2.1 magic number into the .pyc file.
        with open(pycfile, "r+b") as fpyc:
            fpyc.seek(0)
            fpyc.write(binary_bytes([0x2a, 0xeb, 0x0d, 0x0a]))

        with self.assertRaisesRegex(NoCode, "Bad magic number in .pyc file"):
            run_python_file(pycfile, [pycfile])
예제 #5
0
    def test_running_pyc_from_wrong_python(self):
        pycfile = self.make_pyc()

        # Jam Python 2.1 magic number into the .pyc file.
        fpyc = open(pycfile, "r+b")
        fpyc.seek(0)
        fpyc.write(binary_bytes([0x2A, 0xEB, 0x0D, 0x0A]))
        fpyc.close()

        self.assertRaisesRegexp(NoCode, "Bad magic number in .pyc file", run_python_file, pycfile, [pycfile])
예제 #6
0
def numbits_union(numbits1, numbits2):
    """Compute the union of two numbits.

    Arguments:
        numbits1, numbits2: packed number sets.

    Returns:
        A new numbits, the union of the two number sets.
    """
    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))
예제 #7
0
    def test_running_pyc_from_wrong_python(self):
        pycfile = self.make_pyc()

        # Jam Python 2.1 magic number into the .pyc file.
        with open(pycfile, "r+b") as fpyc:
            fpyc.seek(0)
            fpyc.write(binary_bytes([0x2a, 0xeb, 0x0d, 0x0a]))

        with self.assertRaisesRegex(NoCode, "Bad magic number in .pyc file"):
            run_python_file([pycfile])

        # In some environments, the pycfile persists and pollutes another test.
        os.remove(pycfile)
예제 #8
0
    def test_running_pyc_from_wrong_python(self):
        pycfile = self.make_pyc()

        # Jam Python 2.1 magic number into the .pyc file.
        fpyc = open(pycfile, "r+b")
        fpyc.seek(0)
        fpyc.write(binary_bytes([0x2a, 0xeb, 0x0d, 0x0a]))
        fpyc.close()

        self.assertRaisesRegexp(
            NoCode, "Bad magic number in .pyc file",
            run_python_file, pycfile, [pycfile]
        )
예제 #9
0
 def test_binary_bytes(self):
     byte_values = [0, 255, 17, 23, 42, 57]
     bb = binary_bytes(byte_values)
     self.assertEqual(len(bb), len(byte_values))
     self.assertEqual(byte_values, list(bytes_to_ints(bb)))
예제 #10
0
 def test_binary_bytes(self):
     byte_values = [0, 255, 17, 23, 42, 57]
     bb = binary_bytes(byte_values)
     self.assertEqual(len(bb), len(byte_values))
     self.assertEqual(byte_values, list(bytes_to_ints(bb)))
예제 #11
0
 def test_binary_bytes(self):
     byte_values = [0, 255, 17, 23, 42, 57]
     bb = binary_bytes(byte_values)
     assert len(bb) == len(byte_values)
     assert byte_values == list(bytes_to_ints(bb))
예제 #12
0
def merge_bitmaps(map1, map2):
    """Merge two bitmaps"""
    byte_pairs = zip_longest(bytes_to_ints(map1), bytes_to_ints(map2), fillvalue=0)
    return binary_bytes(b1 | b2 for b1, b2 in byte_pairs)