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


Python bitstring.ConstBitStream方法代碼示例

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

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

示例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() 
開發者ID:AvaCity,項目名稱:avacity-2.0,代碼行數:36,代碼來源:client.py

示例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 
開發者ID:lightningd,項目名稱:plugins,代碼行數:9,代碼來源:zbase32.py

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

示例6: _get_file

# 需要導入模塊: import bitstring [as 別名]
# 或者: from bitstring import ConstBitStream [as 別名]
def _get_file():
        return ConstBitStream(filename=_Strings.filename) 
開發者ID:PeteAndersen,項目名稱:swarfarm,代碼行數:4,代碼來源:game_data.py

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

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

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

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

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

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

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

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

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


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