当前位置: 首页>>代码示例>>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;未经允许,请勿转载。