当前位置: 首页>>代码示例>>Python>>正文


Python binascii.crc_hqx方法代码示例

本文整理汇总了Python中binascii.crc_hqx方法的典型用法代码示例。如果您正苦于以下问题:Python binascii.crc_hqx方法的具体用法?Python binascii.crc_hqx怎么用?Python binascii.crc_hqx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在binascii的用法示例。


在下文中一共展示了binascii.crc_hqx方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: from_bytes

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def from_bytes(data: bytes) -> "Packet":

        if len(data) < 1 + 2 + 1 + 2:
            raise ValueError("packet too short")

        magic, _, payload, checksum = data[0], data[1:3], data[4:-2], data[-2:]

        if magic != ord(HUAWEI_LPV2_MAGIC):
            raise ValueError(f"magic mismatch: {magic} != {HUAWEI_LPV2_MAGIC}")

        actual_checksum = encode_int(binascii.crc_hqx(data[:-2], 0))

        if actual_checksum != checksum:
            raise ValueError(f"checksum mismatch: {actual_checksum} != {checksum}")

        return Packet(service_id=payload[0], command_id=payload[1], command=Command.from_bytes(payload[2:])) 
开发者ID:zyv,项目名称:huawei-lpv2,代码行数:18,代码来源:protocol.py

示例2: test_returned_value

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def test_returned_value(self):
        # Limit to the minimum of all limits (b2a_uu)
        MAX_ALL = 45
        raw = self.rawdata[:MAX_ALL]
        for fa, fb in zip(a2b_functions, b2a_functions):
            a2b = getattr(binascii, fa)
            b2a = getattr(binascii, fb)
            try:
                a = b2a(self.type2test(raw))
                res = a2b(self.type2test(a))
            except Exception as err:
                self.fail("{}/{} conversion raises {!r}".format(fb, fa, err))
            if fb == 'b2a_hqx':
                # b2a_hqx returns a tuple
                res, _ = res
            self.assertEqual(res, raw, "{}/{} conversion: "
                             "{!r} != {!r}".format(fb, fa, res, raw))
            self.assertIsInstance(res, bytes)
            self.assertIsInstance(a, bytes)
            self.assertLess(max(a), 128)
        self.assertIsInstance(binascii.crc_hqx(raw, 0), int)
        self.assertIsInstance(binascii.crc32(raw), int) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_binascii.py

示例3: crccalc

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def crccalc(command):
  """returns crc as integer from binary string command"""

  crc=binascii.crc_hqx(command,0)
  crchi=crc>>8
  crclo=crc&255

  if crchi == 0x28 or crchi==0x0d or crchi==0x0a:
    crc+=256

  if crclo == 0x28 or crclo==0x0d or crclo==0x0a:
    crc+=1
  return crc 
开发者ID:simat,项目名称:BatteryMonitor,代码行数:15,代码来源:piptest.py

示例4: crccalc

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def crccalc(self,command):
    """returns crc as integer from binary string command"""

    crc=binascii.crc_hqx(command,0)
    crchi=crc>>8
    crclo=crc&255

    if crchi == 0x28 or crchi==0x0d or crchi==0x0a:
      crc+=256

    if crclo == 0x28 or crclo==0x0d or crclo==0x0a:
      crc+=1
    return crc 
开发者ID:simat,项目名称:BatteryMonitor,代码行数:15,代码来源:pip.py

示例5: _write

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def _write(self, data):
        self.crc = binascii.crc_hqx(data, self.crc)
        self.ofp.write(data) 
开发者ID:glmcdona,项目名称:meddle,代码行数:5,代码来源:binhex.py

示例6: _writecrc

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def _writecrc(self):
        # XXXX Should this be here??
        # self.crc = binascii.crc_hqx('\0\0', self.crc)
        if self.crc < 0:
            fmt = '>h'
        else:
            fmt = '>H'
        self.ofp.write(struct.pack(fmt, self.crc))
        self.crc = 0 
开发者ID:glmcdona,项目名称:meddle,代码行数:11,代码来源:binhex.py

示例7: _read

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def _read(self, len):
        data = self.ifp.read(len)
        self.crc = binascii.crc_hqx(data, self.crc)
        return data 
开发者ID:glmcdona,项目名称:meddle,代码行数:6,代码来源:binhex.py

示例8: _checkcrc

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def _checkcrc(self):
        filecrc = struct.unpack('>h', self.ifp.read(2))[0] & 0xffff
        #self.crc = binascii.crc_hqx('\0\0', self.crc)
        # XXXX Is this needed??
        self.crc = self.crc & 0xffff
        if filecrc != self.crc:
            raise Error, 'CRC error, computed %x, read %x' \
                  %(self.crc, filecrc)
        self.crc = 0 
开发者ID:glmcdona,项目名称:meddle,代码行数:11,代码来源:binhex.py

示例9: __bytes__

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def __bytes__(self) -> bytes:
        payload = bytes([self.service_id, self.command_id]) + bytes(self.command)

        if len(payload) > 2 ** (8 * 2):
            raise ValueError(f"payload too large: {len(payload)}")

        data = HUAWEI_LPV2_MAGIC + encode_int(len(payload) + 1) + b"\0" + payload

        return data + encode_int(binascii.crc_hqx(data, 0)) 
开发者ID:zyv,项目名称:huawei-lpv2,代码行数:11,代码来源:protocol.py

示例10: test_crc_hqx

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def test_crc_hqx(self):
        crc = binascii.crc_hqx(self.type2test(b"Test the CRC-32 of"), 0)
        crc = binascii.crc_hqx(self.type2test(b" this string."), crc)
        self.assertEqual(crc, 14290)

        self.assertRaises(TypeError, binascii.crc_hqx)
        self.assertRaises(TypeError, binascii.crc_hqx, self.type2test(b'')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_binascii.py

示例11: __init__

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def __init__(self, filename):
        self.data = open(filename, 'rb').read()
        stored_crc16, size0, size1, size2 = struct.unpack('<HHHH', self.data[:8])
        calc_crc16 = binascii.crc_hqx(self.data[2:], 0xffff)
        if calc_crc16 != stored_crc16:
            raise ValueError("Unexpected CRC, found %04X but calculated %04X" % (stored_crc16, calc_crc16))
        self.sizes = (size0, size1, size2) 
开发者ID:scanlime,项目名称:fygimbal,代码行数:9,代码来源:fyflash.py

示例12: crc

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def crc(cls, framing, data):
        '''CRC-16 with an initial value that depends on the packet format'''
        return binascii.crc_hqx(data, cls.formats[framing]['initial_crc_value']) 
开发者ID:scanlime,项目名称:fygimbal,代码行数:5,代码来源:fyproto.py

示例13: test_empty_string

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import crc_hqx [as 别名]
def test_empty_string(self):
        # A test for SF bug #1022953.  Make sure SystemError is not raised.
        empty = self.type2test('')
        for func in all_functions:
            if func == 'crc_hqx':
                # crc_hqx needs 2 arguments
                binascii.crc_hqx(empty, 0)
                continue
            f = getattr(binascii, func)
            try:
                f(empty)
            except Exception, err:
                self.fail("{}({!r}) raises {!r}".format(func, empty, err)) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:15,代码来源:test_binascii.py


注:本文中的binascii.crc_hqx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。