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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Fixer for exec.
  5.  
  6. This converts usages of the exec statement into calls to a built-in
  7. exec() function.
  8.  
  9. exec code in ns1, ns2 -> exec(code, ns1, ns2)
  10. '''
  11. from  import pytree
  12. from  import fixer_base
  13. from fixer_util import Comma, Name, Call
  14.  
  15. class FixExec(fixer_base.BaseFix):
  16.     PATTERN = "\n    exec_stmt< 'exec' a=any 'in' b=any [',' c=any] >\n    |\n    exec_stmt< 'exec' (not atom<'(' [any] ')'>) a=any >\n    "
  17.     
  18.     def transform(self, node, results):
  19.         if not results:
  20.             raise AssertionError
  21.         syms = self.syms
  22.         a = results['a']
  23.         b = results.get('b')
  24.         c = results.get('c')
  25.         args = [
  26.             a.clone()]
  27.         args[0].set_prefix('')
  28.         if b is not None:
  29.             args.extend([
  30.                 Comma(),
  31.                 b.clone()])
  32.         
  33.         if c is not None:
  34.             args.extend([
  35.                 Comma(),
  36.                 c.clone()])
  37.         
  38.         return Call(Name('exec'), args, prefix = node.get_prefix())
  39.  
  40.  
  41.