OLD | NEW |
(Empty) | |
| 1 """Fixer that changes unicode to str and unichr to chr, but -- unlike the |
| 2 lib2to3 fix_unicode.py fixer, does not change u"..." into "...". |
| 3 |
| 4 The reason is that Py3.3+ supports the u"..." string prefix, and, if |
| 5 present, the prefix may provide useful information for disambiguating |
| 6 between byte strings and unicode strings, which is often the hardest part |
| 7 of the porting task. |
| 8 |
| 9 """ |
| 10 |
| 11 from lib2to3.pgen2 import token |
| 12 from lib2to3 import fixer_base |
| 13 |
| 14 _mapping = {u"unichr" : u"chr", u"unicode" : u"str"} |
| 15 |
| 16 class 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 |
OLD | NEW |