home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / lib2to3 / fixes / fix_ws_comma.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.4 KB  |  43 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """Fixer that changes 'a ,b' into 'a, b'.
  5.  
  6. This also changes '{a :b}' into '{a: b}', but does not touch other
  7. uses of colons.  It does not touch other uses of whitespace.
  8.  
  9. """
  10. from  import pytree
  11. from pgen2 import token
  12. from  import fixer_base
  13.  
  14. class FixWsComma(fixer_base.BaseFix):
  15.     explicit = True
  16.     PATTERN = "\n    any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]>\n    "
  17.     COMMA = pytree.Leaf(token.COMMA, ',')
  18.     COLON = pytree.Leaf(token.COLON, ':')
  19.     SEPS = (COMMA, COLON)
  20.     
  21.     def transform(self, node, results):
  22.         new = node.clone()
  23.         comma = False
  24.         for child in new.children:
  25.             if child in self.SEPS:
  26.                 prefix = child.get_prefix()
  27.                 if prefix.isspace() and '\n' not in prefix:
  28.                     child.set_prefix('')
  29.                 
  30.                 comma = True
  31.                 continue
  32.             if comma:
  33.                 prefix = child.get_prefix()
  34.                 if not prefix:
  35.                     child.set_prefix(' ')
  36.                 
  37.             
  38.             comma = False
  39.         
  40.         return new
  41.  
  42.  
  43.