diff options
Diffstat (limited to 'Lib/lib2to3/fixes/fix_unicode.py')
| -rw-r--r-- | Lib/lib2to3/fixes/fix_unicode.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/Lib/lib2to3/fixes/fix_unicode.py b/Lib/lib2to3/fixes/fix_unicode.py index 580e82d..cd3b89c 100644 --- a/Lib/lib2to3/fixes/fix_unicode.py +++ b/Lib/lib2to3/fixes/fix_unicode.py @@ -6,23 +6,20 @@ import re from ..pgen2 import token from .. import fixer_base +_mapping = {u"unichr" : u"chr", u"unicode" : u"str"} +_literal_re = re.compile(ur"[uU][rR]?[\'\"]") + class FixUnicode(fixer_base.BaseFix): - PATTERN = "STRING | NAME<'unicode' | 'unichr'>" + PATTERN = "STRING | 'unicode' | 'unichr'" def transform(self, node, results): if node.type == token.NAME: - if node.value == u"unicode": - new = node.clone() - new.value = u"str" - return new - if node.value == u"unichr": - new = node.clone() - new.value = u"chr" - return new - # XXX Warn when __unicode__ found? + new = node.clone() + new.value = _mapping[node.value] + return new elif node.type == token.STRING: - if re.match(ur"[uU][rR]?[\'\"]", node.value): + if _literal_re.match(node.value): new = node.clone() new.value = new.value[1:] return new |
