0001 """Python abstract syntax node definitions 0002 0003 This file is automatically generated by Tools/compiler/astgen.py 0004 """ 0005 from consts import CO_VARARGS, CO_VARKEYWORDS 0006 0007 def flatten(list): 0008 l = [] 0009 for elt in list: 0010 t = type(elt) 0011 if t is tuple or t is list: 0012 for elt2 in flatten(elt): 0013 l.append(elt2) 0014 else: 0015 l.append(elt) 0016 return l 0017 0018 def flatten_nodes(list): 0019 return [n for n in flatten(list) if isinstance(n, Node)] 0020 0021 nodes = {} 0022 0023 class Node: 0024 """Abstract base class for ast nodes.""" 0025 def getChildren(self): 0026 pass # implemented by subclasses 0027 def __iter__(self): 0028 for n in self.getChildren(): 0029 yield n 0030 def asList(self): # for backwards compatibility 0031 return self.getChildren() 0032 def getChildNodes(self): 0033 pass # implemented by subclasses 0034 0035 class EmptyNode(Node): 0036 pass 0037 0038 class Expression(Node): 0039 # Expression is an artificial node class to support "eval" 0040 nodes["expression"] = "Expression" 0041 def __init__(self, node): 0042 self.node = node 0043 0044 def getChildren(self): 0045 return self.node, 0046 0047 def getChildNodes(self): 0048 return self.node, 0049 0050 def __repr__(self): 0051 return "Expression(%s)" % (repr(self.node)) 0052 0053 class Add(Node): 0054 def __init__(self, (left, right), lineno=None): 0055 self.left = left 0056 self.right = right 0057 self.lineno = lineno 0058 0059 def getChildren(self): 0060 return self.left, self.right 0061 0062 def getChildNodes(self): 0063 return self.left, self.right 0064 0065 def __repr__(self): 0066 return "Add((%s, %s))" % (repr(self.left), repr(self.right)) 0067 0068 class And(Node): 0069 def __init__(self, nodes, lineno=None): 0070 self.nodes = nodes 0071 self.lineno = lineno 0072 0073 def getChildren(self): 0074 return tuple(flatten(self.nodes)) 0075 0076 def getChildNodes(self): 0077 nodelist = [] 0078 nodelist.extend(flatten_nodes(self.nodes)) 0079 return tuple(nodelist) 0080 0081 def __repr__(self): 0082 return "And(%s)" % (repr(self.nodes),) 0083 0084 class AssAttr(Node): 0085 def __init__(self, expr, attrname, flags, lineno=None): 0086 self.expr = expr 0087 self.attrname = attrname 0088 self.flags = flags 0089 self.lineno = lineno 0090 0091 def getChildren(self): 0092 return self.expr, self.attrname, self.flags 0093 0094 def getChildNodes(self): 0095 return self.expr, 0096 0097 def __repr__(self): 0098 return "AssAttr(%s, %s, %s)" % (repr(self.expr), repr(self.attrname), repr(self.flags)) 0099 0100 class AssList(Node): 0101 def __init__(self, nodes, lineno=None): 0102 self.nodes = nodes 0103 self.lineno = lineno 0104 0105 def getChildren(self): 0106 return tuple(flatten(self.nodes)) 0107 0108 def getChildNodes(self): 0109 nodelist = [] 0110 nodelist.extend(flatten_nodes(self.nodes)) 0111 return tuple(nodelist) 0112 0113 def __repr__(self): 0114 return "AssList(%s)" % (repr(self.nodes),) 0115 0116 class AssName(Node): 0117 def __init__(self, name, flags, lineno=None): 0118 self.name = name 0119 self.flags = flags 0120 self.lineno = lineno 0121 0122 def getChildren(self): 0123 return self.name, self.flags 0124 0125 def getChildNodes(self): 0126 return () 0127 0128 def __repr__(self): 0129 return "AssName(%s, %s)" % (repr(self.name), repr(self.flags)) 0130 0131 class AssTuple(Node): 0132 def __init__(self, nodes, lineno=None): 0133 self.nodes = nodes 0134 self.lineno = lineno 0135 0136 def getChildren(self): 0137 return tuple(flatten(self.nodes)) 0138 0139 def getChildNodes(self): 0140 nodelist = [] 0141 nodelist.extend(flatten_nodes(self.nodes)) 0142 return tuple(nodelist) 0143 0144 def __repr__(self): 0145 return "AssTuple(%s)" % (repr(self.nodes),) 0146 0147 class Assert(Node): 0148 def __init__(self, test, fail, lineno=None): 0149 self.test = test 0150 self.fail = fail 0151 self.lineno = lineno 0152 0153 def getChildren(self): 0154 children = [] 0155 children.append(self.test) 0156 children.append(self.fail) 0157 return tuple(children) 0158 0159 def getChildNodes(self): 0160 nodelist = [] 0161 nodelist.append(self.test) 0162 if self.fail is not None: 0163 nodelist.append(self.fail) 0164 return tuple(nodelist) 0165 0166 def __repr__(self): 0167 return "Assert(%s, %s)" % (repr(self.test), repr(self.fail)) 0168 0169 class Assign(Node): 0170 def __init__(self, nodes, expr, lineno=None): 0171 self.nodes = nodes 0172 self.expr = expr 0173 self.lineno = lineno 0174 0175 def getChildren(self): 0176 children = [] 0177 children.extend(flatten(self.nodes)) 0178 children.append(self.expr) 0179 return tuple(children) 0180 0181 def getChildNodes(self): 0182 nodelist = [] 0183 nodelist.extend(flatten_nodes(self.nodes)) 0184 nodelist.append(self.expr) 0185 return tuple(nodelist) 0186 0187 def __repr__(self): 0188 return "Assign(%s, %s)" % (repr(self.nodes), repr(self.expr)) 0189 0190 class AugAssign(Node): 0191 def __init__(self, node, op, expr, lineno=None): 0192 self.node = node 0193 self.op = op 0194 self.expr = expr 0195 self.lineno = lineno 0196 0197 def getChildren(self): 0198 return self.node, self.op, self.expr 0199 0200 def getChildNodes(self): 0201 return self.node, self.expr 0202 0203 def __repr__(self): 0204 return "AugAssign(%s, %s, %s)" % (repr(self.node), repr(self.op), repr(self.expr)) 0205 0206 class Backquote(Node): 0207 def __init__(self, expr, lineno=None): 0208 self.expr = expr 0209 self.lineno = lineno 0210 0211 def getChildren(self): 0212 return self.expr, 0213 0214 def getChildNodes(self): 0215 return self.expr, 0216 0217 def __repr__(self): 0218 return "Backquote(%s)" % (repr(self.expr),) 0219 0220 class Bitand(Node): 0221 def __init__(self, nodes, lineno=None): 0222 self.nodes = nodes 0223 self.lineno = lineno 0224 0225 def getChildren(self): 0226 return tuple(flatten(self.nodes)) 0227 0228 def getChildNodes(self): 0229 nodelist = [] 0230 nodelist.extend(flatten_nodes(self.nodes)) 0231 return tuple(nodelist) 0232 0233 def __repr__(self): 0234 return "Bitand(%s)" % (repr(self.nodes),) 0235 0236 class Bitor(Node): 0237 def __init__(self, nodes, lineno=None): 0238 self.nodes = nodes 0239 self.lineno = lineno 0240 0241 def getChildren(self): 0242 return tuple(flatten(self.nodes)) 0243 0244 def getChildNodes(self): 0245 nodelist = [] 0246 nodelist.extend(flatten_nodes(self.nodes)) 0247 return tuple(nodelist) 0248 0249 def __repr__(self): 0250 return "Bitor(%s)" % (repr(self.nodes),) 0251 0252 class Bitxor(Node): 0253 def __init__(self, nodes, lineno=None): 0254 self.nodes = nodes 0255 self.lineno = lineno 0256 0257 def getChildren(self): 0258 return tuple(flatten(self.nodes)) 0259 0260 def getChildNodes(self): 0261 nodelist = [] 0262 nodelist.extend(flatten_nodes(self.nodes)) 0263 return tuple(nodelist) 0264 0265 def __repr__(self): 0266 return "Bitxor(%s)" % (repr(self.nodes),) 0267 0268 class Break(Node): 0269 def __init__(self, lineno=None): 0270 self.lineno = lineno 0271 0272 def getChildren(self): 0273 return () 0274 0275 def getChildNodes(self): 0276 return () 0277 0278 def __repr__(self): 0279 return "Break()" 0280 0281 class CallFunc(Node): 0282 def __init__(self, node, args, star_args = None, dstar_args = None, lineno=None): 0283 self.node = node 0284 self.args = args 0285 self.star_args = star_args 0286 self.dstar_args = dstar_args 0287 self.lineno = lineno 0288 0289 def getChildren(self): 0290 children = [] 0291 children.append(self.node) 0292 children.extend(flatten(self.args)) 0293 children.append(self.star_args) 0294 children.append(self.dstar_args) 0295 return tuple(children) 0296 0297 def getChildNodes(self): 0298 nodelist = [] 0299 nodelist.append(self.node) 0300 nodelist.extend(flatten_nodes(self.args)) 0301 if self.star_args is not None: 0302 nodelist.append(self.star_args) 0303 if self.dstar_args is not None: 0304 nodelist.append(self.dstar_args) 0305 return tuple(nodelist) 0306 0307 def __repr__(self): 0308 return "CallFunc(%s, %s, %s, %s)" % (repr(self.node), repr(self.args), repr(self.star_args), repr(self.dstar_args)) 0309 0310 class Class(Node): 0311 def __init__(self, name, bases, doc, code, lineno=None): 0312 self.name = name 0313 self.bases = bases 0314 self.doc = doc 0315 self.code = code 0316 self.lineno = lineno 0317 0318 def getChildren(self): 0319 children = [] 0320 children.append(self.name) 0321 children.extend(flatten(self.bases)) 0322 children.append(self.doc) 0323 children.append(self.code) 0324 return tuple(children) 0325 0326 def getChildNodes(self): 0327 nodelist = [] 0328 nodelist.extend(flatten_nodes(self.bases)) 0329 nodelist.append(self.code) 0330 return tuple(nodelist) 0331 0332 def __repr__(self): 0333 return "Class(%s, %s, %s, %s)" % (repr(self.name), repr(self.bases), repr(self.doc), repr(self.code)) 0334 0335 class Compare(Node): 0336 def __init__(self, expr, ops, lineno=None): 0337 self.expr = expr 0338 self.ops = ops 0339 self.lineno = lineno 0340 0341 def getChildren(self): 0342 children = [] 0343 children.append(self.expr) 0344 children.extend(flatten(self.ops)) 0345 return tuple(children) 0346 0347 def getChildNodes(self): 0348 nodelist = [] 0349 nodelist.append(self.expr) 0350 nodelist.extend(flatten_nodes(self.ops)) 0351 return tuple(nodelist) 0352 0353 def __repr__(self): 0354 return "Compare(%s, %s)" % (repr(self.expr), repr(self.ops)) 0355 0356 class Const(Node): 0357 def __init__(self, value, lineno=None): 0358 self.value = value 0359 self.lineno = lineno 0360 0361 def getChildren(self): 0362 return self.value, 0363 0364 def getChildNodes(self): 0365 return () 0366 0367 def __repr__(self): 0368 return "Const(%s)" % (repr(self.value),) 0369 0370 class Continue(Node): 0371 def __init__(self, lineno=None): 0372 self.lineno = lineno 0373 0374 def getChildren(self): 0375 return () 0376 0377 def getChildNodes(self): 0378 return () 0379 0380 def __repr__(self): 0381 return "Continue()" 0382 0383 class Decorators(Node): 0384 def __init__(self, nodes, lineno=None): 0385 self.nodes = nodes 0386 self.lineno = lineno 0387 0388 def getChildren(self): 0389 return tuple(flatten(self.nodes)) 0390 0391 def getChildNodes(self): 0392 nodelist = [] 0393 nodelist.extend(flatten_nodes(self.nodes)) 0394 return tuple(nodelist) 0395 0396 def __repr__(self): 0397 return "Decorators(%s)" % (repr(self.nodes),) 0398 0399 class Dict(Node): 0400 def __init__(self, items, lineno=None): 0401 self.items = items 0402 self.lineno = lineno 0403 0404 def getChildren(self): 0405 return tuple(flatten(self.items)) 0406 0407 def getChildNodes(self): 0408 nodelist = [] 0409 nodelist.extend(flatten_nodes(self.items)) 0410 return tuple(nodelist) 0411 0412 def __repr__(self): 0413 return "Dict(%s)" % (repr(self.items),) 0414 0415 class Discard(Node): 0416 def __init__(self, expr, lineno=None): 0417 self.expr = expr 0418 self.lineno = lineno 0419 0420 def getChildren(self): 0421 return self.expr, 0422 0423 def getChildNodes(self): 0424 return self.expr, 0425 0426 def __repr__(self): 0427 return "Discard(%s)" % (repr(self.expr),) 0428 0429 class Div(Node): 0430 def __init__(self, (left, right), lineno=None): 0431 self.left = left 0432 self.right = right 0433 self.lineno = lineno 0434 0435 def getChildren(self): 0436 return self.left, self.right 0437 0438 def getChildNodes(self): 0439 return self.left, self.right 0440 0441 def __repr__(self): 0442 return "Div((%s, %s))" % (repr(self.left), repr(self.right)) 0443 0444 class Ellipsis(Node): 0445 def __init__(self, lineno=None): 0446 self.lineno = lineno 0447 0448 def getChildren(self): 0449 return () 0450 0451 def getChildNodes(self): 0452 return () 0453 0454 def __repr__(self): 0455 return "Ellipsis()" 0456 0457 class Exec(Node): 0458 def __init__(self, expr, locals, globals, lineno=None): 0459 self.expr = expr 0460 self.locals = locals 0461 self.globals = globals 0462 self.lineno = lineno 0463 0464 def getChildren(self): 0465 children = [] 0466 children.append(self.expr) 0467 children.append(self.locals) 0468 children.append(self.globals) 0469 return tuple(children) 0470 0471 def getChildNodes(self): 0472 nodelist = [] 0473 nodelist.append(self.expr) 0474 if self.locals is not None: 0475 nodelist.append(self.locals) 0476 if self.globals is not None: 0477 nodelist.append(self.globals) 0478 return tuple(nodelist) 0479 0480 def __repr__(self): 0481 return "Exec(%s, %s, %s)" % (repr(self.expr), repr(self.locals), repr(self.globals)) 0482 0483 class FloorDiv(Node): 0484 def __init__(self, (left, right), lineno=None): 0485 self.left = left 0486 self.right = right 0487 self.lineno = lineno 0488 0489 def getChildren(self): 0490 return self.left, self.right 0491 0492 def getChildNodes(self): 0493 return self.left, self.right 0494 0495 def __repr__(self): 0496 return "FloorDiv((%s, %s))" % (repr(self.left), repr(self.right)) 0497 0498 class For(Node): 0499 def __init__(self, assign, list, body, else_, lineno=None): 0500 self.assign = assign 0501 self.list = list 0502 self.body = body 0503 self.else_ = else_ 0504 self.lineno = lineno 0505 0506 def getChildren(self): 0507 children = [] 0508 children.append(self.assign) 0509 children.append(self.list) 0510 children.append(self.body) 0511 children.append(self.else_) 0512 return tuple(children) 0513 0514 def getChildNodes(self): 0515 nodelist = [] 0516 nodelist.append(self.assign) 0517 nodelist.append(self.list) 0518 nodelist.append(self.body) 0519 if self.else_ is not None: 0520 nodelist.append(self.else_) 0521 return tuple(nodelist) 0522 0523 def __repr__(self): 0524 return "For(%s, %s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.body), repr(self.else_)) 0525 0526 class From(Node): 0527 def __init__(self, modname, names, lineno=None): 0528 self.modname = modname 0529 self.names = names 0530 self.lineno = lineno 0531 0532 def getChildren(self): 0533 return self.modname, self.names 0534 0535 def getChildNodes(self): 0536 return () 0537 0538 def __repr__(self): 0539 return "From(%s, %s)" % (repr(self.modname), repr(self.names)) 0540 0541 class Function(Node): 0542 def __init__(self, decorators, name, argnames, defaults, flags, doc, code, lineno=None): 0543 self.decorators = decorators 0544 self.name = name 0545 self.argnames = argnames 0546 self.defaults = defaults 0547 self.flags = flags 0548 self.doc = doc 0549 self.code = code 0550 self.lineno = lineno 0551 self.varargs = self.kwargs = None 0552 if flags & CO_VARARGS: 0553 self.varargs = 1 0554 if flags & CO_VARKEYWORDS: 0555 self.kwargs = 1 0556 0557 0558 0559 def getChildren(self): 0560 children = [] 0561 children.append(self.decorators) 0562 children.append(self.name) 0563 children.append(self.argnames) 0564 children.extend(flatten(self.defaults)) 0565 children.append(self.flags) 0566 children.append(self.doc) 0567 children.append(self.code) 0568 return tuple(children) 0569 0570 def getChildNodes(self): 0571 nodelist = [] 0572 if self.decorators is not None: 0573 nodelist.append(self.decorators) 0574 nodelist.extend(flatten_nodes(self.defaults)) 0575 nodelist.append(self.code) 0576 return tuple(nodelist) 0577 0578 def __repr__(self): 0579 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)) 0580 0581 class GenExpr(Node): 0582 def __init__(self, code, lineno=None): 0583 self.code = code 0584 self.lineno = lineno 0585 self.argnames = ['[outmost-iterable]'] 0586 self.varargs = self.kwargs = None 0587 0588 0589 0590 def getChildren(self): 0591 return self.code, 0592 0593 def getChildNodes(self): 0594 return self.code, 0595 0596 def __repr__(self): 0597 return "GenExpr(%s)" % (repr(self.code),) 0598 0599 class GenExprFor(Node): 0600 def __init__(self, assign, iter, ifs, lineno=None): 0601 self.assign = assign 0602 self.iter = iter 0603 self.ifs = ifs 0604 self.lineno = lineno 0605 self.is_outmost = False 0606 0607 0608 def getChildren(self): 0609 children = [] 0610 children.append(self.assign) 0611 children.append(self.iter) 0612 children.extend(flatten(self.ifs)) 0613 return tuple(children) 0614 0615 def getChildNodes(self): 0616 nodelist = [] 0617 nodelist.append(self.assign) 0618 nodelist.append(self.iter) 0619 nodelist.extend(flatten_nodes(self.ifs)) 0620 return tuple(nodelist) 0621 0622 def __repr__(self): 0623 return "GenExprFor(%s, %s, %s)" % (repr(self.assign), repr(self.iter), repr(self.ifs)) 0624 0625 class GenExprIf(Node): 0626 def __init__(self, test, lineno=None): 0627 self.test = test 0628 self.lineno = lineno 0629 0630 def getChildren(self): 0631 return self.test, 0632 0633 def getChildNodes(self): 0634 return self.test, 0635 0636 def __repr__(self): 0637 return "GenExprIf(%s)" % (repr(self.test),) 0638 0639 class GenExprInner(Node): 0640 def __init__(self, expr, quals, lineno=None): 0641 self.expr = expr 0642 self.quals = quals 0643 self.lineno = lineno 0644 0645 def getChildren(self): 0646 children = [] 0647 children.append(self.expr) 0648 children.extend(flatten(self.quals)) 0649 return tuple(children) 0650 0651 def getChildNodes(self): 0652 nodelist = [] 0653 nodelist.append(self.expr) 0654 nodelist.extend(flatten_nodes(self.quals)) 0655 return tuple(nodelist) 0656 0657 def __repr__(self): 0658 return "GenExprInner(%s, %s)" % (repr(self.expr), repr(self.quals)) 0659 0660 class Getattr(Node): 0661 def __init__(self, expr, attrname, lineno=None): 0662 self.expr = expr 0663 self.attrname = attrname 0664 self.lineno = lineno 0665 0666 def getChildren(self): 0667 return self.expr, self.attrname 0668 0669 def getChildNodes(self): 0670 return self.expr, 0671 0672 def __repr__(self): 0673 return "Getattr(%s, %s)" % (repr(self.expr), repr(self.attrname)) 0674 0675 class Global(Node): 0676 def __init__(self, names, lineno=None): 0677 self.names = names 0678 self.lineno = lineno 0679 0680 def getChildren(self): 0681 return self.names, 0682 0683 def getChildNodes(self): 0684 return () 0685 0686 def __repr__(self): 0687 return "Global(%s)" % (repr(self.names),) 0688 0689 class If(Node): 0690 def __init__(self, tests, else_, lineno=None): 0691 self.tests = tests 0692 self.else_ = else_ 0693 self.lineno = lineno 0694 0695 def getChildren(self): 0696 children = [] 0697 children.extend(flatten(self.tests)) 0698 children.append(self.else_) 0699 return tuple(children) 0700 0701 def getChildNodes(self): 0702 nodelist = [] 0703 nodelist.extend(flatten_nodes(self.tests)) 0704 if self.else_ is not None: 0705 nodelist.append(self.else_) 0706 return tuple(nodelist) 0707 0708 def __repr__(self): 0709 return "If(%s, %s)" % (repr(self.tests), repr(self.else_)) 0710 0711 class Import(Node): 0712 def __init__(self, names, lineno=None): 0713 self.names = names 0714 self.lineno = lineno 0715 0716 def getChildren(self): 0717 return self.names, 0718 0719 def getChildNodes(self): 0720 return () 0721 0722 def __repr__(self): 0723 return "Import(%s)" % (repr(self.names),) 0724 0725 class Invert(Node): 0726 def __init__(self, expr, lineno=None): 0727 self.expr = expr 0728 self.lineno = lineno 0729 0730 def getChildren(self): 0731 return self.expr, 0732 0733 def getChildNodes(self): 0734 return self.expr, 0735 0736 def __repr__(self): 0737 return "Invert(%s)" % (repr(self.expr),) 0738 0739 class Keyword(Node): 0740 def __init__(self, name, expr, lineno=None): 0741 self.name = name 0742 self.expr = expr 0743 self.lineno = lineno 0744 0745 def getChildren(self): 0746 return self.name, self.expr 0747 0748 def getChildNodes(self): 0749 return self.expr, 0750 0751 def __repr__(self): 0752 return "Keyword(%s, %s)" % (repr(self.name), repr(self.expr)) 0753 0754 class Lambda(Node): 0755 def __init__(self, argnames, defaults, flags, code, lineno=None): 0756 self.argnames = argnames 0757 self.defaults = defaults 0758 self.flags = flags 0759 self.code = code 0760 self.lineno = lineno 0761 self.varargs = self.kwargs = None 0762 if flags & CO_VARARGS: 0763 self.varargs = 1 0764 if flags & CO_VARKEYWORDS: 0765 self.kwargs = 1 0766 0767 0768 0769 def getChildren(self): 0770 children = [] 0771 children.append(self.argnames) 0772 children.extend(flatten(self.defaults)) 0773 children.append(self.flags) 0774 children.append(self.code) 0775 return tuple(children) 0776 0777 def getChildNodes(self): 0778 nodelist = [] 0779 nodelist.extend(flatten_nodes(self.defaults)) 0780 nodelist.append(self.code) 0781 return tuple(nodelist) 0782 0783 def __repr__(self): 0784 return "Lambda(%s, %s, %s, %s)" % (repr(self.argnames), repr(self.defaults), repr(self.flags), repr(self.code)) 0785 0786 class LeftShift(Node): 0787 def __init__(self, (left, right), lineno=None): 0788 self.left = left 0789 self.right = right 0790 self.lineno = lineno 0791 0792 def getChildren(self): 0793 return self.left, self.right 0794 0795 def getChildNodes(self): 0796 return self.left, self.right 0797 0798 def __repr__(self): 0799 return "LeftShift((%s, %s))" % (repr(self.left), repr(self.right)) 0800 0801 class List(Node): 0802 def __init__(self, nodes, lineno=None): 0803 self.nodes = nodes 0804 self.lineno = lineno 0805 0806 def getChildren(self): 0807 return tuple(flatten(self.nodes)) 0808 0809 def getChildNodes(self): 0810 nodelist = [] 0811 nodelist.extend(flatten_nodes(self.nodes)) 0812 return tuple(nodelist) 0813 0814 def __repr__(self): 0815 return "List(%s)" % (repr(self.nodes),) 0816 0817 class ListComp(Node): 0818 def __init__(self, expr, quals, lineno=None): 0819 self.expr = expr 0820 self.quals = quals 0821 self.lineno = lineno 0822 0823 def getChildren(self): 0824 children = [] 0825 children.append(self.expr) 0826 children.extend(flatten(self.quals)) 0827 return tuple(children) 0828 0829 def getChildNodes(self): 0830 nodelist = [] 0831 nodelist.append(self.expr) 0832 nodelist.extend(flatten_nodes(self.quals)) 0833 return tuple(nodelist) 0834 0835 def __repr__(self): 0836 return "ListComp(%s, %s)" % (repr(self.expr), repr(self.quals)) 0837 0838 class ListCompFor(Node): 0839 def __init__(self, assign, list, ifs, lineno=None): 0840 self.assign = assign 0841 self.list = list 0842 self.ifs = ifs 0843 self.lineno = lineno 0844 0845 def getChildren(self): 0846 children = [] 0847 children.append(self.assign) 0848 children.append(self.list) 0849 children.extend(flatten(self.ifs)) 0850 return tuple(children) 0851 0852 def getChildNodes(self): 0853 nodelist = [] 0854 nodelist.append(self.assign) 0855 nodelist.append(self.list) 0856 nodelist.extend(flatten_nodes(self.ifs)) 0857 return tuple(nodelist) 0858 0859 def __repr__(self): 0860 return "ListCompFor(%s, %s, %s)" % (repr(self.assign), repr(self.list), repr(self.ifs)) 0861 0862 class ListCompIf(Node): 0863 def __init__(self, test, lineno=None): 0864 self.test = test 0865 self.lineno = lineno 0866 0867 def getChildren(self): 0868 return self.test, 0869 0870 def getChildNodes(self): 0871 return self.test, 0872 0873 def __repr__(self): 0874 return "ListCompIf(%s)" % (repr(self.test),) 0875 0876 class Mod(Node): 0877 def __init__(self, (left, right), lineno=None): 0878 self.left = left 0879 self.right = right 0880 self.lineno = lineno 0881 0882 def getChildren(self): 0883 return self.left, self.right 0884 0885 def getChildNodes(self): 0886 return self.left, self.right 0887 0888 def __repr__(self): 0889 return "Mod((%s, %s))" % (repr(self.left), repr(self.right)) 0890 0891 class Module(Node): 0892 def __init__(self, doc, node, lineno=None): 0893 self.doc = doc 0894 self.node = node 0895 self.lineno = lineno 0896 0897 def getChildren(self): 0898 return self.doc, self.node 0899 0900 def getChildNodes(self): 0901 return self.node, 0902 0903 def __repr__(self): 0904 return "Module(%s, %s)" % (repr(self.doc), repr(self.node)) 0905 0906 class Mul(Node): 0907 def __init__(self, (left, right), lineno=None): 0908 self.left = left 0909 self.right = right 0910 self.lineno = lineno 0911 0912 def getChildren(self): 0913 return self.left, self.right 0914 0915 def getChildNodes(self): 0916 return self.left, self.right 0917 0918 def __repr__(self): 0919 return "Mul((%s, %s))" % (repr(self.left), repr(self.right)) 0920 0921 class Name(Node): 0922 def __init__(self, name, lineno=None): 0923 self.name = name 0924 self.lineno = lineno 0925 0926 def getChildren(self): 0927 return self.name, 0928 0929 def getChildNodes(self): 0930 return () 0931 0932 def __repr__(self): 0933 return "Name(%s)" % (repr(self.name),) 0934 0935 class Not(Node): 0936 def __init__(self, expr, lineno=None): 0937 self.expr = expr 0938 self.lineno = lineno 0939 0940 def getChildren(self): 0941 return self.expr, 0942 0943 def getChildNodes(self): 0944 return self.expr, 0945 0946 def __repr__(self): 0947 return "Not(%s)" % (repr(self.expr),) 0948 0949 class Or(Node): 0950 def __init__(self, nodes, lineno=None): 0951 self.nodes = nodes 0952 self.lineno = lineno 0953 0954 def getChildren(self): 0955 return tuple(flatten(self.nodes)) 0956 0957 def getChildNodes(self): 0958 nodelist = [] 0959 nodelist.extend(flatten_nodes(self.nodes)) 0960 return tuple(nodelist) 0961 0962 def __repr__(self): 0963 return "Or(%s)" % (repr(self.nodes),) 0964 0965 class Pass(Node): 0966 def __init__(self, lineno=None): 0967 self.lineno = lineno 0968 0969 def getChildren(self): 0970 return () 0971 0972 def getChildNodes(self): 0973 return () 0974 0975 def __repr__(self): 0976 return "Pass()" 0977 0978 class Power(Node): 0979 def __init__(self, (left, right), lineno=None): 0980 self.left = left 0981 self.right = right 0982 self.lineno = lineno 0983 0984 def getChildren(self): 0985 return self.left, self.right 0986 0987 def getChildNodes(self): 0988 return self.left, self.right 0989 0990 def __repr__(self): 0991 return "Power((%s, %s))" % (repr(self.left), repr(self.right)) 0992 0993 class Print(Node): 0994 def __init__(self, nodes, dest, lineno=None): 0995 self.nodes = nodes 0996 self.dest = dest 0997 self.lineno = lineno 0998 0999 def getChildren(self): 1000 children = [] 1001 children.extend(flatten(self.nodes)) 1002 children.append(self.dest) 1003 return tuple(children) 1004 1005 def getChildNodes(self): 1006 nodelist = [] 1007 nodelist.extend(flatten_nodes(self.nodes)) 1008 if self.dest is not None: 1009 nodelist.append(self.dest) 1010 return tuple(nodelist) 1011 1012 def __repr__(self): 1013 return "Print(%s, %s)" % (repr(self.nodes), repr(self.dest)) 1014 1015 class Printnl(Node): 1016 def __init__(self, nodes, dest, lineno=None): 1017 self.nodes = nodes 1018 self.dest = dest 1019 self.lineno = lineno 1020 1021 def getChildren(self): 1022 children = [] 1023 children.extend(flatten(self.nodes)) 1024 children.append(self.dest) 1025 return tuple(children) 1026 1027 def getChildNodes(self): 1028 nodelist = [] 1029 nodelist.extend(flatten_nodes(self.nodes)) 1030 if self.dest is not None: 1031 nodelist.append(self.dest) 1032 return tuple(nodelist) 1033 1034 def __repr__(self): 1035 return "Printnl(%s, %s)" % (repr(self.nodes), repr(self.dest)) 1036 1037 class Raise(Node): 1038 def __init__(self, expr1, expr2, expr3, lineno=None): 1039 self.expr1 = expr1 1040 self.expr2 = expr2 1041 self.expr3 = expr3 1042 self.lineno = lineno 1043 1044 def getChildren(self): 1045 children = [] 1046 children.append(self.expr1) 1047 children.append(self.expr2) 1048 children.append(self.expr3) 1049 return tuple(children) 1050 1051 def getChildNodes(self): 1052 nodelist = [] 1053 if self.expr1 is not None: 1054 nodelist.append(self.expr1) 1055 if self.expr2 is not None: 1056 nodelist.append(self.expr2) 1057 if self.expr3 is not None: 1058 nodelist.append(self.expr3) 1059 return tuple(nodelist) 1060 1061 def __repr__(self): 1062 return "Raise(%s, %s, %s)" % (repr(self.expr1), repr(self.expr2), repr(self.expr3)) 1063 1064 class Return(Node): 1065 def __init__(self, value, lineno=None): 1066 self.value = value 1067 self.lineno = lineno 1068 1069 def getChildren(self): 1070 return self.value, 1071 1072 def getChildNodes(self): 1073 return self.value, 1074 1075 def __repr__(self): 1076 return "Return(%s)" % (repr(self.value),) 1077 1078 class RightShift(Node): 1079 def __init__(self, (left, right), lineno=None): 1080 self.left = left 1081 self.right = right 1082 self.lineno = lineno 1083 1084 def getChildren(self): 1085 return self.left, self.right 1086 1087 def getChildNodes(self): 1088 return self.left, self.right 1089 1090 def __repr__(self): 1091 return "RightShift((%s, %s))" % (repr(self.left), repr(self.right)) 1092 1093 class Slice(Node): 1094 def __init__(self, expr, flags, lower, upper, lineno=None): 1095 self.expr = expr 1096 self.flags = flags 1097 self.lower = lower 1098 self.upper = upper 1099 self.lineno = lineno 1100 1101 def getChildren(self): 1102 children = [] 1103 children.append(self.expr) 1104 children.append(self.flags) 1105 children.append(self.lower) 1106 children.append(self.upper) 1107 return tuple(children) 1108 1109 def getChildNodes(self): 1110 nodelist = [] 1111 nodelist.append(self.expr) 1112 if self.lower is not None: 1113 nodelist.append(self.lower) 1114 if self.upper is not None: 1115 nodelist.append(self.upper) 1116 return tuple(nodelist) 1117 1118 def __repr__(self): 1119 return "Slice(%s, %s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.lower), repr(self.upper)) 1120 1121 class Sliceobj(Node): 1122 def __init__(self, nodes, lineno=None): 1123 self.nodes = nodes 1124 self.lineno = lineno 1125 1126 def getChildren(self): 1127 return tuple(flatten(self.nodes)) 1128 1129 def getChildNodes(self): 1130 nodelist = [] 1131 nodelist.extend(flatten_nodes(self.nodes)) 1132 return tuple(nodelist) 1133 1134 def __repr__(self): 1135 return "Sliceobj(%s)" % (repr(self.nodes),) 1136 1137 class Stmt(Node): 1138 def __init__(self, nodes, lineno=None): 1139 self.nodes = nodes 1140 self.lineno = lineno 1141 1142 def getChildren(self): 1143 return tuple(flatten(self.nodes)) 1144 1145 def getChildNodes(self): 1146 nodelist = [] 1147 nodelist.extend(flatten_nodes(self.nodes)) 1148 return tuple(nodelist) 1149 1150 def __repr__(self): 1151 return "Stmt(%s)" % (repr(self.nodes),) 1152 1153 class Sub(Node): 1154 def __init__(self, (left, right), lineno=None): 1155 self.left = left 1156 self.right = right 1157 self.lineno = lineno 1158 1159 def getChildren(self): 1160 return self.left, self.right 1161 1162 def getChildNodes(self): 1163 return self.left, self.right 1164 1165 def __repr__(self): 1166 return "Sub((%s, %s))" % (repr(self.left), repr(self.right)) 1167 1168 class Subscript(Node): 1169 def __init__(self, expr, flags, subs, lineno=None): 1170 self.expr = expr 1171 self.flags = flags 1172 self.subs = subs 1173 self.lineno = lineno 1174 1175 def getChildren(self): 1176 children = [] 1177 children.append(self.expr) 1178 children.append(self.flags) 1179 children.extend(flatten(self.subs)) 1180 return tuple(children) 1181 1182 def getChildNodes(self): 1183 nodelist = [] 1184 nodelist.append(self.expr) 1185 nodelist.extend(flatten_nodes(self.subs)) 1186 return tuple(nodelist) 1187 1188 def __repr__(self): 1189 return "Subscript(%s, %s, %s)" % (repr(self.expr), repr(self.flags), repr(self.subs)) 1190 1191 class TryExcept(Node): 1192 def __init__(self, body, handlers, else_, lineno=None): 1193 self.body = body 1194 self.handlers = handlers 1195 self.else_ = else_ 1196 self.lineno = lineno 1197 1198 def getChildren(self): 1199 children = [] 1200 children.append(self.body) 1201 children.extend(flatten(self.handlers)) 1202 children.append(self.else_) 1203 return tuple(children) 1204 1205 def getChildNodes(self): 1206 nodelist = [] 1207 nodelist.append(self.body) 1208 nodelist.extend(flatten_nodes(self.handlers)) 1209 if self.else_ is not None: 1210 nodelist.append(self.else_) 1211 return tuple(nodelist) 1212 1213 def __repr__(self): 1214 return "TryExcept(%s, %s, %s)" % (repr(self.body), repr(self.handlers), repr(self.else_)) 1215 1216 class TryFinally(Node): 1217 def __init__(self, body, final, lineno=None): 1218 self.body = body 1219 self.final = final 1220 self.lineno = lineno 1221 1222 def getChildren(self): 1223 return self.body, self.final 1224 1225 def getChildNodes(self): 1226 return self.body, self.final 1227 1228 def __repr__(self): 1229 return "TryFinally(%s, %s)" % (repr(self.body), repr(self.final)) 1230 1231 class Tuple(Node): 1232 def __init__(self, nodes, lineno=None): 1233 self.nodes = nodes 1234 self.lineno = lineno 1235 1236 def getChildren(self): 1237 return tuple(flatten(self.nodes)) 1238 1239 def getChildNodes(self): 1240 nodelist = [] 1241 nodelist.extend(flatten_nodes(self.nodes)) 1242 return tuple(nodelist) 1243 1244 def __repr__(self): 1245 return "Tuple(%s)" % (repr(self.nodes),) 1246 1247 class UnaryAdd(Node): 1248 def __init__(self, expr, lineno=None): 1249 self.expr = expr 1250 self.lineno = lineno 1251 1252 def getChildren(self): 1253 return self.expr, 1254 1255 def getChildNodes(self): 1256 return self.expr, 1257 1258 def __repr__(self): 1259 return "UnaryAdd(%s)" % (repr(self.expr),) 1260 1261 class UnarySub(Node): 1262 def __init__(self, expr, lineno=None): 1263 self.expr = expr 1264 self.lineno = lineno 1265 1266 def getChildren(self): 1267 return self.expr, 1268 1269 def getChildNodes(self): 1270 return self.expr, 1271 1272 def __repr__(self): 1273 return "UnarySub(%s)" % (repr(self.expr),) 1274 1275 class While(Node): 1276 def __init__(self, test, body, else_, lineno=None): 1277 self.test = test 1278 self.body = body 1279 self.else_ = else_ 1280 self.lineno = lineno 1281 1282 def getChildren(self): 1283 children = [] 1284 children.append(self.test) 1285 children.append(self.body) 1286 children.append(self.else_) 1287 return tuple(children) 1288 1289 def getChildNodes(self): 1290 nodelist = [] 1291 nodelist.append(self.test) 1292 nodelist.append(self.body) 1293 if self.else_ is not None: 1294 nodelist.append(self.else_) 1295 return tuple(nodelist) 1296 1297 def __repr__(self): 1298 return "While(%s, %s, %s)" % (repr(self.test), repr(self.body), repr(self.else_)) 1299 1300 class Yield(Node): 1301 def __init__(self, value, lineno=None): 1302 self.value = value 1303 self.lineno = lineno 1304 1305 def getChildren(self): 1306 return self.value, 1307 1308 def getChildNodes(self): 1309 return self.value, 1310 1311 def __repr__(self): 1312 return "Yield(%s)" % (repr(self.value),) 1313 1314 for name, obj in globals().items(): 1315 if isinstance(obj, type) and issubclass(obj, Node): 1316 nodes[name.lower()] = obj 1317
Generated by PyXR 0.9.4