1"""Fixer that changes unicode to str and unichr to chr, but -- unlike the 2lib2to3 fix_unicode.py fixer, does not change u"..." into "...". 3 4The reason is that Py3.3+ supports the u"..." string prefix, and, if 5present, the prefix may provide useful information for disambiguating 6between byte strings and unicode strings, which is often the hardest part 7of the porting task. 8 9""" 10 11from lib2to3.pgen2 import token 12from lib2to3 import fixer_base 13 14_mapping = {u"unichr" : u"chr", u"unicode" : u"str"} 15 16class FixUnicodeKeepU(fixer_base.BaseFix): 17 BM_compatible = True 18 PATTERN = "'unicode' | 'unichr'" 19 20 def transform(self, node, results): 21 if node.type == token.NAME: 22 new = node.clone() 23 new.value = _mapping[node.value] 24 return new 25