Mercurial > cpython-lru_cache-weakref
annotate Lib/lib2to3/fixes/fix_exec.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 119e4323400d |
| children | 7700408f65fc |
| rev | line source |
|---|---|
| 45906 | 1 # Copyright 2006 Google, Inc. All Rights Reserved. |
| 2 # Licensed to PSF under a Contributor Agreement. | |
| 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 | |
| 12 # Local imports | |
| 13 from .. import pytree | |
|
47726
4e304aded7a8
Merged revisions 64286 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
45906
diff
changeset
|
14 from .. import fixer_base |
|
4e304aded7a8
Merged revisions 64286 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
45906
diff
changeset
|
15 from ..fixer_util import Comma, Name, Call |
| 45906 | 16 |
| 17 | |
|
47726
4e304aded7a8
Merged revisions 64286 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
45906
diff
changeset
|
18 class FixExec(fixer_base.BaseFix): |
| 45906 | 19 |
| 20 PATTERN = """ | |
| 21 exec_stmt< 'exec' a=any 'in' b=any [',' c=any] > | |
| 22 | | |
| 23 exec_stmt< 'exec' (not atom<'(' [any] ')'>) a=any > | |
| 24 """ | |
| 25 | |
| 26 def transform(self, node, results): | |
| 27 assert results | |
| 28 syms = self.syms | |
| 29 a = results["a"] | |
| 30 b = results.get("b") | |
| 31 c = results.get("c") | |
| 32 args = [a.clone()] | |
| 33 args[0].set_prefix("") | |
| 34 if b is not None: | |
| 35 args.extend([Comma(), b.clone()]) | |
| 36 if c is not None: | |
| 37 args.extend([Comma(), c.clone()]) | |
| 38 | |
|
53934
119e4323400d
Merged revisions 72491-72493 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47726
diff
changeset
|
39 return Call(Name(u"exec"), args, prefix=node.get_prefix()) |
