From f36280600f8680fe9ae313d09db663195b615bc0 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 25 Oct 2015 11:07:27 -0400 Subject: [PATCH] Invert fix_unicode_literal to switch back to real literals. --- .../custom_fixers/fix_unicode_literal.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/maint/scripts/custom_fixers/fix_unicode_literal.py b/maint/scripts/custom_fixers/fix_unicode_literal.py index 560c2776..2c56b29c 100644 --- a/maint/scripts/custom_fixers/fix_unicode_literal.py +++ b/maint/scripts/custom_fixers/fix_unicode_literal.py @@ -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))