Bytes literal.
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 997122b..4dee01b 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -403,7 +403,19 @@
self.assertEqual(bytes.join(tuple(lst)), bytes("abc"))
self.assertEqual(bytes.join(iter(lst)), bytes("abc"))
# XXX more...
-
+
+ def test_literal(self):
+ tests = [
+ (b"Wonderful spam", u"Wonderful spam"),
+ (br"Wonderful spam too", u"Wonderful spam too"),
+ (b"\xaa\x00\000\200", u"\xaa\x00\000\200"),
+ (br"\xaa\x00\000\200", ur"\xaa\x00\000\200"),
+ ]
+ for b, s in tests:
+ self.assertEqual(b, bytes(s, 'latin-1'))
+ for c in range(128, 256):
+ self.assertRaises(SyntaxError, eval,
+ 'b"%s"' % chr(c))
# Optimizations:
# __iter__? (optimization)
diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py
index ab9a660..bbd7511 100644
--- a/Lib/test/test_compiler.py
+++ b/Lib/test/test_compiler.py
@@ -187,6 +187,30 @@
exec(c, dct)
self.assertEquals(dct.get('result'), 1)
+ def testBytesLiteral(self):
+ c = compiler.compile("b'foo'", '<string>', 'eval')
+ b = eval(c)
+
+ c = compiler.compile('def f(b=b"foo"):\n'
+ ' b[0] += 1\n'
+ ' return b\n'
+ 'f(); f(); result = f()\n',
+ '<string>',
+ 'exec')
+ dct = {}
+ exec(c, dct)
+ self.assertEquals(dct.get('result'), b"ioo")
+
+ c = compiler.compile('def f():\n'
+ ' b = b"foo"\n'
+ ' b[0] += 1\n'
+ ' return b\n'
+ 'f(); f(); result = f()\n',
+ '<string>',
+ 'exec')
+ dct = {}
+ exec(c, dct)
+ self.assertEquals(dct.get('result'), b"goo")
NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard)