diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2008-12-02 06:00:15 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2008-12-02 06:00:15 (GMT) |
commit | 15b16a3ec4d515a7ea506fafd4a830fda3c84616 (patch) | |
tree | 82f0d5d902556899c6375d9e70b303131ccb5d48 /Lib/test | |
parent | eae122be62af41d2b6557c0056cc167a3052a034 (diff) | |
download | cpython-15b16a3ec4d515a7ea506fafd4a830fda3c84616.zip cpython-15b16a3ec4d515a7ea506fafd4a830fda3c84616.tar.gz cpython-15b16a3ec4d515a7ea506fafd4a830fda3c84616.tar.bz2 |
Issue #4387: binascii now refuses to accept str as binary input.
Diffstat (limited to 'Lib/test')
-rwxr-xr-x | Lib/test/test_binascii.py | 12 | ||||
-rw-r--r-- | Lib/test/test_descr.py | 16 | ||||
-rw-r--r-- | Lib/test/test_zlib.py | 4 |
3 files changed, 16 insertions, 16 deletions
diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index 76a76b2..d4ab6bf 100755 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -121,7 +121,7 @@ class BinASCIITest(unittest.TestCase): self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1]) self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1] + b'q') - self.assertEqual(binascii.hexlify('a'), b'61') + self.assertEqual(binascii.hexlify(b'a'), b'61') def test_qp(self): # A test for SF bug 534347 (segfaults without the proper fix) @@ -166,7 +166,15 @@ class BinASCIITest(unittest.TestCase): f(b'') except SystemError as err: self.fail("%s(b'') raises SystemError: %s" % (n, err)) - binascii.crc_hqx('', 0) + binascii.crc_hqx(b'', 0) + + def test_no_binary_strings(self): + # b2a_ must not accept strings + for f in (binascii.b2a_uu, binascii.b2a_base64, + binascii.b2a_hqx, binascii.b2a_qp, + binascii.hexlify, binascii.rlecode_hqx, + binascii.crc_hqx, binascii.crc32): + self.assertRaises(TypeError, f, "test") def test_main(): support.run_unittest(BinASCIITest) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index fa3e0c3..1020740 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -3097,22 +3097,14 @@ order (MRO) for bases """ import binascii # SF bug [#470040] ParseTuple t# vs subclasses. - class MyStr(str): + class MyBytes(bytes): pass - base = 'abc' - m = MyStr(base) + base = b'abc' + m = MyBytes(base) # b2a_hex uses the buffer interface to get its argument's value, via # PyArg_ParseTuple 't#' code. self.assertEqual(binascii.b2a_hex(m), binascii.b2a_hex(base)) - # It's not clear that unicode will continue to support the character - # buffer interface, and this test will fail if that's taken away. - class MyUni(str): - pass - base = 'abc' - m = MyUni(base) - self.assertEqual(binascii.b2a_hex(m), binascii.b2a_hex(base)) - class MyInt(int): pass m = MyInt(42) @@ -3129,7 +3121,7 @@ order (MRO) for bases """ class octetstring(str): def __str__(self): - return binascii.b2a_hex(self).decode("ascii") + return binascii.b2a_hex(self.encode('ascii')).decode("ascii") def __repr__(self): return self + " repr" diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index f52aa5e..99c8dda 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -48,11 +48,11 @@ class ChecksumTestCase(unittest.TestCase): self.assertEqual(zlib.adler32('spam'), 72286642) def test_same_as_binascii_crc32(self): - foo = 'abcdefghijklmnop' + foo = b'abcdefghijklmnop' crc = 2486878355 self.assertEqual(binascii.crc32(foo), crc) self.assertEqual(zlib.crc32(foo), crc) - self.assertEqual(binascii.crc32('spam'), zlib.crc32('spam')) + self.assertEqual(binascii.crc32(b'spam'), zlib.crc32(b'spam')) |