]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/lib2to3/fixes/fix_throw.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / lib2to3 / fixes / fix_throw.py
CommitLineData
4710c53d 1"""Fixer for generator.throw(E, V, T).\r
2\r
3g.throw(E) -> g.throw(E)\r
4g.throw(E, V) -> g.throw(E(V))\r
5g.throw(E, V, T) -> g.throw(E(V).with_traceback(T))\r
6\r
7g.throw("foo"[, V[, T]]) will warn about string exceptions."""\r
8# Author: Collin Winter\r
9\r
10# Local imports\r
11from .. import pytree\r
12from ..pgen2 import token\r
13from .. import fixer_base\r
14from ..fixer_util import Name, Call, ArgList, Attr, is_tuple\r
15\r
16class FixThrow(fixer_base.BaseFix):\r
17 BM_compatible = True\r
18 PATTERN = """\r
19 power< any trailer< '.' 'throw' >\r
20 trailer< '(' args=arglist< exc=any ',' val=any [',' tb=any] > ')' >\r
21 >\r
22 |\r
23 power< any trailer< '.' 'throw' > trailer< '(' exc=any ')' > >\r
24 """\r
25\r
26 def transform(self, node, results):\r
27 syms = self.syms\r
28\r
29 exc = results["exc"].clone()\r
30 if exc.type is token.STRING:\r
31 self.cannot_convert(node, "Python 3 does not support string exceptions")\r
32 return\r
33\r
34 # Leave "g.throw(E)" alone\r
35 val = results.get(u"val")\r
36 if val is None:\r
37 return\r
38\r
39 val = val.clone()\r
40 if is_tuple(val):\r
41 args = [c.clone() for c in val.children[1:-1]]\r
42 else:\r
43 val.prefix = u""\r
44 args = [val]\r
45\r
46 throw_args = results["args"]\r
47\r
48 if "tb" in results:\r
49 tb = results["tb"].clone()\r
50 tb.prefix = u""\r
51\r
52 e = Call(exc, args)\r
53 with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])]\r
54 throw_args.replace(pytree.Node(syms.power, with_tb))\r
55 else:\r
56 throw_args.replace(Call(exc, args))\r