Staging
v0.5.1
swh:1:snp:635f4099902912592851108bcac178ff574f7c5f
Raw File
Tip revision: 4bd1cefca9e1e4925c25c8119790288b89e7a52d authored by Barry Warsaw on 18 July 2008, 02:28:44 UTC
Bumping to 3.0b2
Tip revision: 4bd1cef
fix_unicode.py
"""Fixer that changes unicode to str, unichr to chr, and u"..." into "...".

"""

import re
from ..pgen2 import token
from .. import fixer_base

class FixUnicode(fixer_base.BaseFix):

    PATTERN = "STRING | NAME<'unicode' | 'unichr'>"

    def transform(self, node, results):
        if node.type == token.NAME:
            if node.value == "unicode":
                new = node.clone()
                new.value = "str"
                return new
            if node.value == "unichr":
                new = node.clone()
                new.value = "chr"
                return new
            # XXX Warn when __unicode__ found?
        elif node.type == token.STRING:
            if re.match(r"[uU][rR]?[\'\"]", node.value):
                new = node.clone()
                new.value = new.value[1:]
                return new
back to top