1"""Python abstract syntax node definitions
2
3This file is automatically generated by Tools/compiler/astgen.py
4"""
5from __future__ import absolute_import
6from pony.py23compat import items_list
7
8from .consts import CO_VARARGS, CO_VARKEYWORDS
9
10def flatten(seq):
11    l = []
12    for elt in seq:
13        t = type(elt)
14        if t is tuple or t is list:
15            for elt2 in flatten(elt):
16                l.append(elt2)
17        else:
18            l.append(elt)
19    return l
20
21def flatten_nodes(seq):
22    return [n for n in flatten(seq) if isinstance(n, Node)]
23
24nodes = {}
25
26class Node:
27    """Abstract base class for ast nodes."""
28    def getChildren(self):
29        pass # implemented by subclasses
30    def __iter__(self):
31        for n in self.getChildren():
32            yield n
33    def asList(self): # for backwards compatibility
34        return self.getChildren()
35    def getChildNodes(self):
36        pass # implemented by subclasses
37
38class EmptyNode(Node):
39    pass
40
41class Expression(Node):
42    # Expression is an artificial node class to support "eval"
43    nodes["expression"] = "Expression"
44    def __init__(self, node):
45        self.node = node
46
47    def getChildren(self):
48        return self.node,
49
50    def getChildNodes(self):
51        return self.node,
52
53    def __repr__(self):
54        return "Expression(%s)" % (repr(self.node))
55
56class Add(Node):
57    def __init__(self, leftright, lineno=None):
58        self.left = leftright[0]
59        self.right = leftright[1]
60        self.lineno = lineno
61
62    def getChildren(self):
63        return self.left, self.right
64
65    def getChildNodes(self):
66        return self.left, self.right
67
68    def __repr__(self):
69        return "Add((%s, %s))" % (repr(self.left), repr(self.right))
70
71class And(Node):
72    def __init__(self, nodes, lineno=None):
73        self.nodes = nodes
74        self.lineno = lineno
75
76    def getChildren(self):
77        return tuple(flatten(self.nodes))
78
79    def getChildNodes(self):
80        nodelist = []
81        nodelist.extend(flatten_nodes(self.nodes))
82        return tuple(nodelist)
83
84    def __repr__(self):
85        return "And(%s)" % (repr(self.nodes),)
86
87class AssAttr(Node):
88    def __init__(self, expr, attrname, flags, lineno=None):
89        self.expr = expr
90        self.attrname = attrname
91        self.flags = flags
92        self.lineno = lineno
93
94    def getChildren(self):
95        return self.expr, self.attrname, self.flags
96
97    def getChildNodes(self):
98        return self.expr,
99
100    def __repr__(self):
101        return "AssAttr(%s, %s, %s)" % (repr(self.expr), repr(self.attrname), repr(self.flags))
102
103class AssList(Node):
104    def __init__(self, nodes, lineno=None):
105        self.nodes = nodes
106        self.lineno = lineno
107
108    def getChildren(self):
109        return tuple(flatten(self.nodes))
110
111    def getChildNodes(self):
112        nodelist = []
113        nodelist.extend(flatten_nodes(self.nodes))
114        return tuple(nodelist)
115
116    def __repr__(self):
117        return "AssList(%s)" % (repr(self.nodes),)
118
119class AssName(Node):
120    def __init__(self, name, flags, lineno=None):
121        self.name = name
122        self.flags = flags
123        self.lineno = lineno
124
125    def getChildren(self):
126        return self.name, self.flags
127
128    def getChildNodes(self):
129        return ()
130
131    def __repr__(self):
132        return "AssName(%s, %s)" % (repr(self.name), repr(self.flags))
133
134class AssTuple(Node):
135    def __init__(self, nodes, lineno=None):
136        self.nodes = nodes
137        self.lineno = lineno
138
139    def getChildren(self):
140        return tuple(flatten(self.nodes))
141
142    def getChildNodes(self):
143        nodelist = []
144        nodelist.extend(flatten_nodes(self.nodes))
145        return tuple(nodelist)
146
147    def __repr__(self):
148        return "AssTuple(%s)" % (repr(self.nodes),)
149
150class Assert(Node):
151    def __init__(self, test, fail, lineno=None):
152        self.test = test
153        self.fail = fail
154        self.lineno = lineno
155
156    def getChildren(self):
157        children = []
158        children.append(self.test)
159        children.append(self.fail)
160        return tuple(children)
161
162    def getChildNodes(self):
163        nodelist = []
164        nodelist.append(self.test)
165        if self.fail is not None:
166            nodelist.append(self.fail)
167        return tuple(nodelist)
168
169    def __repr__(self):
170        return "Assert(%s, %s)" % (repr(self.test), repr(self.fail))
171
172class Assign(Node):
173    def __init__(self, nodes, expr, lineno=None):
174        self.nodes = nodes
175        self.expr = expr
176        self.lineno = lineno
177
178    def getChildren(self):
179        children = []
180        children.extend(flatten(self.nodes))
181        children.append(self.expr)
182        return tuple(children)
183
184    def getChildNodes(self):
185        nodelist = []
186        nodelist.extend(flatten_nodes(self.nodes))
187        nodelist.append(self.expr)
188        return tuple(nodelist)
189
190    def __repr__(self):
191        return "Assign(%s, %s)" % (repr(self.nodes), repr(self.expr))
192
193class AugAssign(Node):
194    def __init__(self, node, op, expr, lineno=None):
195        self.node = node
196        self.op = op
197        self.expr = expr
198        self.lineno = lineno
199
200    def getChildren(self):
201        return self.node, self.op, self.expr
202
203    def getChildNodes(self):
204        return self.node, self.expr
205
206    def __repr__(self):
207        return "AugAssign(%s, %s, %s)" % (repr(self.node), repr(self.op), repr(self.expr))
208
209class Backquote(Node):
210    def __init__(self, expr, lineno=None):
211        self.expr = expr
212        self.lineno = lineno
213
214    def getChildren(self):
215        return self.expr,
216
217    def getChildNodes(self):
218        return self.expr,
219
220    def __repr__(self):
221        return "Backquote(%s)" % (repr(self.expr),)
222
223class Bitand(Node):
224    def __init__(self, nodes, lineno=None):
225        self.nodes = nodes
226        self.lineno = lineno
227
228    def getChildren(self):
229        return tuple(flatten(self.nodes))
230
231    def getChildNodes(self):
232        nodelist = []
233        nodelist.extend(flatten_nodes(self.nodes))
234        return tuple(nodelist)
235
236    def __repr__(self):
237        return "Bitand(%s)" % (repr(self.nodes),)
238
239class Bitor(Node):
240    def __init__(self, nodes, lineno=None):
241        self.nodes = nodes
242        self.lineno = lineno
243
244    def getChildren(self):
245        return tuple(flatten(self.nodes))
246
247    def getChildNodes(self):
248        nodelist = []
249        nodelist.extend(flatten_nodes(self.nodes))
250        return tuple(nodelist)
251
252    def __repr__(self):
253        return "Bitor(%s)" % (repr(self.nodes),)
254
255class Bitxor(Node):
256    def __init__(self, nodes, lineno=None):
257        self.nodes = nodes
258        self.lineno = lineno
259
260    def getChildren(self):
261        return tuple(flatten(self.nodes))
262
263    def getChildNodes(self):
264        nodelist = []
265        nodelist.extend(flatten_nodes(self.nodes))
266        return tuple(nodelist)
267
268    def __repr__(self):
269        return "Bitxor(%s)" % (repr(self.nodes),)
270
271class Break(Node):
272    def __init__(self, lineno=None):
273        self.lineno = lineno
274
275    def getChildren(self):
276        return ()
277
278    def getChildNodes(self):
279        return ()
280
281    def __repr__(self):
282        return "Break()"
283
284class CallFunc(Node):
285    def __init__(self, node, args, star_args = None, dstar_args = None, lineno=None):
286        self.node = node
287        self.args = args
288        self.star_args = star_args
289        self.dstar_args = dstar_args
290        self.lineno = lineno
291
292    def getChildren(self):
293        children = []
294        children.append(self.node)
295        children.extend(flatten(self.args))
296        children.append(self.star_args)
297        children.append(self.dstar_args)
298        return tuple(children)
299
300    def getChildNodes(self):
301        nodelist = []
302        nodelist.append(self.node)
303        nodelist.extend(flatten_nodes(self.args))
304        if self.star_args is not None:
305            nodelist.append(self.star_args)
306        if self.dstar_args is not None:
307            nodelist.append(self.dstar_args)
308        return tuple(nodelist)
309
310    def __repr__(self):
311        return "CallFunc(%s, %s, %s, %s)" % (repr(self.node), repr(self.args), repr(self.star_args), repr(self.dstar_args))
312
313class Class(Node):
314    def __init__(self, name, bases, doc, code, decorators = None, lineno=None):
315        self.name = name
316        self.bases = bases
317        self.doc = doc
318        self.code = code
319        self.decorators = decorators
320        self.lineno = lineno
321
322    def getChildren(self):
323        children = []
324        children.append(self.name)
325        children.extend(flatten(self.bases))
326        children.append(self.doc)
327        children.append(self.code)
328        children.append(self.decorators)
329        return tuple(children)
330
331    def getChildNodes(self):
332        nodelist = []
333        nodelist.extend(flatten_nodes(self.bases))
334        nodelist.append(self.code)
335        if self.decorators is not None:
336            nodelist.append(self.decorators)
337        return tuple(nodelist)
338
339    def __repr__(self):
340        return "Class(%s, %s, %s, %s, %s)" % (repr(self.name), repr(self.bases), repr(self.doc), repr(self.code), repr(self.decorators))
341
342class Compare(Node):
343    def __init__(self, expr, ops, lineno=None):
344        self.expr = expr
345        self.ops = ops
346        self.lineno = lineno
347
348    def getChildren(self):
349        children = []
350        children.append(self.expr)
351        children.extend(flatten(self.ops))
352        return tuple(children)
353
354    def getChildNodes(self):
355        nodelist = []
356        nodelist.append(self.expr)
357        nodelist.extend(flatten_nodes(self.ops))
358        return tuple(nodelist)
359
360    def __repr__(self):
361        return "Compare(%s, %s)" % (repr(self.expr), repr(self.ops))
362
363class Const(Node):
364    def __init__(self, value, lineno=None):
365        self.value = value
366        self.lineno = lineno
367
368    def getChildren(self):
369        return self.value,
370
371    def getChildNodes(self):
372        return ()
373
374    def __repr__(self):
375        return "Const(%s)" % (repr(self.value),)
376
377class Continue(Node):
378    def __init__(self, lineno=None):
379        self.lineno = lineno
380
381    def getChildren(self):
382        return ()
383
384    def getChildNodes(self):
385        return ()
386
387    def __repr__(self):
388        return "Continue()"
389
390class Decorators(Node):
391    def __init__(self, nodes, lineno=None):
392        self.nodes = nodes
393        self.lineno = lineno
394
395    def getChildren(self):
396        return tuple(flatten(self.nodes))
397
398    def getChildNodes(self):
399        nodelist = []
400        nodelist.extend(flatten_nodes(self.nodes))
401        return tuple(nodelist)
402
403    def __repr__(self):
404        return "Decorators(%s)" % (repr(self.nodes),)
405
406class Dict(Node):
407    def __init__(self, items, lineno=None):
408        self.items = items
409        self.lineno = lineno
410
411    def getChildren(self):
412        return tuple(flatten(self.items))
413
414    def getChildNodes(self):
415        nodelist = []
416        nodelist.extend(flatten_nodes(self.items))
417        return tuple(nodelist)
418
419    def __repr__(self):
420        return "Dict(%s)" % (repr(self.items),)
421
422class Discard(Node):
423    def __init__(self, expr, lineno=None):
424        self.expr = expr
425        self.lineno = lineno
426
427    def getChildren(self):
428        return self.expr,
429
430    def getChildNodes(self):
431        return self.expr,
432
433    def __repr__(self):
434        return "Discard(%s)" % (repr(self.expr),)
435
436class Div(Node):
437    def __init__(self, leftright, lineno=None):
438        self.left = leftright[0]
439        self.right = leftright[1]
440        self.lineno = lineno
441
442    def getChildren(self):
443        return self.left, self.right
444
445    def getChildNodes(self):
446        return self.left, self.right
447
448    def __repr__(self):
449        return "Div((%s, %s))" % (repr(self.left), repr(self.right))
450
451class Ellipsis(Node):
452    def __init__(self, lineno=None):
453        self.lineno = lineno
454
455    def getChildren(self):
456        return ()
457
458    def getChildNodes(self):
459        return ()
460
461    def __repr__(self):
462        return "Ellipsis()"
463
464class Exec(Node):
465    def __init__(self, expr, locals, globals, lineno=None):
466        self.expr = expr
467        self.locals = locals
468        self.globals = globals
469        self.lineno = lineno
470
471    def getChildren(self):
472        children = []
473        children.append(self.expr)
474        children.append(self.locals)
475        children.append(self.globals)
476        return tuple(children)
477
478    def getChildNodes(self):
479        nodelist = []
480        nodelist.append(self.expr)
481        if self.locals is not None:
482            nodelist.append(self.locals)
483        if self.globals is not None:
484            nodelist.append(self.globals)
485        return tuple(nodelist)
486
487    def __repr__(self):
488        return "Exec(%s, %s, %s)" % (repr(self.expr), repr(self.locals), repr(self.globals))
489
490class FloorDiv(Node):
491    def __init__(self, leftright, lineno=None):
492        self.left = leftright[0]
493        self.right = leftright[1]
494        self.lineno = lineno
495
496    def getChildren(self):
497        return self.left, self.right
498
499    def getChildNodes(self):
500        return self.left, self.right
501
502    def __repr__(self):
503        return "FloorDiv((%s, %s))" % (repr(self.left), repr(self.right))
504
505class For(Node):
506    def __init__(self, assign, list, body, else_, lineno=None):
507        self.assign = assign
508        self.list = list
509        self.body = body
510        self.else_ = else_
511        self.lineno = lineno
512
513    def getChildren(self):
514        children = []
515        children.append(self.assign)
516        children.append(self.list)
517        children.append(self.body)
518        children.append(self.else_)
519        return tuple(children)
520
521    def getChildNodes(self):
522        nodelist = []
523        nodelist.append(self.assign)
524        nodelist.append(self.list)
525        nodelist.append(self.body)
526        if self.else_ is not None:
527            nodelist.append(self.else_)
528        return tuple(nodelist)
529
530    def __repr__(self):
531        return "For(%s, %s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.body), repr(self.else_))
532
533class FormattedValue(Node):
534    def __init__(self, value, fmt_spec):
535        self.value = value
536        self.fmt_spec = fmt_spec
537
538    def getChildren(self):
539        return self.value, self.fmt_spec
540
541    def getChildNodes(self):
542        return self.value, self.fmt_spec
543
544    def __repr__(self):
545        return "FormattedValue(%s, %s)" % (self.value, self.fmt_spec)
546
547class From(Node):
548    def __init__(self, modname, names, level, lineno=None):
549        self.modname = modname
550        self.names = names
551        self.level = level
552        self.lineno = lineno
553
554    def getChildren(self):
555        return self.modname, self.names, self.level
556
557    def getChildNodes(self):
558        return ()
559
560    def __repr__(self):
561        return "From(%s, %s, %s)" % (repr(self.modname), repr(self.names), repr(self.level))
562
563class Function(Node):
564    def __init__(self, decorators, name, argnames, defaults, flags, doc, code, lineno=None):
565        self.decorators = decorators
566        self.name = name
567        self.argnames = argnames
568        self.defaults = defaults
569        self.flags = flags
570        self.doc = doc
571        self.code = code
572        self.lineno = lineno
573        self.varargs = self.kwargs = None
574        if flags & CO_VARARGS:
575            self.varargs = 1
576        if flags & CO_VARKEYWORDS:
577            self.kwargs = 1
578
579
580    def getChildren(self):
581        children = []
582        children.append(self.decorators)
583        children.append(self.name)
584        children.append(self.argnames)
585        children.extend(flatten(self.defaults))
586        children.append(self.flags)
587        children.append(self.doc)
588        children.append(self.code)
589        return tuple(children)
590
591    def getChildNodes(self):
592        nodelist = []
593        if self.decorators is not None:
594            nodelist.append(self.decorators)
595        nodelist.extend(flatten_nodes(self.defaults))
596        nodelist.append(self.code)
597        return tuple(nodelist)
598
599    def __repr__(self):
600        return "Function(%s, %s, %s, %s, %s, %s, %s)" % (repr(self.decorators), repr(self.name), repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.doc), repr(self.code))
601
602class GenExpr(Node):
603    def __init__(self, code, lineno=None):
604        self.code = code
605        self.lineno = lineno
606        self.argnames = ['.0']
607        self.varargs = self.kwargs = None
608
609
610    def getChildren(self):
611        return self.code,
612
613    def getChildNodes(self):
614        return self.code,
615
616    def __repr__(self):
617        return "GenExpr(%s)" % (repr(self.code),)
618
619class GenExprFor(Node):
620    def __init__(self, assign, iter, ifs, lineno=None):
621        self.assign = assign
622        self.iter = iter
623        self.ifs = ifs
624        self.lineno = lineno
625        self.is_outmost = False
626
627    def getChildren(self):
628        children = []
629        children.append(self.assign)
630        children.append(self.iter)
631        children.extend(flatten(self.ifs))
632        return tuple(children)
633
634    def getChildNodes(self):
635        nodelist = []
636        nodelist.append(self.assign)
637        nodelist.append(self.iter)
638        nodelist.extend(flatten_nodes(self.ifs))
639        return tuple(nodelist)
640
641    def __repr__(self):
642        return "GenExprFor(%s, %s, %s)" % (repr(self.assign), repr(self.iter), repr(self.ifs))
643
644class GenExprIf(Node):
645    def __init__(self, test, lineno=None):
646        self.test = test
647        self.lineno = lineno
648
649    def getChildren(self):
650        return self.test,
651
652    def getChildNodes(self):
653        return self.test,
654
655    def __repr__(self):
656        return "GenExprIf(%s)" % (repr(self.test),)
657
658class GenExprInner(Node):
659    def __init__(self, expr, quals, lineno=None):
660        self.expr = expr
661        self.quals = quals
662        self.lineno = lineno
663
664    def getChildren(self):
665        children = []
666        children.append(self.expr)
667        children.extend(flatten(self.quals))
668        return tuple(children)
669
670    def getChildNodes(self):
671        nodelist = []
672        nodelist.append(self.expr)
673        nodelist.extend(flatten_nodes(self.quals))
674        return tuple(nodelist)
675
676    def __repr__(self):
677        return "GenExprInner(%s, %s)" % (repr(self.expr), repr(self.quals))
678
679class Getattr(Node):
680    def __init__(self, expr, attrname, lineno=None):
681        self.expr = expr
682        self.attrname = attrname
683        self.lineno = lineno
684
685    def getChildren(self):
686        return self.expr, self.attrname
687
688    def getChildNodes(self):
689        return self.expr,
690
691    def __repr__(self):
692        return "Getattr(%s, %s)" % (repr(self.expr), repr(self.attrname))
693
694class Global(Node):
695    def __init__(self, names, lineno=None):
696        self.names = names
697        self.lineno = lineno
698
699    def getChildren(self):
700        return self.names,
701
702    def getChildNodes(self):
703        return ()
704
705    def __repr__(self):
706        return "Global(%s)" % (repr(self.names),)
707
708class If(Node):
709    def __init__(self, tests, else_, lineno=None):
710        self.tests = tests
711        self.else_ = else_
712        self.lineno = lineno
713
714    def getChildren(self):
715        children = []
716        children.extend(flatten(self.tests))
717        children.append(self.else_)
718        return tuple(children)
719
720    def getChildNodes(self):
721        nodelist = []
722        nodelist.extend(flatten_nodes(self.tests))
723        if self.else_ is not None:
724            nodelist.append(self.else_)
725        return tuple(nodelist)
726
727    def __repr__(self):
728        return "If(%s, %s)" % (repr(self.tests), repr(self.else_))
729
730class IfExp(Node):
731    def __init__(self, test, then, else_, lineno=None):
732        self.test = test
733        self.then = then
734        self.else_ = else_
735        self.lineno = lineno
736
737    def getChildren(self):
738        return self.test, self.then, self.else_
739
740    def getChildNodes(self):
741        return self.test, self.then, self.else_
742
743    def __repr__(self):
744        return "IfExp(%s, %s, %s)" % (repr(self.test), repr(self.then), repr(self.else_))
745
746class Import(Node):
747    def __init__(self, names, lineno=None):
748        self.names = names
749        self.lineno = lineno
750
751    def getChildren(self):
752        return self.names,
753
754    def getChildNodes(self):
755        return ()
756
757    def __repr__(self):
758        return "Import(%s)" % (repr(self.names),)
759
760class Invert(Node):
761    def __init__(self, expr, lineno=None):
762        self.expr = expr
763        self.lineno = lineno
764
765    def getChildren(self):
766        return self.expr,
767
768    def getChildNodes(self):
769        return self.expr,
770
771    def __repr__(self):
772        return "Invert(%s)" % (repr(self.expr),)
773
774class Keyword(Node):
775    def __init__(self, name, expr, lineno=None):
776        self.name = name
777        self.expr = expr
778        self.lineno = lineno
779
780    def getChildren(self):
781        return self.name, self.expr
782
783    def getChildNodes(self):
784        return self.expr,
785
786    def __repr__(self):
787        return "Keyword(%s, %s)" % (repr(self.name), repr(self.expr))
788
789class Lambda(Node):
790    def __init__(self, argnames, defaults, flags, code, lineno=None):
791        self.argnames = argnames
792        self.defaults = defaults
793        self.flags = flags
794        self.code = code
795        self.lineno = lineno
796        self.varargs = self.kwargs = None
797        if flags & CO_VARARGS:
798            self.varargs = 1
799        if flags & CO_VARKEYWORDS:
800            self.kwargs = 1
801
802
803    def getChildren(self):
804        children = []
805        children.append(self.argnames)
806        children.extend(flatten(self.defaults))
807        children.append(self.flags)
808        children.append(self.code)
809        return tuple(children)
810
811    def getChildNodes(self):
812        nodelist = []
813        nodelist.extend(flatten_nodes(self.defaults))
814        nodelist.append(self.code)
815        return tuple(nodelist)
816
817    def __repr__(self):
818        return "Lambda(%s, %s, %s, %s)" % (repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.code))
819
820class LeftShift(Node):
821    def __init__(self, leftright, lineno=None):
822        self.left = leftright[0]
823        self.right = leftright[1]
824        self.lineno = lineno
825
826    def getChildren(self):
827        return self.left, self.right
828
829    def getChildNodes(self):
830        return self.left, self.right
831
832    def __repr__(self):
833        return "LeftShift((%s, %s))" % (repr(self.left), repr(self.right))
834
835class List(Node):
836    def __init__(self, nodes, lineno=None):
837        self.nodes = nodes
838        self.lineno = lineno
839
840    def getChildren(self):
841        return tuple(flatten(self.nodes))
842
843    def getChildNodes(self):
844        nodelist = []
845        nodelist.extend(flatten_nodes(self.nodes))
846        return tuple(nodelist)
847
848    def __repr__(self):
849        return "List(%s)" % (repr(self.nodes),)
850
851class ListComp(Node):
852    def __init__(self, expr, quals, lineno=None):
853        self.expr = expr
854        self.quals = quals
855        self.lineno = lineno
856
857    def getChildren(self):
858        children = []
859        children.append(self.expr)
860        children.extend(flatten(self.quals))
861        return tuple(children)
862
863    def getChildNodes(self):
864        nodelist = []
865        nodelist.append(self.expr)
866        nodelist.extend(flatten_nodes(self.quals))
867        return tuple(nodelist)
868
869    def __repr__(self):
870        return "ListComp(%s, %s)" % (repr(self.expr), repr(self.quals))
871
872class ListCompFor(Node):
873    def __init__(self, assign, list, ifs, lineno=None):
874        self.assign = assign
875        self.list = list
876        self.ifs = ifs
877        self.lineno = lineno
878
879    def getChildren(self):
880        children = []
881        children.append(self.assign)
882        children.append(self.list)
883        children.extend(flatten(self.ifs))
884        return tuple(children)
885
886    def getChildNodes(self):
887        nodelist = []
888        nodelist.append(self.assign)
889        nodelist.append(self.list)
890        nodelist.extend(flatten_nodes(self.ifs))
891        return tuple(nodelist)
892
893    def __repr__(self):
894        return "ListCompFor(%s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.ifs))
895
896class ListCompIf(Node):
897    def __init__(self, test, lineno=None):
898        self.test = test
899        self.lineno = lineno
900
901    def getChildren(self):
902        return self.test,
903
904    def getChildNodes(self):
905        return self.test,
906
907    def __repr__(self):
908        return "ListCompIf(%s)" % (repr(self.test),)
909
910class SetComp(Node):
911    def __init__(self, expr, quals, lineno=None):
912        self.expr = expr
913        self.quals = quals
914        self.lineno = lineno
915
916    def getChildren(self):
917        children = []
918        children.append(self.expr)
919        children.extend(flatten(self.quals))
920        return tuple(children)
921
922    def getChildNodes(self):
923        nodelist = []
924        nodelist.append(self.expr)
925        nodelist.extend(flatten_nodes(self.quals))
926        return tuple(nodelist)
927
928    def __repr__(self):
929        return "SetComp(%s, %s)" % (repr(self.expr), repr(self.quals))
930
931class DictComp(Node):
932    def __init__(self, key, value, quals, lineno=None):
933        self.key = key
934        self.value = value
935        self.quals = quals
936        self.lineno = lineno
937
938    def getChildren(self):
939        children = []
940        children.append(self.key)
941        children.append(self.value)
942        children.extend(flatten(self.quals))
943        return tuple(children)
944
945    def getChildNodes(self):
946        nodelist = []
947        nodelist.append(self.key)
948        nodelist.append(self.value)
949        nodelist.extend(flatten_nodes(self.quals))
950        return tuple(nodelist)
951
952    def __repr__(self):
953        return "DictComp(%s, %s, %s)" % (repr(self.key), repr(self.value), repr(self.quals))
954
955class Mod(Node):
956    def __init__(self, leftright, lineno=None):
957        self.left = leftright[0]
958        self.right = leftright[1]
959        self.lineno = lineno
960
961    def getChildren(self):
962        return self.left, self.right
963
964    def getChildNodes(self):
965        return self.left, self.right
966
967    def __repr__(self):
968        return "Mod((%s, %s))" % (repr(self.left), repr(self.right))
969
970class Module(Node):
971    def __init__(self, doc, node, lineno=None):
972        self.doc = doc
973        self.node = node
974        self.lineno = lineno
975
976    def getChildren(self):
977        return self.doc, self.node
978
979    def getChildNodes(self):
980        return self.node,
981
982    def __repr__(self):
983        return "Module(%s, %s)" % (repr(self.doc), repr(self.node))
984
985class Mul(Node):
986    def __init__(self, leftright, lineno=None):
987        self.left = leftright[0]
988        self.right = leftright[1]
989        self.lineno = lineno
990
991    def getChildren(self):
992        return self.left, self.right
993
994    def getChildNodes(self):
995        return self.left, self.right
996
997    def __repr__(self):
998        return "Mul((%s, %s))" % (repr(self.left), repr(self.right))
999
1000class Name(Node):
1001    def __init__(self, name, lineno=None):
1002        self.name = name
1003        self.lineno = lineno
1004
1005    def getChildren(self):
1006        return self.name,
1007
1008    def getChildNodes(self):
1009        return ()
1010
1011    def __repr__(self):
1012        return "Name(%s)" % (repr(self.name),)
1013
1014class Not(Node):
1015    def __init__(self, expr, lineno=None):
1016        self.expr = expr
1017        self.lineno = lineno
1018
1019    def getChildren(self):
1020        return self.expr,
1021
1022    def getChildNodes(self):
1023        return self.expr,
1024
1025    def __repr__(self):
1026        return "Not(%s)" % (repr(self.expr),)
1027
1028class Or(Node):
1029    def __init__(self, nodes, lineno=None):
1030        self.nodes = nodes
1031        self.lineno = lineno
1032
1033    def getChildren(self):
1034        return tuple(flatten(self.nodes))
1035
1036    def getChildNodes(self):
1037        nodelist = []
1038        nodelist.extend(flatten_nodes(self.nodes))
1039        return tuple(nodelist)
1040
1041    def __repr__(self):
1042        return "Or(%s)" % (repr(self.nodes),)
1043
1044class Pass(Node):
1045    def __init__(self, lineno=None):
1046        self.lineno = lineno
1047
1048    def getChildren(self):
1049        return ()
1050
1051    def getChildNodes(self):
1052        return ()
1053
1054    def __repr__(self):
1055        return "Pass()"
1056
1057class Power(Node):
1058    def __init__(self, leftright, lineno=None):
1059        self.left = leftright[0]
1060        self.right = leftright[1]
1061        self.lineno = lineno
1062
1063    def getChildren(self):
1064        return self.left, self.right
1065
1066    def getChildNodes(self):
1067        return self.left, self.right
1068
1069    def __repr__(self):
1070        return "Power((%s, %s))" % (repr(self.left), repr(self.right))
1071
1072class Print(Node):
1073    def __init__(self, nodes, dest, lineno=None):
1074        self.nodes = nodes
1075        self.dest = dest
1076        self.lineno = lineno
1077
1078    def getChildren(self):
1079        children = []
1080        children.extend(flatten(self.nodes))
1081        children.append(self.dest)
1082        return tuple(children)
1083
1084    def getChildNodes(self):
1085        nodelist = []
1086        nodelist.extend(flatten_nodes(self.nodes))
1087        if self.dest is not None:
1088            nodelist.append(self.dest)
1089        return tuple(nodelist)
1090
1091    def __repr__(self):
1092        return "Print(%s, %s)" % (repr(self.nodes), repr(self.dest))
1093
1094class Printnl(Node):
1095    def __init__(self, nodes, dest, lineno=None):
1096        self.nodes = nodes
1097        self.dest = dest
1098        self.lineno = lineno
1099
1100    def getChildren(self):
1101        children = []
1102        children.extend(flatten(self.nodes))
1103        children.append(self.dest)
1104        return tuple(children)
1105
1106    def getChildNodes(self):
1107        nodelist = []
1108        nodelist.extend(flatten_nodes(self.nodes))
1109        if self.dest is not None:
1110            nodelist.append(self.dest)
1111        return tuple(nodelist)
1112
1113    def __repr__(self):
1114        return "Printnl(%s, %s)" % (repr(self.nodes), repr(self.dest))
1115
1116class Raise(Node):
1117    def __init__(self, expr1, expr2, expr3, lineno=None):
1118        self.expr1 = expr1
1119        self.expr2 = expr2
1120        self.expr3 = expr3
1121        self.lineno = lineno
1122
1123    def getChildren(self):
1124        children = []
1125        children.append(self.expr1)
1126        children.append(self.expr2)
1127        children.append(self.expr3)
1128        return tuple(children)
1129
1130    def getChildNodes(self):
1131        nodelist = []
1132        if self.expr1 is not None:
1133            nodelist.append(self.expr1)
1134        if self.expr2 is not None:
1135            nodelist.append(self.expr2)
1136        if self.expr3 is not None:
1137            nodelist.append(self.expr3)
1138        return tuple(nodelist)
1139
1140    def __repr__(self):
1141        return "Raise(%s, %s, %s)" % (repr(self.expr1), repr(self.expr2), repr(self.expr3))
1142
1143class Return(Node):
1144    def __init__(self, value, lineno=None):
1145        self.value = value
1146        self.lineno = lineno
1147
1148    def getChildren(self):
1149        return self.value,
1150
1151    def getChildNodes(self):
1152        return self.value,
1153
1154    def __repr__(self):
1155        return "Return(%s)" % (repr(self.value),)
1156
1157class RightShift(Node):
1158    def __init__(self, leftright, lineno=None):
1159        self.left = leftright[0]
1160        self.right = leftright[1]
1161        self.lineno = lineno
1162
1163    def getChildren(self):
1164        return self.left, self.right
1165
1166    def getChildNodes(self):
1167        return self.left, self.right
1168
1169    def __repr__(self):
1170        return "RightShift((%s, %s))" % (repr(self.left), repr(self.right))
1171
1172class Set(Node):
1173    def __init__(self, nodes, lineno=None):
1174        self.nodes = nodes
1175        self.lineno = lineno
1176
1177    def getChildren(self):
1178        return tuple(flatten(self.nodes))
1179
1180    def getChildNodes(self):
1181        nodelist = []
1182        nodelist.extend(flatten_nodes(self.nodes))
1183        return tuple(nodelist)
1184
1185    def __repr__(self):
1186        return "Set(%s)" % (repr(self.nodes),)
1187
1188class Slice(Node):
1189    def __init__(self, expr, flags, lower, upper, lineno=None):
1190        self.expr = expr
1191        self.flags = flags
1192        self.lower = lower
1193        self.upper = upper
1194        self.lineno = lineno
1195
1196    def getChildren(self):
1197        children = []
1198        children.append(self.expr)
1199        children.append(self.flags)
1200        children.append(self.lower)
1201        children.append(self.upper)
1202        return tuple(children)
1203
1204    def getChildNodes(self):
1205        nodelist = []
1206        nodelist.append(self.expr)
1207        if self.lower is not None:
1208            nodelist.append(self.lower)
1209        if self.upper is not None:
1210            nodelist.append(self.upper)
1211        return tuple(nodelist)
1212
1213    def __repr__(self):
1214        return "Slice(%s, %s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.lower), repr(self.upper))
1215
1216class Sliceobj(Node):
1217    def __init__(self, nodes, lineno=None):
1218        self.nodes = nodes
1219        self.lineno = lineno
1220
1221    def getChildren(self):
1222        return tuple(flatten(self.nodes))
1223
1224    def getChildNodes(self):
1225        nodelist = []
1226        nodelist.extend(flatten_nodes(self.nodes))
1227        return tuple(nodelist)
1228
1229    def __repr__(self):
1230        return "Sliceobj(%s)" % (repr(self.nodes),)
1231
1232class Stmt(Node):
1233    def __init__(self, nodes, lineno=None):
1234        self.nodes = nodes
1235        self.lineno = lineno
1236
1237    def getChildren(self):
1238        return tuple(flatten(self.nodes))
1239
1240    def getChildNodes(self):
1241        nodelist = []
1242        nodelist.extend(flatten_nodes(self.nodes))
1243        return tuple(nodelist)
1244
1245    def __repr__(self):
1246        return "Stmt(%s)" % (repr(self.nodes),)
1247
1248class Str(Node):
1249    def __init__(self, value, flags):
1250        self.value = value
1251        self.flags = flags
1252
1253    def getChildren(self):
1254        return self.value, self.flags
1255
1256    def getChildNodes(self):
1257        return self.value,
1258
1259    def __repr__(self):
1260        return "Str(%s, %d)" % (self.value, self.flags)
1261
1262class JoinedStr(Node):
1263    def __init__(self, values):
1264        self.values = values
1265
1266    def getChildren(self):
1267        return self.values
1268
1269    def getChildNodes(self):
1270        return self.values
1271
1272    def __repr__(self):
1273        return "JoinedStr(%s)" % (', '.join(repr(value) for value in self.values))
1274
1275class Sub(Node):
1276    def __init__(self, leftright, lineno=None):
1277        self.left = leftright[0]
1278        self.right = leftright[1]
1279        self.lineno = lineno
1280
1281    def getChildren(self):
1282        return self.left, self.right
1283
1284    def getChildNodes(self):
1285        return self.left, self.right
1286
1287    def __repr__(self):
1288        return "Sub((%s, %s))" % (repr(self.left), repr(self.right))
1289
1290class Subscript(Node):
1291    def __init__(self, expr, flags, subs, lineno=None):
1292        self.expr = expr
1293        self.flags = flags
1294        self.subs = subs
1295        self.lineno = lineno
1296
1297    def getChildren(self):
1298        children = []
1299        children.append(self.expr)
1300        children.append(self.flags)
1301        children.extend(flatten(self.subs))
1302        return tuple(children)
1303
1304    def getChildNodes(self):
1305        nodelist = []
1306        nodelist.append(self.expr)
1307        nodelist.extend(flatten_nodes(self.subs))
1308        return tuple(nodelist)
1309
1310    def __repr__(self):
1311        return "Subscript(%s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.subs))
1312
1313class TryExcept(Node):
1314    def __init__(self, body, handlers, else_, lineno=None):
1315        self.body = body
1316        self.handlers = handlers
1317        self.else_ = else_
1318        self.lineno = lineno
1319
1320    def getChildren(self):
1321        children = []
1322        children.append(self.body)
1323        children.extend(flatten(self.handlers))
1324        children.append(self.else_)
1325        return tuple(children)
1326
1327    def getChildNodes(self):
1328        nodelist = []
1329        nodelist.append(self.body)
1330        nodelist.extend(flatten_nodes(self.handlers))
1331        if self.else_ is not None:
1332            nodelist.append(self.else_)
1333        return tuple(nodelist)
1334
1335    def __repr__(self):
1336        return "TryExcept(%s, %s, %s)" % (repr(self.body), repr(self.handlers), repr(self.else_))
1337
1338class TryFinally(Node):
1339    def __init__(self, body, final, lineno=None):
1340        self.body = body
1341        self.final = final
1342        self.lineno = lineno
1343
1344    def getChildren(self):
1345        return self.body, self.final
1346
1347    def getChildNodes(self):
1348        return self.body, self.final
1349
1350    def __repr__(self):
1351        return "TryFinally(%s, %s)" % (repr(self.body), repr(self.final))
1352
1353class Tuple(Node):
1354    def __init__(self, nodes, lineno=None):
1355        self.nodes = nodes
1356        self.lineno = lineno
1357
1358    def getChildren(self):
1359        return tuple(flatten(self.nodes))
1360
1361    def getChildNodes(self):
1362        nodelist = []
1363        nodelist.extend(flatten_nodes(self.nodes))
1364        return tuple(nodelist)
1365
1366    def __repr__(self):
1367        return "Tuple(%s)" % (repr(self.nodes),)
1368
1369class UnaryAdd(Node):
1370    def __init__(self, expr, lineno=None):
1371        self.expr = expr
1372        self.lineno = lineno
1373
1374    def getChildren(self):
1375        return self.expr,
1376
1377    def getChildNodes(self):
1378        return self.expr,
1379
1380    def __repr__(self):
1381        return "UnaryAdd(%s)" % (repr(self.expr),)
1382
1383class UnarySub(Node):
1384    def __init__(self, expr, lineno=None):
1385        self.expr = expr
1386        self.lineno = lineno
1387
1388    def getChildren(self):
1389        return self.expr,
1390
1391    def getChildNodes(self):
1392        return self.expr,
1393
1394    def __repr__(self):
1395        return "UnarySub(%s)" % (repr(self.expr),)
1396
1397class While(Node):
1398    def __init__(self, test, body, else_, lineno=None):
1399        self.test = test
1400        self.body = body
1401        self.else_ = else_
1402        self.lineno = lineno
1403
1404    def getChildren(self):
1405        children = []
1406        children.append(self.test)
1407        children.append(self.body)
1408        children.append(self.else_)
1409        return tuple(children)
1410
1411    def getChildNodes(self):
1412        nodelist = []
1413        nodelist.append(self.test)
1414        nodelist.append(self.body)
1415        if self.else_ is not None:
1416            nodelist.append(self.else_)
1417        return tuple(nodelist)
1418
1419    def __repr__(self):
1420        return "While(%s, %s, %s)" % (repr(self.test), repr(self.body), repr(self.else_))
1421
1422class With(Node):
1423    def __init__(self, expr, vars, body, lineno=None):
1424        self.expr = expr
1425        self.vars = vars
1426        self.body = body
1427        self.lineno = lineno
1428
1429    def getChildren(self):
1430        children = []
1431        children.append(self.expr)
1432        children.append(self.vars)
1433        children.append(self.body)
1434        return tuple(children)
1435
1436    def getChildNodes(self):
1437        nodelist = []
1438        nodelist.append(self.expr)
1439        if self.vars is not None:
1440            nodelist.append(self.vars)
1441        nodelist.append(self.body)
1442        return tuple(nodelist)
1443
1444    def __repr__(self):
1445        return "With(%s, %s, %s)" % (repr(self.expr), repr(self.vars), repr(self.body))
1446
1447class Yield(Node):
1448    def __init__(self, value, lineno=None):
1449        self.value = value
1450        self.lineno = lineno
1451
1452    def getChildren(self):
1453        return self.value,
1454
1455    def getChildNodes(self):
1456        return self.value,
1457
1458    def __repr__(self):
1459        return "Yield(%s)" % (repr(self.value),)
1460
1461for name, obj in items_list(globals()):
1462    if isinstance(obj, type) and issubclass(obj, Node):
1463        nodes[name.lower()] = obj
1464