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_itertools.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.7 KB  |  37 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. ''' Fixer for itertools.(imap|ifilter|izip) --> (map|filter|zip) and
  5.     itertools.ifilterfalse --> itertools.filterfalse (bugs 2360-2363)
  6.  
  7.     imports from itertools are fixed in fix_itertools_import.py
  8.  
  9.     If itertools is imported as something else (ie: import itertools as it;
  10.     it.izip(spam, eggs)) method calls will not get fixed.
  11.     '''
  12. from  import fixer_base
  13. from fixer_util import Name
  14.  
  15. class FixItertools(fixer_base.BaseFix):
  16.     it_funcs = "('imap'|'ifilter'|'izip'|'ifilterfalse')"
  17.     PATTERN = "\n              power< it='itertools'\n                  trailer<\n                     dot='.' func=%(it_funcs)s > trailer< '(' [any] ')' > >\n              |\n              power< func=%(it_funcs)s trailer< '(' [any] ')' > >\n              " % locals()
  18.     run_order = 6
  19.     
  20.     def transform(self, node, results):
  21.         prefix = None
  22.         func = results['func'][0]
  23.         if 'it' in results and func.value != 'ifilterfalse':
  24.             dot = results['dot']
  25.             it = results['it']
  26.             prefix = it.get_prefix()
  27.             it.remove()
  28.             dot.remove()
  29.             func.parent.replace(func)
  30.         
  31.         if not prefix:
  32.             pass
  33.         prefix = func.get_prefix()
  34.         func.replace(Name(func.value[1:], prefix = prefix))
  35.  
  36.  
  37.