本文整理汇总了Python中bitstring.ConstBitStream方法的典型用法代码示例。如果您正苦于以下问题:Python bitstring.ConstBitStream方法的具体用法?Python bitstring.ConstBitStream怎么用?Python bitstring.ConstBitStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitstring
的用法示例。
在下文中一共展示了bitstring.ConstBitStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRepr
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testRepr(self):
max = bitstring.MAX_CHARS
bls = ['', '0b1', '0o5', '0x43412424f41', '0b00101001010101']
for bs in bls:
a = BitStream(bs)
b = eval(a.__repr__())
self.assertTrue(a == b)
for f in [ConstBitStream(filename='test.m1v'),
ConstBitStream(filename='test.m1v', length=17),
ConstBitStream(filename='test.m1v', length=23, offset=23102)]:
f2 = eval(f.__repr__())
self.assertEqual(f._datastore._rawarray.source.name, f2._datastore._rawarray.source.name)
self.assertTrue(f2.tobytes() == f.tobytes())
a = BitStream('0b1')
self.assertEqual(repr(a), "BitStream('0b1')")
a += '0b11'
self.assertEqual(repr(a), "BitStream('0b111')")
a += '0b1'
self.assertEqual(repr(a), "BitStream('0xf')")
a *= max
self.assertEqual(repr(a), "BitStream('0x" + "f" * max + "')")
a += '0xf'
self.assertEqual(repr(a), "BitStream('0x" + "f" * max + "...') # length=%d" % (max * 4 + 4))
示例2: testLengthKeywords
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testLengthKeywords(self):
s = BitStream('0x0102')
x, y = s.peeklist('a, hex:b', a=8, b=4)
self.assertEqual((x, y), (1, '0'))
self.assertEqual(s.pos, 0)
##class Miscellany(unittest.TestCase):
##
## def testNumpyInt(self):
## try:
## import numpy
## a = ConstBitStream(uint=numpy.uint8(5), length=3)
## self.assertEqual(a.uint, 5)
## except ImportError:
## # Not to worry
## pass
示例3: handle
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def handle(self, connection, address):
self.address = address
self.connection = connection
logging.debug(f"Connection from {address[0]}")
buffer = ConstBitStream()
while True:
try:
data = connection.recv(1024)
except OSError:
break
if not data:
break
data = buffer + ConstBitStream(data)
buffer = ConstBitStream()
if data.hex == "3c706f6c6963792d66696c652d726571756573742f3e00":
send_data = BitArray(const.XML)
send_data.append("0x00")
connection.send(send_data.bytes)
continue
while len(data) - data.pos > 32:
length = data.read(32).int
if (len(data) - data.pos) / 8 < length:
data.pos = 0
break
final_data = protocol.processFrame(data.read(length * 8),
True)
if final_data:
try:
self.server.process_data(final_data, self)
except Exception:
logging.exception("Ошибка при обработке данных")
if len(data) - data.pos > 0:
buffer = data.read(len(data) - data.pos)
self._close_connection()
示例4: bitarray_to_u5
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def bitarray_to_u5(barr):
assert len(barr) % 5 == 0
ret = []
s = bitstring.ConstBitStream(barr)
while s.pos != s.len:
ret.append(s.read(5).uint)
return ret
示例5: _get_decrypted_data
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def _get_decrypted_data():
if _LocalValueData._decrypted_data is None:
with open(_LocalValueData.filename) as f:
_LocalValueData._decrypted_data = decrypt_response(f.read().strip('\0'))
return ConstBitStream(_LocalValueData._decrypted_data)
示例6: _get_file
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def _get_file():
return ConstBitStream(filename=_Strings.filename)
示例7: testAll
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testAll(self):
exported = ['ConstBitArray', 'ConstBitStream', 'BitStream', 'BitArray',
'Bits', 'BitString', 'pack', 'Error', 'ReadError',
'InterpretError', 'ByteAlignError', 'CreationError', 'bytealigned', 'set_lsb0', 'set_msb0']
self.assertEqual(set(bitstring.__all__), set(exported))
示例8: testBaselineMemory
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testBaselineMemory(self):
try:
import pympler.asizeof.asizeof as size
except ImportError:
return
# These values might be platform dependent, so don't fret too much.
self.assertEqual(size(bitstring.ConstBitStream([0])), 64)
self.assertEqual(size(bitstring.Bits([0])), 64)
self.assertEqual(size(bitstring.BitStream([0])), 64)
self.assertEqual(size(bitstring.BitArray([0])), 64)
from bitstring.bitstore import ByteStore
self.assertEqual(size(ByteStore(bytearray())), 100)
示例9: testConstBitStreamCopy
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testConstBitStreamCopy(self):
cbs = bitstring.ConstBitStream(100)
cbs.pos = 50
cbs_copy = copy.copy(cbs)
self.assertEqual(cbs_copy.pos, 0)
self.assertTrue(cbs._datastore is cbs_copy._datastore)
self.assertTrue(cbs == cbs_copy)
示例10: testCBS
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testCBS(self):
a = bitstring.ConstBitStream('0b11000')
b = bitstring.ConstBitStream('0b11000')
self.assertFalse(a is b)
示例11: testAppendToBits
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testAppendToBits(self):
a = Bits(BitArray())
with self.assertRaises(AttributeError):
a.append('0b1')
self.assertEqual(type(a), Bits)
b = bitstring.ConstBitStream(bitstring.BitStream())
self.assertEqual(type(b), bitstring.ConstBitStream)
示例12: testCreationFromFileOperations
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testCreationFromFileOperations(self):
s = BitStream(filename='smalltestfile')
s.append('0xff')
self.assertEqual(s.hex, '0123456789abcdefff')
s = ConstBitStream(filename='smalltestfile')
t = BitStream('0xff') + s
self.assertEqual(t.hex, 'ff0123456789abcdef')
s = BitStream(filename='smalltestfile')
del s[:1]
self.assertEqual((BitStream('0b0') + s).hex, '0123456789abcdef')
s = BitStream(filename='smalltestfile')
del s[:7 * 8]
self.assertEqual(s.hex, 'ef')
s = BitStream(filename='smalltestfile')
s.insert('0xc', 4)
self.assertEqual(s.hex, '0c123456789abcdef')
s = BitStream(filename='smalltestfile')
s.prepend('0xf')
self.assertEqual(s.hex, 'f0123456789abcdef')
s = BitStream(filename='smalltestfile')
s.overwrite('0xaaa', 12)
self.assertEqual(s.hex, '012aaa6789abcdef')
s = BitStream(filename='smalltestfile')
s.reverse()
self.assertEqual(s.hex, 'f7b3d591e6a2c480')
s = BitStream(filename='smalltestfile')
del s[-60:]
self.assertEqual(s.hex, '0')
s = BitStream(filename='smalltestfile')
del s[:60]
self.assertEqual(s.hex, 'f')
示例13: testFileProperties
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testFileProperties(self):
s = ConstBitStream(filename='smalltestfile')
self.assertEqual(s.hex, '0123456789abcdef')
self.assertEqual(s.uint, 81985529216486895)
self.assertEqual(s.int, 81985529216486895)
self.assertEqual(s.bin, '0000000100100011010001010110011110001001101010111100110111101111')
self.assertEqual(s[:-1].oct, '002215053170465363367')
s.bitpos = 0
self.assertEqual(s.read('se'), -72)
s.bitpos = 0
self.assertEqual(s.read('ue'), 144)
self.assertEqual(s.bytes, b'\x01\x23\x45\x67\x89\xab\xcd\xef')
self.assertEqual(s.tobytes(), b'\x01\x23\x45\x67\x89\xab\xcd\xef')
示例14: testCreationFromFileWithLength
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testCreationFromFileWithLength(self):
s = ConstBitStream(filename='test.m1v', length=32)
self.assertEqual(s.length, 32)
self.assertEqual(s.hex, '000001b3')
s = ConstBitStream(filename='test.m1v', length=0)
self.assertFalse(s)
self.assertRaises(bitstring.CreationError, BitStream, filename='smalltestfile', length=65)
self.assertRaises(bitstring.CreationError, ConstBitStream, filename='smalltestfile', length=64, offset=1)
# self.assertRaises(bitstring.CreationError, ConstBitStream, filename='smalltestfile', offset=65)
with open('smalltestfile', 'rb') as f:
# self.assertRaises(bitstring.CreationError, ConstBitStream, auto=f, offset=65)
self.assertRaises(bitstring.CreationError, ConstBitStream, auto=f, length=65)
self.assertRaises(bitstring.CreationError, ConstBitStream, auto=f, offset=60, length=5)
示例15: testFileBitGetting
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import ConstBitStream [as 别名]
def testFileBitGetting(self):
s = ConstBitStream(filename='smalltestfile', offset=16, length=8) # 0x45
b = s[1]
self.assertTrue(b)
b = s.any(0, [-1, -2, -3])
self.assertTrue(b)
b = s.all(0, [0, 1, 2])
self.assertFalse(b)