mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-30103: Allow Uuencode in Python using backtick as zero instead of space (#1326)
This commit is contained in:
parent
0360a9d015
commit
13f1f423fa
10 changed files with 137 additions and 67 deletions
|
@ -112,29 +112,41 @@ class BinASCIITest(unittest.TestCase):
|
|||
|
||||
def test_uu(self):
|
||||
MAX_UU = 45
|
||||
lines = []
|
||||
for i in range(0, len(self.data), MAX_UU):
|
||||
b = self.type2test(self.rawdata[i:i+MAX_UU])
|
||||
a = binascii.b2a_uu(b)
|
||||
lines.append(a)
|
||||
res = bytes()
|
||||
for line in lines:
|
||||
a = self.type2test(line)
|
||||
b = binascii.a2b_uu(a)
|
||||
res += b
|
||||
self.assertEqual(res, self.rawdata)
|
||||
for backtick in (True, False):
|
||||
lines = []
|
||||
for i in range(0, len(self.data), MAX_UU):
|
||||
b = self.type2test(self.rawdata[i:i+MAX_UU])
|
||||
a = binascii.b2a_uu(b, backtick=backtick)
|
||||
lines.append(a)
|
||||
res = bytes()
|
||||
for line in lines:
|
||||
a = self.type2test(line)
|
||||
b = binascii.a2b_uu(a)
|
||||
res += b
|
||||
self.assertEqual(res, self.rawdata)
|
||||
|
||||
self.assertEqual(binascii.a2b_uu(b"\x7f"), b"\x00"*31)
|
||||
self.assertEqual(binascii.a2b_uu(b"\x80"), b"\x00"*32)
|
||||
self.assertEqual(binascii.a2b_uu(b"\xff"), b"\x00"*31)
|
||||
self.assertRaises(binascii.Error, binascii.a2b_uu, b"\xff\x00")
|
||||
self.assertRaises(binascii.Error, binascii.a2b_uu, b"!!!!")
|
||||
|
||||
self.assertRaises(binascii.Error, binascii.b2a_uu, 46*b"!")
|
||||
|
||||
# Issue #7701 (crash on a pydebug build)
|
||||
self.assertEqual(binascii.b2a_uu(b'x'), b'!> \n')
|
||||
|
||||
self.assertEqual(binascii.b2a_uu(b''), b' \n')
|
||||
self.assertEqual(binascii.b2a_uu(b'', backtick=True), b'`\n')
|
||||
self.assertEqual(binascii.a2b_uu(b' \n'), b'')
|
||||
self.assertEqual(binascii.a2b_uu(b'`\n'), b'')
|
||||
self.assertEqual(binascii.b2a_uu(b'\x00Cat'), b'$ $-A= \n')
|
||||
self.assertEqual(binascii.b2a_uu(b'\x00Cat', backtick=True),
|
||||
b'$`$-A=```\n')
|
||||
self.assertEqual(binascii.a2b_uu(b'$`$-A=```\n'),
|
||||
binascii.a2b_uu(b'$ $-A= \n'))
|
||||
with self.assertRaises(TypeError):
|
||||
binascii.b2a_uu(b"", True)
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue