Invert fix_unicode_literal to switch back to real literals.
This commit is contained in:
parent
4d6fef7897
commit
f36280600f
|
@ -1,18 +1,19 @@
|
||||||
import re
|
|
||||||
from lib2to3.pgen2 import token
|
|
||||||
from lib2to3 import fixer_base
|
from lib2to3 import fixer_base
|
||||||
from lib2to3.fixer_util import Name, Call
|
from lib2to3.fixer_util import String
|
||||||
|
|
||||||
_literal_re = re.compile(r"[uU][rR]?[\'\"]")
|
|
||||||
|
|
||||||
|
|
||||||
class FixUnicodeLiteral(fixer_base.BaseFix):
|
class FixUnicodeLiteral(fixer_base.BaseFix):
|
||||||
BM_compatible = True
|
BM_compatible = True
|
||||||
PATTERN = """STRING"""
|
PATTERN = """
|
||||||
|
power< 'u'
|
||||||
|
trailer<
|
||||||
|
'('
|
||||||
|
arg=any
|
||||||
|
')'
|
||||||
|
>
|
||||||
|
>
|
||||||
|
"""
|
||||||
|
|
||||||
def transform(self, node, results):
|
def transform(self, node, results):
|
||||||
if node.type == token.STRING and _literal_re.match(node.value):
|
arg = results["arg"]
|
||||||
new = node.clone()
|
node.replace(String('u'+arg.value, prefix=node.prefix))
|
||||||
new.value = new.value[1:]
|
|
||||||
new.prefix = ''
|
|
||||||
node.replace(Call(Name(u'u', prefix=node.prefix), [new]))
|
|
||||||
|
|
Loading…
Reference in New Issue