Exemplo n.º 1
0
	def test_unconsumed_ranges3(self):
		stream = six.BytesIO(pfp.utils.binary("A" * 100))
		bitwrapped = BitwrappedStream(stream)

		bitwrapped.read(10)

		# it should not need a second read to add the
		# unconsumed range
		uranges = bitwrapped.unconsumed_ranges()

		self.assertEqual(len(uranges), 0)
Exemplo n.º 2
0
    def test_unconsumed_ranges3(self):
        stream = six.BytesIO(pfp.utils.binary("A" * 100))
        bitwrapped = BitwrappedStream(stream)

        bitwrapped.read(10)

        # it should not need a second read to add the
        # unconsumed range
        uranges = bitwrapped.unconsumed_ranges()

        self.assertEqual(len(uranges), 0)
Exemplo n.º 3
0
    def test_unconsumed_ranges2(self):
        stream = six.BytesIO(pfp.utils.binary("A" * 100))
        bitwrapped = BitwrappedStream(stream)

        bitwrapped.read(10)
        bitwrapped.seek(bitwrapped.tell() + 10)

        # it should not need a second read to add the
        # unconsumed range
        uranges = bitwrapped.unconsumed_ranges()

        self.assertEqual(len(uranges), 1)

        # test (11,20]
        self.assertEqual(len(uranges[11]), 1)
        self.assertEqual(len(uranges[10]), 0)
        self.assertEqual(len(uranges[19]), 1)
        self.assertEqual(len(uranges[20]), 0)
Exemplo n.º 4
0
	def test_unconsumed_ranges2(self):
		stream = six.BytesIO(pfp.utils.binary("A" * 100))
		bitwrapped = BitwrappedStream(stream)

		bitwrapped.read(10)
		bitwrapped.seek(bitwrapped.tell()+10)

		# it should not need a second read to add the
		# unconsumed range
		uranges = bitwrapped.unconsumed_ranges()

		self.assertEqual(len(uranges), 1)

		# test (11,20]
		self.assertEqual(len(uranges[11]), 1)
		self.assertEqual(len(uranges[10]), 0)
		self.assertEqual(len(uranges[19]), 1)
		self.assertEqual(len(uranges[20]), 0)
Exemplo n.º 5
0
	def test_bits_read2_padded2(self):
		stream = six.BytesIO(pfp.utils.binary(chr(int("11110000",2)) + chr(int("10101010", 2))))
		bitwrapped = BitwrappedStream(stream)
		bitwrapped.padded = True

		res = bitwrapped.read_bits(4)
		self.assertEqual([1,1,1,1], res)

		next_byte = bitwrapped.read(1)
		self.assertEqual(pfp.utils.binary(chr(int("10101010", 2))), next_byte)
Exemplo n.º 6
0
    def test_bits_read2_padded2(self):
        stream = six.BytesIO(
            pfp.utils.binary(
                chr(int("11110000", 2)) + chr(int("10101010", 2))))
        bitwrapped = BitwrappedStream(stream)
        bitwrapped.padded = True

        res = bitwrapped.read_bits(4)
        self.assertEqual([1, 1, 1, 1], res)

        next_byte = bitwrapped.read(1)
        self.assertEqual(pfp.utils.binary(chr(int("10101010", 2))), next_byte)
Exemplo n.º 7
0
	def test_bits_read_unpadded(self):
		stream = six.BytesIO(pfp.utils.binary(chr(int("11110000",2)) + chr(int("10101010", 2))))
		bitwrapped = BitwrappedStream(stream)
		bitwrapped.padded = False

		res = bitwrapped.read_bits(4)
		self.assertEqual([1,1,1,1], res)

		res = bitwrapped.read(1)
		self.assertEqual(pfp.utils.binary(chr(int("00001010", 2))), res)

		res = bitwrapped.read_bits(4)
		self.assertEqual([1,0,1,0], res)
Exemplo n.º 8
0
    def test_bits_read_unpadded(self):
        stream = six.BytesIO(
            pfp.utils.binary(
                chr(int("11110000", 2)) + chr(int("10101010", 2))))
        bitwrapped = BitwrappedStream(stream)
        bitwrapped.padded = False

        res = bitwrapped.read_bits(4)
        self.assertEqual([1, 1, 1, 1], res)

        res = bitwrapped.read(1)
        self.assertEqual(pfp.utils.binary(chr(int("00001010", 2))), res)

        res = bitwrapped.read_bits(4)
        self.assertEqual([1, 0, 1, 0], res)
Exemplo n.º 9
0
    def test_tell_bits(self):
        stream = six.BytesIO(pfp.utils.binary("\x41" + chr(0b11001100)))
        bitwrapped = BitwrappedStream(stream)

        res = bitwrapped.read(1)
        self.assertEqual(res, b"\x41")

        self.assertEqual(bitwrapped.tell(), 1)
        self.assertEqual(bitwrapped.tell_bits(), 0)

        bits = bitwrapped.read_bits(1)
        self.assertEqual(bits, [1])
        self.assertEqual(bitwrapped.tell_bits(), 1)

        bits = bitwrapped.read_bits(1)
        self.assertEqual(bits, [1])
        self.assertEqual(bitwrapped.tell_bits(), 2)

        bits = bitwrapped.read_bits(1)
        self.assertEqual(bits, [0])
        self.assertEqual(bitwrapped.tell_bits(), 3)
Exemplo n.º 10
0
    def test_unconsumed_ranges1(self):
        stream = six.BytesIO(pfp.utils.binary("A" * 100))
        bitwrapped = BitwrappedStream(stream)

        bitwrapped.read(10)
        bitwrapped.seek(bitwrapped.tell() + 10)
        bitwrapped.read(10)
        bitwrapped.seek(bitwrapped.tell() + 10)
        bitwrapped.read(10)

        uranges = bitwrapped.unconsumed_ranges()

        # test (11,20]
        self.assertEqual(len(uranges[11]), 1)
        self.assertEqual(len(uranges[10]), 0)
        self.assertEqual(len(uranges[19]), 1)
        self.assertEqual(len(uranges[20]), 0)

        # test (31,40]
        self.assertEqual(len(uranges[31]), 1)
        self.assertEqual(len(uranges[30]), 0)
        self.assertEqual(len(uranges[39]), 1)
        self.assertEqual(len(uranges[40]), 0)
Exemplo n.º 11
0
	def test_unconsumed_ranges1(self):
		stream = six.BytesIO(pfp.utils.binary("A" * 100))
		bitwrapped = BitwrappedStream(stream)

		bitwrapped.read(10)
		bitwrapped.seek(bitwrapped.tell()+10)
		bitwrapped.read(10)
		bitwrapped.seek(bitwrapped.tell()+10)
		bitwrapped.read(10)

		uranges = bitwrapped.unconsumed_ranges()

		# test (11,20]
		self.assertEqual(len(uranges[11]), 1)
		self.assertEqual(len(uranges[10]), 0)
		self.assertEqual(len(uranges[19]), 1)
		self.assertEqual(len(uranges[20]), 0)

		# test (31,40]
		self.assertEqual(len(uranges[31]), 1)
		self.assertEqual(len(uranges[30]), 0)
		self.assertEqual(len(uranges[39]), 1)
		self.assertEqual(len(uranges[40]), 0)
Exemplo n.º 12
0
 def test_bytes_read(self):
     stream = six.BytesIO(pfp.utils.binary("abcd"))
     bitwrapped = BitwrappedStream(stream)
     res = bitwrapped.read(4)
     self.assertEqual(pfp.utils.binary("abcd"), res)
Exemplo n.º 13
0
	def test_bytes_read(self):
		stream = six.BytesIO(pfp.utils.binary("abcd"))
		bitwrapped = BitwrappedStream(stream)
		res = bitwrapped.read(4)
		self.assertEqual(pfp.utils.binary("abcd"), res)