本文整理匯總了Python中binascii.b2a_hqx方法的典型用法代碼示例。如果您正苦於以下問題:Python binascii.b2a_hqx方法的具體用法?Python binascii.b2a_hqx怎麽用?Python binascii.b2a_hqx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類binascii
的用法示例。
在下文中一共展示了binascii.b2a_hqx方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_returned_value
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import b2a_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, 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, str)
self.assertIsInstance(a, str)
self.assertLess(max(ord(c) for c in a), 128)
示例2: test_returned_value
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import b2a_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)
示例3: write
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import b2a_hqx [as 別名]
def write(self, data):
self.data = self.data + data
datalen = len(self.data)
todo = (datalen//3)*3
data = self.data[:todo]
self.data = self.data[todo:]
if not data:
return
self.hqxdata = self.hqxdata + binascii.b2a_hqx(data)
self._flush(0)
示例4: close
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import b2a_hqx [as 別名]
def close(self):
if self.data:
self.hqxdata = \
self.hqxdata + binascii.b2a_hqx(self.data)
self._flush(1)
self.ofp.close()
del self.ofp
示例5: test_hqx
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import b2a_hqx [as 別名]
def test_hqx(self):
# Perform binhex4 style RLE-compression
# Then calculate the hexbin4 binary-to-ASCII translation
rle = binascii.rlecode_hqx(self.data)
a = binascii.b2a_hqx(self.type2test(rle))
b, _ = binascii.a2b_hqx(self.type2test(a))
res = binascii.rledecode_hqx(b)
self.assertEqual(res, self.rawdata)
示例6: test_not_implemented
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import b2a_hqx [as 別名]
def test_not_implemented(self):
test_cases = [
lambda: binascii.a2b_qp(None),
lambda: binascii.a2b_qp(None, None),
lambda: binascii.a2b_hqx(None),
lambda: binascii.rledecode_hqx(None),
lambda: binascii.rlecode_hqx(None),
lambda: binascii.b2a_hqx(None),
]
for temp_func in test_cases:
self.assertRaises(NotImplementedError, temp_func)
示例7: write
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import b2a_hqx [as 別名]
def write(self, data):
self.data = self.data + data
datalen = len(self.data)
todo = (datalen // 3) * 3
data = self.data[:todo]
self.data = self.data[todo:]
if not data:
return
self.hqxdata = self.hqxdata + binascii.b2a_hqx(data)
self._flush(0)
示例8: close
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import b2a_hqx [as 別名]
def close(self):
if self.data:
self.hqxdata = self.hqxdata + binascii.b2a_hqx(self.data)
self._flush(1)
self.ofp.close()
del self.ofp
示例9: test_unicode_a2b
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import b2a_hqx [as 別名]
def test_unicode_a2b(self):
# Unicode strings are accepted by a2b_* functions.
MAX_ALL = 45
raw = self.rawdata[:MAX_ALL]
for fa, fb in zip(a2b_functions, b2a_functions):
if fa == 'rledecode_hqx':
# Takes non-ASCII data
continue
a2b = getattr(binascii, fa)
b2a = getattr(binascii, fb)
try:
a = b2a(self.type2test(raw))
binary_res = a2b(a)
a = a.decode('ascii')
res = a2b(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
binary_res, _ = binary_res
self.assertEqual(res, raw, "{}/{} conversion: "
"{!r} != {!r}".format(fb, fa, res, raw))
self.assertEqual(res, binary_res)
self.assertIsInstance(res, bytes)
# non-ASCII string
self.assertRaises(ValueError, a2b, "\x80")