PageRenderTime 42ms CodeModel.GetById 37ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Lib/lib2to3/fixes/fix_unicode.py

http://unladen-swallow.googlecode.com/
Python | 28 lines | 28 code | 0 blank | 0 comment | 0 complexity | 05e9e9ae6cbc1c396bc11b19b5dab25a MD5 | raw file
 1"""Fixer that changes unicode to str, unichr to chr, and u"..." into "...".
 2
 3"""
 4
 5import re
 6from ..pgen2 import token
 7from .. import fixer_base
 8
 9class 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