Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r48238:e2959749a482
Date: 2011-10-19 22:31 +0200
http://bitbucket.org/pypy/pypy/changeset/e2959749a482/
Log: Fix the binascii module
diff --git a/pypy/module/binascii/interp_base64.py
b/pypy/module/binascii/interp_base64.py
--- a/pypy/module/binascii/interp_base64.py
+++ b/pypy/module/binascii/interp_base64.py
@@ -71,7 +71,7 @@
if leftbits != 0:
raise_Error(space, "Incorrect padding")
- return space.wrap(res.build())
+ return space.wrapbytes(res.build())
# ____________________________________________________________
@@ -110,4 +110,4 @@
res.append(table_b2a_base64[(leftchar & 0xf) << 2])
res.append(PAD)
res.append('\n')
- return space.wrap(res.build())
+ return space.wrapbytes(res.build())
diff --git a/pypy/module/binascii/interp_hexlify.py
b/pypy/module/binascii/interp_hexlify.py
--- a/pypy/module/binascii/interp_hexlify.py
+++ b/pypy/module/binascii/interp_hexlify.py
@@ -24,7 +24,7 @@
for c in data:
res.append(_value2char(ord(c) >> 4))
res.append(_value2char(ord(c) & 0xf))
- return space.wrap(res.build())
+ return space.wrapbytes(res.build())
# ____________________________________________________________
@@ -55,4 +55,4 @@
a = _char2value(space, hexstr[i])
b = _char2value(space, hexstr[i+1])
res.append(chr((a << 4) | b))
- return space.wrap(res.build())
+ return space.wrapbytes(res.build())
diff --git a/pypy/module/binascii/interp_hqx.py
b/pypy/module/binascii/interp_hqx.py
--- a/pypy/module/binascii/interp_hqx.py
+++ b/pypy/module/binascii/interp_hqx.py
@@ -97,7 +97,7 @@
else:
if pending_bits > 0:
raise_Incomplete(space, 'String has incomplete number of bytes')
- return space.newtuple([space.wrap(res.build()), space.wrap(done)])
+ return space.newtuple([space.wrapbytes(res.build()), space.wrap(done)])
# ____________________________________________________________
@@ -128,7 +128,7 @@
if leftbits > 0:
leftchar <<= (6 - leftbits)
res.append(hqx_encoding[leftchar & 0x3f])
- return space.wrap(res.build())
+ return space.wrapbytes(res.build())
# ____________________________________________________________
@@ -150,7 +150,7 @@
lastpushed = ord(c)
else:
if i == end:
- raise_Incomplete(space, 'String ends with the RLE code \x90')
+ raise_Incomplete(space, 'String ends with the RLE code \\x90')
count = ord(hexbin[i]) - 1
i += 1
if count < 0:
@@ -158,9 +158,9 @@
lastpushed = 0x90
else:
if lastpushed < 0:
- raise_Error(space, 'String starts with the RLE code \x90')
+ raise_Error(space, 'String starts with the RLE code \\x90')
res.append_multiple_char(chr(lastpushed), count)
- return space.wrap(res.build())
+ return space.wrapbytes(res.build())
# ____________________________________________________________
@@ -197,7 +197,7 @@
# string that rledecode_hqx() would expand back to 'data', there are
# some programs somewhere that would start failing obscurely in rare
# cases.
- return space.wrap(res.build())
+ return space.wrapbytes(res.build())
# ____________________________________________________________
diff --git a/pypy/module/binascii/interp_qp.py
b/pypy/module/binascii/interp_qp.py
--- a/pypy/module/binascii/interp_qp.py
+++ b/pypy/module/binascii/interp_qp.py
@@ -56,7 +56,7 @@
if header and c == '_':
c = ' '
odata.append(c)
- return space.wrap(odata.build())
+ return space.wrapbytes(odata.build())
# ____________________________________________________________
@@ -159,4 +159,4 @@
odata.append(c)
inp += 1
- return space.wrap(odata.build())
+ return space.wrapbytes(odata.build())
diff --git a/pypy/module/binascii/interp_uu.py
b/pypy/module/binascii/interp_uu.py
--- a/pypy/module/binascii/interp_uu.py
+++ b/pypy/module/binascii/interp_uu.py
@@ -52,7 +52,7 @@
remaining = length - res.getlength()
if remaining > 0:
res.append_multiple_char('\x00', remaining)
- return space.wrap(res.build())
+ return space.wrapbytes(res.build())
# ____________________________________________________________
@@ -84,4 +84,4 @@
res.append(chr(0x20 + (C & 0x3F)))
res.append('\n')
- return space.wrap(res.build())
+ return space.wrapbytes(res.build())
diff --git a/pypy/module/binascii/test/test_binascii.py
b/pypy/module/binascii/test/test_binascii.py
--- a/pypy/module/binascii/test/test_binascii.py
+++ b/pypy/module/binascii/test/test_binascii.py
@@ -16,405 +16,405 @@
def test_a2b_uu(self):
# obscure case, for compability with CPython
- assert self.binascii.a2b_uu("") == "\x00" * 0x20
+ assert self.binascii.a2b_uu(b"") == b"\x00" * 0x20
#
for input, expected in [
- (" ", ""),
- ("!", "\x00"),
- ("!6", "X"),
- ('"6', "X\x00"),
- ('"W', "\xdc\x00"),
- ('"WA', "\xde\x10"),
- ('"WAX', "\xde\x1e"),
- ('#WAX', "\xde\x1e\x00"),
- ('#WAXR', "\xde\x1e2"),
- ('$WAXR', "\xde\x1e2\x00"),
- ('$WAXR6', "\xde\x1e2X"),
- ('%WAXR6U', "\xde\x1e2[P"),
- ('&WAXR6UB', "\xde\x1e2[X\x80"),
- ("'WAXR6UBA3", "\xde\x1e2[X\xa1L"),
- ('(WAXR6UBA3#', "\xde\x1e2[X\xa1L0"),
- (')WAXR6UBA3#Q', "\xde\x1e2[X\xa1L<@"),
- ('*WAXR6UBA3#Q!5', "\xde\x1e2[X\xa1L<AT"),
+ (b" ", b""),
+ (b"!", b"\x00"),
+ (b"!6", b"X"),
+ (b'"6', b"X\x00"),
+ (b'"W', b"\xdc\x00"),
+ (b'"WA', b"\xde\x10"),
+ (b'"WAX', b"\xde\x1e"),
+ (b'#WAX', b"\xde\x1e\x00"),
+ (b'#WAXR', b"\xde\x1e2"),
+ (b'$WAXR', b"\xde\x1e2\x00"),
+ (b'$WAXR6', b"\xde\x1e2X"),
+ (b'%WAXR6U', b"\xde\x1e2[P"),
+ (b'&WAXR6UB', b"\xde\x1e2[X\x80"),
+ (b"'WAXR6UBA3", b"\xde\x1e2[X\xa1L"),
+ (b'(WAXR6UBA3#', b"\xde\x1e2[X\xa1L0"),
+ (b')WAXR6UBA3#Q', b"\xde\x1e2[X\xa1L<@"),
+ (b'*WAXR6UBA3#Q!5', b"\xde\x1e2[X\xa1L<AT"),
]:
assert self.binascii.a2b_uu(input) == expected
- assert self.binascii.a2b_uu(input + ' ') == expected
- assert self.binascii.a2b_uu(input + ' ') == expected
- assert self.binascii.a2b_uu(input + ' ') == expected
- assert self.binascii.a2b_uu(input + ' ') == expected
- assert self.binascii.a2b_uu(input + '\n') == expected
- assert self.binascii.a2b_uu(input + '\r\n') == expected
- assert self.binascii.a2b_uu(input + ' \r\n') == expected
- assert self.binascii.a2b_uu(input + ' \r\n') == expected
+ assert self.binascii.a2b_uu(input + b' ') == expected
+ assert self.binascii.a2b_uu(input + b' ') == expected
+ assert self.binascii.a2b_uu(input + b' ') == expected
+ assert self.binascii.a2b_uu(input + b' ') == expected
+ assert self.binascii.a2b_uu(input + b'\n') == expected
+ assert self.binascii.a2b_uu(input + b'\r\n') == expected
+ assert self.binascii.a2b_uu(input + b' \r\n') == expected
+ assert self.binascii.a2b_uu(input + b' \r\n') == expected
#
for bogus in [
- "!w",
- "! w",
- "! w",
- "! w",
- "! w",
- "! w",
- "! w",
- "#a",
- '"WAXR',
+ b"!w",
+ b"! w",
+ b"! w",
+ b"! w",
+ b"! w",
+ b"! w",
+ b"! w",
+ b"#a",
+ b'"WAXR',
]:
raises(self.binascii.Error, self.binascii.a2b_uu, bogus)
- raises(self.binascii.Error, self.binascii.a2b_uu, bogus + ' ')
- raises(self.binascii.Error, self.binascii.a2b_uu, bogus + ' ')
- raises(self.binascii.Error, self.binascii.a2b_uu, bogus + ' ')
- raises(self.binascii.Error, self.binascii.a2b_uu, bogus + ' ')
- raises(self.binascii.Error, self.binascii.a2b_uu, bogus + '\n')
- raises(self.binascii.Error, self.binascii.a2b_uu, bogus + '\r\n')
- raises(self.binascii.Error, self.binascii.a2b_uu, bogus + ' \r\n')
+ raises(self.binascii.Error, self.binascii.a2b_uu, bogus + b' ')
+ raises(self.binascii.Error, self.binascii.a2b_uu, bogus + b' ')
+ raises(self.binascii.Error, self.binascii.a2b_uu, bogus + b' ')
+ raises(self.binascii.Error, self.binascii.a2b_uu, bogus + b' ')
+ raises(self.binascii.Error, self.binascii.a2b_uu, bogus + b'\n')
+ raises(self.binascii.Error, self.binascii.a2b_uu, bogus + b'\r\n')
+ raises(self.binascii.Error, self.binascii.a2b_uu, bogus + b'
\r\n')
def test_b2a_uu(self):
for input, expected in [
- ("", " "),
- ("\x00", "! "),
- ("X", "!6 "),
- ("X\x00", '"6 '),
- ("\xdc\x00", '"W '),
- ("\xde\x10", '"WA '),
- ("\xde\x1e", '"WAX '),
- ("\xde\x1e\x00", '#WAX '),
- ("\xde\x1e2", '#WAXR'),
- ("\xde\x1e2\x00", '$WAXR '),
- ("\xde\x1e2X", '$WAXR6 '),
- ("\xde\x1e2[P", '%WAXR6U '),
- ("\xde\x1e2[X\x80", '&WAXR6UB '),
- ("\xde\x1e2[X\xa1L", "'WAXR6UBA3 "),
- ("\xde\x1e2[X\xa1L0", '(WAXR6UBA3# '),
- ("\xde\x1e2[X\xa1L<@", ')WAXR6UBA3#Q '),
- ("\xde\x1e2[X\xa1L<AT", '*WAXR6UBA3#Q!5 '),
+ (b"", b" "),
+ (b"\x00", b"! "),
+ (b"X", b"!6 "),
+ (b"X\x00", b'"6 '),
+ (b"\xdc\x00", b'"W '),
+ (b"\xde\x10", b'"WA '),
+ (b"\xde\x1e", b'"WAX '),
+ (b"\xde\x1e\x00", b'#WAX '),
+ (b"\xde\x1e2", b'#WAXR'),
+ (b"\xde\x1e2\x00", b'$WAXR '),
+ (b"\xde\x1e2X", b'$WAXR6 '),
+ (b"\xde\x1e2[P", b'%WAXR6U '),
+ (b"\xde\x1e2[X\x80", b'&WAXR6UB '),
+ (b"\xde\x1e2[X\xa1L", b"'WAXR6UBA3 "),
+ (b"\xde\x1e2[X\xa1L0", b'(WAXR6UBA3# '),
+ (b"\xde\x1e2[X\xa1L<@", b')WAXR6UBA3#Q '),
+ (b"\xde\x1e2[X\xa1L<AT", b'*WAXR6UBA3#Q!5 '),
]:
- assert self.binascii.b2a_uu(input) == expected + '\n'
+ assert self.binascii.b2a_uu(input) == expected + b'\n'
def test_a2b_base64(self):
for input, expected in [
- ("", ""),
- ("\n", ""),
- ("Yg==\n", "b"),
- ("Y g = \n = \r", "b"), # random spaces
- ("Y\x80g\xff=\xc4=", "b"), # random junk chars, >= 0x80
- ("abcd", "i\xb7\x1d"),
- ("abcdef==", "i\xb7\x1dy"),
- ("abcdefg=", "i\xb7\x1dy\xf8"),
- ("abcdefgh", "i\xb7\x1dy\xf8!"),
- ("abcdef==FINISHED", "i\xb7\x1dy"),
- ("abcdef= \n =FINISHED", "i\xb7\x1dy"),
- ("abcdefg=FINISHED", "i\xb7\x1dy\xf8"),
- ("abcd=efgh", "i\xb7\x1dy\xf8!"),
- ("abcde=fgh", "i\xb7\x1dy\xf8!"),
- ("abcdef=gh", "i\xb7\x1dy\xf8!"),
+ (b"", b""),
+ (b"\n", b""),
+ (b"Yg==\n", b"b"),
+ (b"Y g = \n = \r", b"b"), # random spaces
+ (b"Y\x80g\xff=\xc4=", b"b"), # random junk chars, >= 0x80
+ (b"abcd", b"i\xb7\x1d"),
+ (b"abcdef==", b"i\xb7\x1dy"),
+ (b"abcdefg=", b"i\xb7\x1dy\xf8"),
+ (b"abcdefgh", b"i\xb7\x1dy\xf8!"),
+ (b"abcdef==FINISHED", b"i\xb7\x1dy"),
+ (b"abcdef= \n =FINISHED", b"i\xb7\x1dy"),
+ (b"abcdefg=FINISHED", b"i\xb7\x1dy\xf8"),
+ (b"abcd=efgh", b"i\xb7\x1dy\xf8!"),
+ (b"abcde=fgh", b"i\xb7\x1dy\xf8!"),
+ (b"abcdef=gh", b"i\xb7\x1dy\xf8!"),
]:
assert self.binascii.a2b_base64(input) == expected
#
for bogus in [
- "abcde",
- "abcde=",
- "abcde==",
- "abcde===",
- "abcdef",
- "abcdef=",
- "abcdefg",
+ b"abcde",
+ b"abcde=",
+ b"abcde==",
+ b"abcde===",
+ b"abcdef",
+ b"abcdef=",
+ b"abcdefg",
]:
raises(self.binascii.Error, self.binascii.a2b_base64, bogus)
def test_b2a_base64(self):
for input, expected in [
- ("", ""),
- ("b", "Yg=="),
- ("i\xb7\x1d", "abcd"),
- ("i\xb7\x1dy", "abcdeQ=="),
- ("i\xb7\x1dy\xf8", "abcdefg="),
- ("i\xb7\x1dy\xf8!", "abcdefgh"),
- ("i\xb7\x1d" * 345, "abcd" * 345),
+ (b"", b""),
+ (b"b", b"Yg=="),
+ (b"i\xb7\x1d", b"abcd"),
+ (b"i\xb7\x1dy", b"abcdeQ=="),
+ (b"i\xb7\x1dy\xf8", b"abcdefg="),
+ (b"i\xb7\x1dy\xf8!", b"abcdefgh"),
+ (b"i\xb7\x1d" * 345, b"abcd" * 345),
]:
- assert self.binascii.b2a_base64(input) == expected + '\n'
+ assert self.binascii.b2a_base64(input) == expected + b'\n'
def test_a2b_qp(self):
for input, expected in [
# these are the tests from CPython 2.7
- ("= ", "= "),
- ("==", "="),
- ("=AX", "=AX"),
- ("=00\r\n=00", "\x00\r\n\x00"),
+ (b"= ", b"= "),
+ (b"==", b"="),
+ (b"=AX", b"=AX"),
+ (b"=00\r\n=00", b"\x00\r\n\x00"),
# more tests follow
- ("=", ""),
- ("abc=", "abc"),
- ("ab=\ncd", "abcd"),
- ("ab=\r\ncd", "abcd"),
- (''.join(["=%02x" % n for n in range(256)]),
- ''.join(map(chr, range(256)))),
- (''.join(["=%02X" % n for n in range(256)]),
- ''.join(map(chr, range(256)))),
+ (b"=", b""),
+ (b"abc=", b"abc"),
+ (b"ab=\ncd", b"abcd"),
+ (b"ab=\r\ncd", b"abcd"),
+ (''.join(["=%02x" % n for n in range(256)]).encode(),
+ bytes(range(256))),
+ (''.join(["=%02X" % n for n in range(256)]).encode(),
+ bytes(range(256))),
]:
assert self.binascii.a2b_qp(input) == expected
#
for input, expected in [
- ("xyz", "xyz"),
- ("__", " "),
- ("a_b", "a b"),
+ (b"xyz", b"xyz"),
+ (b"__", b" "),
+ (b"a_b", b"a b"),
]:
assert self.binascii.a2b_qp(input, header=True) == expected
def test_b2a_qp(self):
for input, flags, expected in [
# these are the tests from CPython 2.7
- ("\xff\r\n\xff\n\xff", {}, "=FF\r\n=FF\r\n=FF"),
- ("0"*75+"\xff\r\n\xff\r\n\xff",{},"0"*75+"=\r\n=FF\r\n=FF\r\n=FF"),
- ('\0\n', {}, '=00\n'),
- ('\0\n', {'quotetabs': True}, '=00\n'),
- ('foo\tbar\t\n', {}, 'foo\tbar=09\n'),
- ('foo\tbar\t\n', {'quotetabs': True}, 'foo=09bar=09\n'),
- ('.', {}, '=2E'),
- ('.\n', {}, '=2E\n'),
- ('a.\n', {}, 'a.\n'),
+ (b"\xff\r\n\xff\n\xff", {}, b"=FF\r\n=FF\r\n=FF"),
+
(b"0"*75+b"\xff\r\n\xff\r\n\xff",{},b"0"*75+b"=\r\n=FF\r\n=FF\r\n=FF"),
+ (b'\0\n', {}, b'=00\n'),
+ (b'\0\n', {'quotetabs': True}, b'=00\n'),
+ (b'foo\tbar\t\n', {}, b'foo\tbar=09\n'),
+ (b'foo\tbar\t\n', {'quotetabs': True}, b'foo=09bar=09\n'),
+ (b'.', {}, b'=2E'),
+ (b'.\n', {}, b'=2E\n'),
+ (b'a.\n', {}, b'a.\n'),
# more tests follow
- ('_', {}, '_'),
- ('_', {'header': True}, '=5F'),
- ('.x', {}, '.x'),
- ('.\r\nn', {}, '=2E\r\nn'),
- ('\nn', {}, '\nn'),
- ('\r\nn', {}, '\r\nn'),
- ('\nn', {'istext': False}, '=0An'),
- ('\r\nn', {'istext': False}, '=0D=0An'),
- (' ', {}, '=20'),
- ('\t', {}, '=09'),
- (' x', {}, ' x'),
- ('\tx', {}, '\tx'),
- ('\x16x', {}, '=16x'),
- (' x', {'quotetabs': True}, '=20x'),
- ('\tx', {'quotetabs': True}, '=09x'),
- (' \nn', {}, '=20\nn'),
- ('\t\nn', {}, '=09\nn'),
- ('x\nn', {}, 'x\nn'),
- (' \r\nn', {}, '=20\r\nn'),
- ('\t\r\nn', {}, '=09\r\nn'),
- ('x\r\nn', {}, 'x\r\nn'),
- ('x\nn', {'istext': False}, 'x=0An'),
- (' ', {}, ' =20'),
- (' ', {'header': True}, '__=20'),
- (' \nn', {}, ' =20\nn'),
- (' \nn', {'header': True}, '___\nn'),
- (' ', {}, ' =20'),
- ('\t\t\t', {'header': True}, '\t\t=09'),
- ('\t\t\t\nn', {}, '\t\t=09\nn'),
- ('\t\t\t\nn', {'header': True}, '\t\t=09\nn'),
+ (b'_', {}, b'_'),
+ (b'_', {'header': True}, b'=5F'),
+ (b'.x', {}, b'.x'),
+ (b'.\r\nn', {}, b'=2E\r\nn'),
+ (b'\nn', {}, b'\nn'),
+ (b'\r\nn', {}, b'\r\nn'),
+ (b'\nn', {'istext': False}, b'=0An'),
+ (b'\r\nn', {'istext': False}, b'=0D=0An'),
+ (b' ', {}, b'=20'),
+ (b'\t', {}, b'=09'),
+ (b' x', {}, b' x'),
+ (b'\tx', {}, b'\tx'),
+ (b'\x16x', {}, b'=16x'),
+ (b' x', {'quotetabs': True}, b'=20x'),
+ (b'\tx', {'quotetabs': True}, b'=09x'),
+ (b' \nn', {}, b'=20\nn'),
+ (b'\t\nn', {}, b'=09\nn'),
+ (b'x\nn', {}, b'x\nn'),
+ (b' \r\nn', {}, b'=20\r\nn'),
+ (b'\t\r\nn', {}, b'=09\r\nn'),
+ (b'x\r\nn', {}, b'x\r\nn'),
+ (b'x\nn', {'istext': False}, b'x=0An'),
+ (b' ', {}, b' =20'),
+ (b' ', {'header': True}, b'__=20'),
+ (b' \nn', {}, b' =20\nn'),
+ (b' \nn', {'header': True}, b'___\nn'),
+ (b' ', {}, b' =20'),
+ (b'\t\t\t', {'header': True}, b'\t\t=09'),
+ (b'\t\t\t\nn', {}, b'\t\t=09\nn'),
+ (b'\t\t\t\nn', {'header': True}, b'\t\t=09\nn'),
]:
assert self.binascii.b2a_qp(input, **flags) == expected
def test_a2b_hqx(self):
for input, expected, done in [
- ("", "", 0),
- ("AAAA", "]u\xd7", 0),
- ("A\nA\rAA", "]u\xd7", 0),
- (":", "", 1),
- ("A:", "", 1),
- ("AA:", "]", 1),
- ("AAA:", "]u", 1),
- ("AAAA:", "]u\xd7", 1),
- ("AAAA:foobarbaz", "]u\xd7", 1),
- ("41-CZ:", "D\xe3\x19", 1),
- ("41-CZl:", "D\xe3\x19\xbb", 1),
- ("41-CZlm:", "D\xe3\x19\xbb\xbf", 1),
- ("41-CZlm@:", "D\xe3\x19\xbb\xbf\x16", 1),
+ (b"", b"", 0),
+ (b"AAAA", b"]u\xd7", 0),
+ (b"A\nA\rAA", b"]u\xd7", 0),
+ (b":", b"", 1),
+ (b"A:", b"", 1),
+ (b"AA:", b"]", 1),
+ (b"AAA:", b"]u", 1),
+ (b"AAAA:", b"]u\xd7", 1),
+ (b"AAAA:foobarbaz", b"]u\xd7", 1),
+ (b"41-CZ:", b"D\xe3\x19", 1),
+ (b"41-CZl:", b"D\xe3\x19\xbb", 1),
+ (b"41-CZlm:", b"D\xe3\x19\xbb\xbf", 1),
+ (b"41-CZlm@:", b"D\xe3\x19\xbb\xbf\x16", 1),
]:
assert self.binascii.a2b_hqx(input) == (expected, done)
#
for incomplete in [
- "A",
- "AA",
- "AAA",
- "12345",
- "123456",
- "1234560",
+ b"A",
+ b"AA",
+ b"AAA",
+ b"12345",
+ b"123456",
+ b"1234560",
]:
raises(self.binascii.Incomplete, self.binascii.a2b_hqx, incomplete)
#
for bogus in [
- "\x00",
- ".",
- "AAA AAAAAA:",
+ b"\x00",
+ b".",
+ b"AAA AAAAAA:",
]:
raises(self.binascii.Error, self.binascii.a2b_hqx, bogus)
def test_b2a_hqx(self):
for input, expected in [
- ("", ""),
- ("A", "33"),
- ("AB", "38)"),
- ("ABC", "38*$"),
- ("ABCD", "38*$4!"),
- ("ABCDE", "38*$4%8"),
- ("ABCDEF", "38*$4%9'"),
- ("ABCDEFG", "38*$4%9'4`"),
- ("]u\xd7", "AAAA"),
+ (b"", b""),
+ (b"A", b"33"),
+ (b"AB", b"38)"),
+ (b"ABC", b"38*$"),
+ (b"ABCD", b"38*$4!"),
+ (b"ABCDE", b"38*$4%8"),
+ (b"ABCDEF", b"38*$4%9'"),
+ (b"ABCDEFG", b"38*$4%9'4`"),
+ (b"]u\xd7", b"AAAA"),
]:
assert self.binascii.b2a_hqx(input) == expected
def test_rledecode_hqx(self):
for input, expected in [
- ("", ""),
- ("hello world", "hello world"),
- ("\x90\x00", "\x90"),
- ("a\x90\x05", "a" * 5),
- ("a\x90\xff", "a" * 0xFF),
- ("abc\x90\x01def", "abcdef"),
- ("abc\x90\x02def", "abccdef"),
- ("abc\x90\x03def", "abcccdef"),
- ("abc\x90\xa1def", "ab" + "c" * 0xA1 + "def"),
- ("abc\x90\x03\x90\x02def", "abccccdef"),
- ("abc\x90\x00\x90\x03def", "abc\x90\x90\x90def"),
- ("abc\x90\x03\x90\x00def", "abccc\x90def"),
+ (b"", b""),
+ (b"hello world", b"hello world"),
+ (b"\x90\x00", b"\x90"),
+ (b"a\x90\x05", b"a" * 5),
+ (b"a\x90\xff", b"a" * 0xFF),
+ (b"abc\x90\x01def", b"abcdef"),
+ (b"abc\x90\x02def", b"abccdef"),
+ (b"abc\x90\x03def", b"abcccdef"),
+ (b"abc\x90\xa1def", b"ab" + b"c" * 0xA1 + b"def"),
+ (b"abc\x90\x03\x90\x02def", b"abccccdef"),
+ (b"abc\x90\x00\x90\x03def", b"abc\x90\x90\x90def"),
+ (b"abc\x90\x03\x90\x00def", b"abccc\x90def"),
]:
assert self.binascii.rledecode_hqx(input) == expected
#
for input in [
- "\x90",
- "a\x90",
- "hello world\x90",
+ b"\x90",
+ b"a\x90",
+ b"hello world\x90",
]:
raises(self.binascii.Incomplete, self.binascii.rledecode_hqx,
input)
#
- raises(self.binascii.Error, self.binascii.rledecode_hqx, "\x90\x01")
- raises(self.binascii.Error, self.binascii.rledecode_hqx, "\x90\x02")
- raises(self.binascii.Error, self.binascii.rledecode_hqx, "\x90\xff")
+ raises(self.binascii.Error, self.binascii.rledecode_hqx, b"\x90\x01")
+ raises(self.binascii.Error, self.binascii.rledecode_hqx, b"\x90\x02")
+ raises(self.binascii.Error, self.binascii.rledecode_hqx, b"\x90\xff")
def test_rlecode_hqx(self):
for input, expected in [
- ("", ""),
- ("hello world", "hello world"),
- ("helllo world", "helllo world"),
- ("hellllo world", "hel\x90\x04o world"),
- ("helllllo world", "hel\x90\x05o world"),
- ("aaa", "aaa"),
- ("aaaa", "a\x90\x04"),
- ("a" * 0xff, "a\x90\xff"),
- ("a" * 0x100, "a\x90\xffa"),
- ("a" * 0x101, "a\x90\xffaa"),
- ("a" * 0x102, "a\x90\xffaaa"), # see comments in the source
- ("a" * 0x103, "a\x90\xffa\x90\x04"),
- ("a" * 0x1fe, "a\x90\xffa\x90\xff"),
- ("a" * 0x1ff, "a\x90\xffa\x90\xffa"),
- ("\x90", "\x90\x00"),
- ("\x90" * 2, "\x90\x00" * 2),
- ("\x90" * 3, "\x90\x00" * 3), # see comments in the source
- ("\x90" * 345, "\x90\x00" * 345),
+ (b"", b""),
+ (b"hello world", b"hello world"),
+ (b"helllo world", b"helllo world"),
+ (b"hellllo world", b"hel\x90\x04o world"),
+ (b"helllllo world", b"hel\x90\x05o world"),
+ (b"aaa", b"aaa"),
+ (b"aaaa", b"a\x90\x04"),
+ (b"a" * 0xff, b"a\x90\xff"),
+ (b"a" * 0x100, b"a\x90\xffa"),
+ (b"a" * 0x101, b"a\x90\xffaa"),
+ (b"a" * 0x102, b"a\x90\xffaaa"), # see comments in the source
+ (b"a" * 0x103, b"a\x90\xffa\x90\x04"),
+ (b"a" * 0x1fe, b"a\x90\xffa\x90\xff"),
+ (b"a" * 0x1ff, b"a\x90\xffa\x90\xffa"),
+ (b"\x90", b"\x90\x00"),
+ (b"\x90" * 2, b"\x90\x00" * 2),
+ (b"\x90" * 3, b"\x90\x00" * 3), # see comments in the source
+ (b"\x90" * 345, b"\x90\x00" * 345),
]:
assert self.binascii.rlecode_hqx(input) == expected
def test_crc_hqx(self):
for input, initial, expected in [
- ("", 0, 0),
- ("", 123, 123),
- ("hello", 321, 28955),
- ("world", 65535, 12911),
- ("uh", 40102, 37544),
- ('a', 10000, 14338),
- ('b', 10000, 2145),
- ('c', 10000, 6208),
- ('d', 10000, 26791),
- ('e', 10000, 30854),
- ('f', 10000, 18661),
- ('g', 10000, 22724),
- ('h', 10000, 43307),
- ('i', 10000, 47370),
- ('j', 10000, 35177),
- ('k', 10000, 39240),
- ('l', 10000, 59823),
- ('m', 10000, 63886),
- ('n', 10000, 51693),
- ('o', 10000, 55756),
- ('p', 10000, 14866),
- ('q', 10000, 10803),
- ('r', 10000, 6736),
- ('s', 10000, 2673),
- ('t', 10000, 31382),
- ('u', 10000, 27319),
- ('v', 10000, 23252),
- ('w', 10000, 19189),
- ('x', 10000, 47898),
- ('y', 10000, 43835),
- ('z', 10000, 39768),
+ (b"", 0, 0),
+ (b"", 123, 123),
+ (b"hello", 321, 28955),
+ (b"world", 65535, 12911),
+ (b"uh", 40102, 37544),
+ (b'a', 10000, 14338),
+ (b'b', 10000, 2145),
+ (b'c', 10000, 6208),
+ (b'd', 10000, 26791),
+ (b'e', 10000, 30854),
+ (b'f', 10000, 18661),
+ (b'g', 10000, 22724),
+ (b'h', 10000, 43307),
+ (b'i', 10000, 47370),
+ (b'j', 10000, 35177),
+ (b'k', 10000, 39240),
+ (b'l', 10000, 59823),
+ (b'm', 10000, 63886),
+ (b'n', 10000, 51693),
+ (b'o', 10000, 55756),
+ (b'p', 10000, 14866),
+ (b'q', 10000, 10803),
+ (b'r', 10000, 6736),
+ (b's', 10000, 2673),
+ (b't', 10000, 31382),
+ (b'u', 10000, 27319),
+ (b'v', 10000, 23252),
+ (b'w', 10000, 19189),
+ (b'x', 10000, 47898),
+ (b'y', 10000, 43835),
+ (b'z', 10000, 39768),
]:
assert self.binascii.crc_hqx(input, initial) == expected
def test_crc32(self):
for input, initial, expected in [
- ("", 0, 0),
- ("", 123, 123),
- ("hello", 321, -348147686),
- ("world", -2147483648, 32803080),
- ("world", 2147483647, 942244330),
- ('a', 10000, -184504832),
- ('b', 10000, 1812594618),
- ('c', 10000, 453955372),
- ('d', 10000, -2056627569),
- ('e', 10000, -227710439),
- ('f', 10000, 1801730979),
- ('g', 10000, 476252981),
- ('h', 10000, -1931733340),
- ('i', 10000, -69523918),
- ('j', 10000, 1657960328),
- ('k', 10000, 366298910),
- ('l', 10000, -1951280451),
- ('m', 10000, -55123413),
- ('n', 10000, 1707062161),
- ('o', 10000, 314082055),
- ('p', 10000, -1615819022),
- ('q', 10000, -390611356),
- ('r', 10000, 1908338654),
- ('s', 10000, 112844616),
- ('t', 10000, -1730327829),
- ('u', 10000, -270894467),
- ('v', 10000, 1993550791),
- ('w', 10000, 30677841),
- ('x', 10000, -1855256896),
- ('y', 10000, -429115818),
- ('z', 10000, 2137352172),
- ('foo', 99999999999999999999999999, -1932704816),
- ('bar', -99999999999999999999999999, 2000545409),
+ (b"", 0, 0),
+ (b"", 123, 123),
+ (b"hello", 321, -348147686),
+ (b"world", -2147483648, 32803080),
+ (b"world", 2147483647, 942244330),
+ (b'a', 10000, -184504832),
+ (b'b', 10000, 1812594618),
+ (b'c', 10000, 453955372),
+ (b'd', 10000, -2056627569),
+ (b'e', 10000, -227710439),
+ (b'f', 10000, 1801730979),
+ (b'g', 10000, 476252981),
+ (b'h', 10000, -1931733340),
+ (b'i', 10000, -69523918),
+ (b'j', 10000, 1657960328),
+ (b'k', 10000, 366298910),
+ (b'l', 10000, -1951280451),
+ (b'm', 10000, -55123413),
+ (b'n', 10000, 1707062161),
+ (b'o', 10000, 314082055),
+ (b'p', 10000, -1615819022),
+ (b'q', 10000, -390611356),
+ (b'r', 10000, 1908338654),
+ (b's', 10000, 112844616),
+ (b't', 10000, -1730327829),
+ (b'u', 10000, -270894467),
+ (b'v', 10000, 1993550791),
+ (b'w', 10000, 30677841),
+ (b'x', 10000, -1855256896),
+ (b'y', 10000, -429115818),
+ (b'z', 10000, 2137352172),
+ (b'foo', 99999999999999999999999999, -1932704816),
+ (b'bar', -99999999999999999999999999, 2000545409),
]:
assert self.binascii.crc32(input, initial) == expected
def test_hexlify(self):
for input, expected in [
- ("", ""),
- ("0", "30"),
- ("1", "31"),
- ("2", "32"),
- ("8", "38"),
- ("9", "39"),
- ("A", "41"),
- ("O", "4f"),
- ("\xde", "de"),
- ("ABC", "414243"),
- ("\x00\x00\x00\xff\x00\x00", "000000ff0000"),
- ("\x28\x9c\xc8\xc0\x3d\x8e", "289cc8c03d8e"),
+ (b"", b""),
+ (b"0", b"30"),
+ (b"1", b"31"),
+ (b"2", b"32"),
+ (b"8", b"38"),
+ (b"9", b"39"),
+ (b"A", b"41"),
+ (b"O", b"4f"),
+ (b"\xde", b"de"),
+ (b"ABC", b"414243"),
+ (b"\x00\x00\x00\xff\x00\x00", b"000000ff0000"),
+ (b"\x28\x9c\xc8\xc0\x3d\x8e", b"289cc8c03d8e"),
]:
assert self.binascii.hexlify(input) == expected
assert self.binascii.b2a_hex(input) == expected
def test_unhexlify(self):
for input, expected in [
- ("", ""),
- ("30", "0"),
- ("31", "1"),
- ("32", "2"),
- ("38", "8"),
- ("39", "9"),
- ("41", "A"),
- ("4F", "O"),
- ("4f", "O"),
- ("DE", "\xde"),
- ("De", "\xde"),
- ("dE", "\xde"),
- ("de", "\xde"),
- ("414243", "ABC"),
- ("000000FF0000", "\x00\x00\x00\xff\x00\x00"),
- ("289cc8C03d8e", "\x28\x9c\xc8\xc0\x3d\x8e"),
+ (b"", b""),
+ (b"30", b"0"),
+ (b"31", b"1"),
+ (b"32", b"2"),
+ (b"38", b"8"),
+ (b"39", b"9"),
+ (b"41", b"A"),
+ (b"4F", b"O"),
+ (b"4f", b"O"),
+ (b"DE", b"\xde"),
+ (b"De", b"\xde"),
+ (b"dE", b"\xde"),
+ (b"de", b"\xde"),
+ (b"414243", b"ABC"),
+ (b"000000FF0000", b"\x00\x00\x00\xff\x00\x00"),
+ (b"289cc8C03d8e", b"\x28\x9c\xc8\xc0\x3d\x8e"),
]:
assert self.binascii.unhexlify(input) == expected
assert self.binascii.a2b_hex(input) == expected
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit