]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Invert fix_unicode_literal to switch back to real literals.
authorBen Darnell <ben@bendarnell.com>
Sun, 25 Oct 2015 15:07:27 +0000 (11:07 -0400)
committerBen Darnell <ben@bendarnell.com>
Fri, 6 Nov 2015 23:53:11 +0000 (18:53 -0500)
maint/scripts/custom_fixers/fix_unicode_literal.py

index 560c277668c34d6e7c642d4b9ea34570a3a20366..2c56b29ceb569c1cb7807aecf030daac92cf29f4 100644 (file)
@@ -1,18 +1,19 @@
-import re
-from lib2to3.pgen2 import token
 from lib2to3 import fixer_base
-from lib2to3.fixer_util import Name, Call
-
-_literal_re = re.compile(r"[uU][rR]?[\'\"]")
+from lib2to3.fixer_util import String
 
 
 class FixUnicodeLiteral(fixer_base.BaseFix):
     BM_compatible = True
-    PATTERN = """STRING"""
+    PATTERN = """
+    power< 'u'
+        trailer<
+            '('
+                arg=any
+            ')'
+        >
+    >
+    """
 
     def transform(self, node, results):
-        if node.type == token.STRING and _literal_re.match(node.value):
-            new = node.clone()
-            new.value = new.value[1:]
-            new.prefix = ''
-            node.replace(Call(Name(u'u', prefix=node.prefix), [new]))
+        arg = results["arg"]
+        node.replace(String('u'+arg.value, prefix=node.prefix))