forked from tornadoweb/tornado
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invert fix_unicode_literal to switch back to real literals.
- Loading branch information
Showing
1 changed file
with
12 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |