diff options
author | Guido van Rossum <guido@python.org> | 2007-05-08 19:09:34 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-08 19:09:34 (GMT) |
commit | 57b93ad56d570c27bd3de3820b996352121c18e2 (patch) | |
tree | dbdce68ef3995086ec14d57493573029a9037ab6 | |
parent | e5e80b8c561de3a13154fa45eafcb32b8695eea7 (diff) | |
download | cpython-57b93ad56d570c27bd3de3820b996352121c18e2.zip cpython-57b93ad56d570c27bd3de3820b996352121c18e2.tar.gz cpython-57b93ad56d570c27bd3de3820b996352121c18e2.tar.bz2 |
repr(b"\0") should return b"\x00", not the (unusual) b"\0".
-rw-r--r-- | Lib/test/test_bytes.py | 5 | ||||
-rw-r--r-- | Objects/bytesobject.c | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 102eb46..ded0491 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -73,8 +73,9 @@ class BytesTest(unittest.TestCase): def test_repr(self): self.assertEqual(repr(bytes()), "b''") - self.assertEqual(repr(bytes([0])), "b'\\0'") - self.assertEqual(repr(bytes([0, 1, 254, 255])), "b'\\0\\x01\\xfe\\xff'") + self.assertEqual(repr(bytes([0])), "b'\\x00'") + self.assertEqual(repr(bytes([0, 1, 254, 255])), + "b'\\x00\\x01\\xfe\\xff'") self.assertEqual(repr(bytes('abc')), "b'abc'") self.assertEqual(repr(bytes("'")), "b'\\''") diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index cb830e3..3a707ac 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -849,7 +849,7 @@ bytes_repr(PyBytesObject *self) else if (c == '\r') *p++ = '\\', *p++ = 'r'; else if (c == 0) - *p++ = '\\', *p++ = '0'; + *p++ = '\\', *p++ = 'x', *p++ = '0', *p++ = '0'; else if (c < ' ' || c >= 0x7f) { /* For performance, we don't want to call PyOS_snprintf here (extra layers of |