Skip to content

Commit

Permalink
Invert fix_unicode_literal to switch back to real literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Nov 6, 2015
1 parent 4d6fef7 commit f362806
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions 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))

0 comments on commit f362806

Please sign in to comment.