Skip to content

Instantly share code, notes, and snippets.

@eli-collins
Created December 9, 2011 19:05
Show Gist options
  • Save eli-collins/1452842 to your computer and use it in GitHub Desktop.
Save eli-collins/1452842 to your computer and use it in GitHub Desktop.
patch against Python 3.3 source to re-enable u'' prefixes
diff -r f1cafe6f7834 Lib/test/test_builtin.py
--- a/Lib/test/test_builtin.py Sun Nov 20 16:01:35 2011 +0100
+++ b/Lib/test/test_builtin.py Fri Dec 09 14:04:31 2011 -0500
@@ -437,6 +437,14 @@
self.assertRaises(TypeError, eval, ())
self.assertRaises(SyntaxError, eval, bom[:2] + b'a')
+ # test 2.x u'...' syntax
+ self.assertEqual(eval('u"abc"'), "abc")
+ self.assertEqual(eval(r'ur"a\bc"'), "a\\bc")
+ self.assertRaises(SyntaxError, eval, 'bu"abc"')
+ self.assertRaises(SyntaxError, eval, 'ub"abc"')
+ self.assertRaises(SyntaxError, eval, 'ru"abc"')
+
+
def test_general_eval(self):
# Tests that general mappings can be used for the locals argument
diff -r f1cafe6f7834 Parser/tokenizer.c
--- a/Parser/tokenizer.c Sun Nov 20 16:01:35 2011 +0100
+++ b/Parser/tokenizer.c Fri Dec 09 14:04:31 2011 -0500
@@ -1412,8 +1412,8 @@
/* Identifier (most frequent token!) */
nonascii = 0;
if (is_potential_identifier_start(c)) {
- /* Process b"", r"" and br"" */
- if (c == 'b' || c == 'B') {
+ /* Process u"", b"", r"", ur"" and br"" */
+ if (c == 'b' || c == 'B' || c == 'u' || c == 'U') {
c = tok_nextc(tok);
if (c == '"' || c == '\'')
goto letter_quote;
diff -r f1cafe6f7834 Python/ast.c
--- a/Python/ast.c Sun Nov 20 16:01:35 2011 +0100
+++ b/Python/ast.c Fri Dec 09 14:04:31 2011 -0500
@@ -3748,6 +3748,10 @@
quote = *++s;
*bytesmode = 1;
}
+ else if (quote == 'u' || quote == 'U') {
+ /* this is parsed for 2.x compatibility, but ignored. */
+ quote = *++s;
+ }
if (quote == 'r' || quote == 'R') {
quote = *++s;
rawmode = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment