equal
deleted
inserted
replaced
|
1 """Fixer that changes unicode to str, unichr to chr, and u"..." into "...". |
|
2 |
|
3 """ |
|
4 |
|
5 import re |
|
6 from ..pgen2 import token |
|
7 from .. import fixer_base |
|
8 |
|
9 class FixUnicode(fixer_base.BaseFix): |
|
10 |
|
11 PATTERN = "STRING | NAME<'unicode' | 'unichr'>" |
|
12 |
|
13 def transform(self, node, results): |
|
14 if node.type == token.NAME: |
|
15 if node.value == "unicode": |
|
16 new = node.clone() |
|
17 new.value = "str" |
|
18 return new |
|
19 if node.value == "unichr": |
|
20 new = node.clone() |
|
21 new.value = "chr" |
|
22 return new |
|
23 # XXX Warn when __unicode__ found? |
|
24 elif node.type == token.STRING: |
|
25 if re.match(r"[uU][rR]?[\'\"]", node.value): |
|
26 new = node.clone() |
|
27 new.value = new.value[1:] |
|
28 return new |