當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。