當前位置: 首頁>>代碼示例>>Python>>正文


Python bitstring.BitStream方法代碼示例

本文整理匯總了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 
開發者ID:avatartwo,項目名稱:avatar2,代碼行數:25,代碼來源:coresight.py

示例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) 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:20,代碼來源:test_bitstream.py

示例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')) 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:18,代碼來源:test_bitstream.py

示例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') 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:24,代碼來源:test_bitstream.py

示例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')) 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:24,代碼來源:test_bitstream.py

示例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) 
開發者ID:yunwilliamyu,項目名稱:hyperminhash,代碼行數:12,代碼來源:hyperminhash.py

示例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 
開發者ID:ywangd,項目名稱:pybufrkit,代碼行數:6,代碼來源:bitops.py

示例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}') 
開發者ID:PeteAndersen,項目名稱:swarfarm,代碼行數:43,代碼來源:static.py

示例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 
開發者ID:KI-labs,項目名稱:kaos,代碼行數:14,代碼來源:pachyderm.py

示例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)) 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:7,代碼來源:test_bitstring.py

示例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) 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:5,代碼來源:test_bitstring.py

示例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) 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:14,代碼來源:test_bitstring.py

示例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) 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:9,代碼來源:test_bitstring.py

示例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)) 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:11,代碼來源:test_bitstream.py

示例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) 
開發者ID:scott-griffiths,項目名稱:bitstring,代碼行數:9,代碼來源:test_bitstream.py


注:本文中的bitstring.BitStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。