本文整理汇总了Python中bitstring.BitStream方法的典型用法代码示例。如果您正苦于以下问题:Python bitstring.BitStream方法的具体用法?Python bitstring.BitStream怎么用?Python bitstring.BitStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitstring
的用法示例。
在下文中一共展示了bitstring.BitStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def __init__(self, avatar, origin):
self.avatar = avatar
self._avatar_queue = avatar.queue
self._avatar_fast_queue = avatar.fast_queue
self._origin = origin
self.trace_queue = None
self.trace_buffer = BitStream()
self._close = Event()
self._closed = Event()
self._close.clear()
self._closed.clear()
self._sync_responses_cv = Condition()
self._last_exec_token = 0
# logger = logging.getLogger('%s.%s' %
# (origin.log.name, self.__class__.__name__)
# ) if origin else \
# logging.getLogger(self.__class__.__name__)
self._monitor_stub_base = None
self._monitor_stub_isr = None
self._monitor_stub_loop = None
self._monitor_stub_writeme = None
Thread.__init__(self)
self.daemon = True
示例2: testReplaceBitpos
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def testReplaceBitpos(self):
a = BitStream('0xff')
a.bitpos = 8
a.replace('0xff', '', bytealigned=True)
self.assertEqual(a.bitpos, 0)
a = BitStream('0b0011110001')
a.bitpos = 4
a.replace('0b1', '0b000')
self.assertEqual(a.bitpos, 8)
a = BitStream('0b1')
a.bitpos = 1
a.replace('0b1', '0b11111', bytealigned=True)
self.assertEqual(a.bitpos, 5)
a.replace('0b11', '0b0', False)
self.assertEqual(a.bitpos, 3)
a.append('0b00')
a.replace('0b00', '0xffff')
self.assertEqual(a.bitpos, 17)
示例3: testInsertingUsingSetItem
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def testInsertingUsingSetItem(self):
a = BitStream()
a[0:0] = '0xdeadbeef'
self.assertEqual(a, '0xdeadbeef')
self.assertEqual(a.bytepos, 4)
a[16:16] = '0xfeed'
self.assertEqual(a, '0xdeadfeedbeef')
self.assertEqual(a.bytepos, 4)
a[0:0] = '0xa'
self.assertEqual(a, '0xadeadfeedbeef')
self.assertEqual(a.bitpos, 4)
a.bytepos = 6
a[0:0] = '0xff'
self.assertEqual(a.bytepos, 1)
a[8:0] = '0x00000'
self.assertTrue(a.startswith('0xff00000adead'))
示例4: testPackWithLiterals
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def testPackWithLiterals(self):
s = bitstring.pack('0xf')
self.assertEqual(s, '0xf')
self.assertTrue(type(s), BitStream)
s = pack('0b1')
self.assertEqual(s, '0b1')
s = pack('0o7')
self.assertEqual(s, '0o7')
s = pack('int:10=-1')
self.assertEqual(s, '0b1111111111')
s = pack('uint:10=1')
self.assertEqual(s, '0b0000000001')
s = pack('ue=12')
self.assertEqual(s.ue, 12)
s = pack('se=-12')
self.assertEqual(s.se, -12)
s = pack('bin=01')
self.assertEqual(s.bin, '01')
s = pack('hex=01')
self.assertEqual(s.hex, '01')
s = pack('oct=01')
self.assertEqual(s.oct, '01')
示例5: testPackWithLengthRestriction
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def testPackWithLengthRestriction(self):
s = pack('bin:3', '0b000')
self.assertRaises(bitstring.CreationError, pack, 'bin:3', '0b0011')
self.assertRaises(bitstring.CreationError, pack, 'bin:3', '0b11')
self.assertRaises(bitstring.CreationError, pack, 'bin:3=0b0011')
self.assertRaises(bitstring.CreationError, pack, 'bin:3=0b11')
s = pack('hex:4', '0xf')
self.assertRaises(bitstring.CreationError, pack, 'hex:4', '0b111')
self.assertRaises(bitstring.CreationError, pack, 'hex:4', '0b11111')
self.assertRaises(bitstring.CreationError, pack, 'hex:8=0xf')
s = pack('oct:6', '0o77')
self.assertRaises(bitstring.CreationError, pack, 'oct:6', '0o1')
self.assertRaises(bitstring.CreationError, pack, 'oct:6', '0o111')
self.assertRaises(bitstring.CreationError, pack, 'oct:3', '0b1')
self.assertRaises(bitstring.CreationError, pack, 'oct:3=hello', hello='0o12')
s = pack('bits:3', BitStream('0b111'))
self.assertRaises(bitstring.CreationError, pack, 'bits:3', BitStream('0b11'))
self.assertRaises(bitstring.CreationError, pack, 'bits:3', BitStream('0b1111'))
self.assertRaises(bitstring.CreationError, pack, 'bits:12=b', b=BitStream('0b11'))
示例6: unpackbits
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def unpackbits(X):
'''Returns a tuple (b, L) corresponding to a list of unsigned b-bit integers, from X'''
params = X[0:16]
b, length = struct.unpack("<2Q", params)
L = np.zeros(length, dtype=np.uint64)
array = bitstring.BitArray(X[16:])
array = bitstring.BitStream(array)
for i in range(length):
L[i] = array.read(b).uint
return (b, L)
示例7: __init__
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def __init__(self, s):
import bitstring
self.bit_stream = bitstring.BitStream(bytes=s)
self.bitstring_Error = bitstring.Error
示例8: decrypt_images
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def decrypt_images(**kwargs):
path = kwargs.pop('path', 'herders/static/herders/images')
for im_path in iglob(f'{path}/**/*.png', recursive=True):
encrypted = BitStream(filename=im_path)
# Check if it is 'encrypted'. 8th byte is 0x0B instead of the correct signature 0x0A
encrypted.pos = 0x07 * 8
signature = encrypted.peek('uint:8')
if signature == 0x0B:
print(f'Decrypting {im_path}')
# Correct the PNG signature
encrypted.overwrite('0x0A', encrypted.pos)
# Replace bits with magic decrypted values
try:
while True:
pos = encrypted.pos
val = encrypted.peek('uint:8')
encrypted.overwrite(Bits(uint=com2us_decrypt_values[val], length=8), pos)
except ReadError:
# EOF
pass
# Write it back to the file
with open(im_path, 'wb') as f:
encrypted.tofile(f)
continue
# Check for weird jpeg format with extra header junk. Convert to png.
encrypted.pos = 0
if encrypted.peek('bytes:5') == b'Joker':
print(f'Trimming and converting weird JPEG to PNG {im_path}')
del encrypted[0:16 * 8]
# Open it as a jpg and resave to disk
try:
new_imfile = Image.open(io.BytesIO(encrypted.tobytes()))
new_imfile.save(im_path)
except IOError:
print(f'Unable to open {im_path}')
示例9: get_blob
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def get_blob(self, repo: str, commit: str, path: str):
app.logger.debug("@%s: get blob from repo %s at path %s with commit id %s", PachydermClient.__name__, repo,
path, commit)
file = self.pfs_client.get_file(f"{repo}/{commit}",
path=path)
stream = bitstring.BitStream()
for chunk in file:
stream.append(chunk)
return stream.bytes
示例10: testAll
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [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))
示例11: testAliases
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def testAliases(self):
self.assertTrue(bitstring.Bits is bitstring.ConstBitArray)
self.assertTrue(bitstring.BitStream is bitstring.BitString)
示例12: testBaselineMemory
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [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)
示例13: testBitStreamCopy
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def testBitStreamCopy(self):
bs = bitstring.BitStream(100)
bs.pos = 50
bs_copy = copy.copy(bs)
self.assertEqual(bs_copy.pos, 0)
self.assertFalse(bs._datastore is bs_copy._datastore)
self.assertTrue(bs == bs_copy)
示例14: testFlexibleInitialisation
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def testFlexibleInitialisation(self):
a = BitStream('uint:8=12')
c = BitStream(' uint : 8 = 12')
self.assertTrue(a == c == BitStream(uint=12, length=8))
self.assertEqual(a.uint, 12)
a = BitStream(' int:2= -1')
b = BitStream('int :2 = -1')
c = BitStream(' int: 2 =-1 ')
self.assertTrue(a == b == c == BitStream(int=-1, length=2))
示例15: testFlexibleInitialisation3
# 需要导入模块: import bitstring [as 别名]
# 或者: from bitstring import BitStream [as 别名]
def testFlexibleInitialisation3(self):
for s in ['se=-1', ' se = -1 ', 'se = -1']:
a = BitStream(s)
self.assertEqual(a.se, -1)
for s in ['ue=23', 'ue =23', 'ue = 23']:
a = BitStream(s)
self.assertEqual(a.ue, 23)