~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Lib/lib2to3/fixes/fix_unicode.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from ..pgen2 import token
7
7
from .. import fixer_base
8
8
 
 
9
_mapping = {u"unichr" : u"chr", u"unicode" : u"str"}
 
10
_literal_re = re.compile(ur"[uU][rR]?[\'\"]")
 
11
 
9
12
class FixUnicode(fixer_base.BaseFix):
10
13
 
11
 
    PATTERN = "STRING | NAME<'unicode' | 'unichr'>"
 
14
    PATTERN = "STRING | 'unicode' | 'unichr'"
12
15
 
13
16
    def transform(self, node, results):
14
17
        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?
 
18
            new = node.clone()
 
19
            new.value = _mapping[node.value]
 
20
            return new
24
21
        elif node.type == token.STRING:
25
 
            if re.match(r"[uU][rR]?[\'\"]", node.value):
 
22
            if _literal_re.match(node.value):
26
23
                new = node.clone()
27
24
                new.value = new.value[1:]
28
25
                return new