home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / fix_unicode.py < prev    next >
Encoding:
Python Source  |  2011-02-15  |  832 b   |  29 lines

  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
  29.