PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/lib-python/2/lib2to3/fixes/fix_unicode.py

https://bitbucket.org/kcr/pypy
Python | 25 lines | 25 code | 0 blank | 0 comment | 0 complexity | 81a50bc98661c686cb876425b5a0fddd MD5 | raw file
Possible License(s): Apache-2.0
  1. """Fixer that changes unicode to str, unichr to chr, and u"..." into "...".
  2. """
  3. import re
  4. from ..pgen2 import token
  5. from .. import fixer_base
  6. _mapping = {u"unichr" : u"chr", u"unicode" : u"str"}
  7. _literal_re = re.compile(ur"[uU][rR]?[\'\"]")
  8. class FixUnicode(fixer_base.BaseFix):
  9. BM_compatible = True
  10. PATTERN = "STRING | 'unicode' | 'unichr'"
  11. def transform(self, node, results):
  12. if node.type == token.NAME:
  13. new = node.clone()
  14. new.value = _mapping[node.value]
  15. return new
  16. elif node.type == token.STRING:
  17. if _literal_re.match(node.value):
  18. new = node.clone()
  19. new.value = new.value[1:]
  20. return new