<s> """<STR_LIT>""" <EOL> from ast import * <EOL> parser = None <EOL> import symbol <EOL> import token <EOL> import sys <EOL> error = '<STR_LIT>' <EOL> from consts import CO_VARARGS , CO_VARKEYWORDS <EOL> from consts import OP_ASSIGN , OP_DELETE , OP_APPLY <EOL> def parseFile ( path ) : <EOL> f = open ( path ) <EOL> src = f . read ( ) + "<STR_LIT:\n>" <EOL> f . close ( ) <EOL> return parse ( src ) <EOL> def parse ( buf , mode = "<STR_LIT>" ) : <EOL> if mode == "<STR_LIT>" or mode == "<STR_LIT>" : <EOL> return Transformer ( ) . parsesuite ( buf ) <EOL> elif mode == "<STR_LIT>" : <EOL> return Transformer ( ) . parseexpr ( buf ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def asList ( nodes ) : <EOL> l = [ ] <EOL> for item in nodes : <EOL> if hasattr ( item , "<STR_LIT>" ) : <EOL> l . append ( item . asList ( ) ) <EOL> else : <EOL> if type ( item ) is type ( ( None , None ) ) : <EOL> l . append ( tuple ( asList ( item ) ) ) <EOL> elif type ( item ) is type ( [ ] ) : <EOL> l . append ( asList ( item ) ) <EOL> else : <EOL> l . append ( item ) <EOL> return l <EOL> def Node ( * args ) : <EOL> kind = args [ <NUM_LIT:0> ] <EOL> if nodes . has_key ( kind ) : <EOL> try : <EOL> return nodes [ kind ] ( * args [ <NUM_LIT:1> : ] ) <EOL> except TypeError : <EOL> print nodes [ kind ] , len ( args ) , args <EOL> raise <EOL> else : <EOL> raise error , "<STR_LIT>" % str ( args ) <EOL> class Transformer : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _dispatch = { } <EOL> for value , name in symbol . sym_name . items ( ) : <EOL> if hasattr ( self , name ) : <EOL> self . _dispatch [ value ] = getattr ( self , name ) <EOL> self . _dispatch [ token . NEWLINE ] = self . com_NEWLINE <EOL> self . _atom_dispatch = { token . LPAR : self . atom_lpar , <EOL> token . LSQB : self . atom_lsqb , <EOL> token . LBRACE : self . atom_lbrace , <EOL> token . BACKQUOTE : self . atom_backquote , <EOL> token . NUMBER : self . atom_number , <EOL> token . STRING : self . atom_string , <EOL> token . NAME : self . atom_name , <EOL> } <EOL> self . encoding = None <EOL> def transform ( self , tree ) : <EOL> """<STR_LIT>""" <EOL> if type ( tree ) != type ( ( ) ) and type ( tree ) != type ( [ ] ) : <EOL> tree = parser . ast2tuple ( tree , line_info = <NUM_LIT:1> ) <EOL> return self . compile_node ( tree ) <EOL> def parsesuite ( self , text ) : <EOL> """<STR_LIT>""" <EOL> text = text . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return self . transform ( parser . suite ( text ) ) <EOL> def parseexpr ( self , text ) : <EOL> """<STR_LIT>""" <EOL> return self . transform ( parser . expr ( text ) ) <EOL> def parsefile ( self , file ) : <EOL> """<STR_LIT>""" <EOL> if type ( file ) == type ( '<STR_LIT>' ) : <EOL> file = open ( file ) <EOL> return self . parsesuite ( file . read ( ) ) <EOL> def compile_node ( self , node ) : <EOL> n = node [ <NUM_LIT:0> ] <EOL> if n == symbol . encoding_decl : <EOL> self . encoding = node [ <NUM_LIT:2> ] <EOL> node = node [ <NUM_LIT:1> ] <EOL> n = node [ <NUM_LIT:0> ] <EOL> if n == symbol . single_input : <EOL> return self . single_input ( node [ <NUM_LIT:1> : ] ) <EOL> if n == symbol . file_input : <EOL> return self . file_input ( node [ <NUM_LIT:1> : ] ) <EOL> if n == symbol . eval_input : <EOL> return self . eval_input ( node [ <NUM_LIT:1> : ] ) <EOL> if n == symbol . lambdef : <EOL> return self . lambdef ( node [ <NUM_LIT:1> : ] ) <EOL> if n == symbol . funcdef : <EOL> return self . funcdef ( node [ <NUM_LIT:1> : ] ) <EOL> if n == symbol . classdef : <EOL> return self . classdef ( node [ <NUM_LIT:1> : ] ) <EOL> raise error , ( '<STR_LIT>' , n ) <EOL> def single_input ( self , node ) : <EOL> n = node [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> if n != token . NEWLINE : <EOL> return self . com_stmt ( node [ <NUM_LIT:0> ] ) <EOL> return Pass ( ) <EOL> def file_input ( self , nodelist ) : <EOL> doc = self . get_docstring ( nodelist , symbol . file_input ) <EOL> if doc is not None : <EOL> i = <NUM_LIT:1> <EOL> else : <EOL> i = <NUM_LIT:0> <EOL> stmts = [ ] <EOL> for node in nodelist [ i : ] : <EOL> if node [ <NUM_LIT:0> ] != token . ENDMARKER and node [ <NUM_LIT:0> ] != token . NEWLINE : <EOL> self . com_append_stmt ( stmts , node ) <EOL> return Module ( doc , Stmt ( stmts ) ) <EOL> def eval_input ( self , nodelist ) : <EOL> return Expression ( self . com_node ( nodelist [ <NUM_LIT:0> ] ) ) <EOL> def funcdef ( self , nodelist ) : <EOL> lineno = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> name = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> args = nodelist [ <NUM_LIT:2> ] [ <NUM_LIT:2> ] <EOL> if args [ <NUM_LIT:0> ] == symbol . varargslist : <EOL> names , defaults , flags = self . com_arglist ( args [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> names = defaults = ( ) <EOL> flags = <NUM_LIT:0> <EOL> doc = self . get_docstring ( nodelist [ <NUM_LIT:4> ] ) <EOL> code = self . com_node ( nodelist [ <NUM_LIT:4> ] ) <EOL> if doc is not None : <EOL> assert isinstance ( code , Stmt ) <EOL> assert isinstance ( code . nodes [ <NUM_LIT:0> ] , Discard ) <EOL> del code . nodes [ <NUM_LIT:0> ] <EOL> n = Function ( name , names , defaults , flags , doc , code ) <EOL> n . lineno = lineno <EOL> return n <EOL> def lambdef ( self , nodelist ) : <EOL> if nodelist [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] == symbol . varargslist : <EOL> names , defaults , flags = self . com_arglist ( nodelist [ <NUM_LIT:2> ] [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> names = defaults = ( ) <EOL> flags = <NUM_LIT:0> <EOL> code = self . com_node ( nodelist [ - <NUM_LIT:1> ] ) <EOL> n = Lambda ( names , defaults , flags , code ) <EOL> n . lineno = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def classdef ( self , nodelist ) : <EOL> name = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> doc = self . get_docstring ( nodelist [ - <NUM_LIT:1> ] ) <EOL> if nodelist [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] == token . COLON : <EOL> bases = [ ] <EOL> else : <EOL> bases = self . com_bases ( nodelist [ <NUM_LIT:3> ] ) <EOL> code = self . com_node ( nodelist [ - <NUM_LIT:1> ] ) <EOL> if doc is not None : <EOL> assert isinstance ( code , Stmt ) <EOL> assert isinstance ( code . nodes [ <NUM_LIT:0> ] , Discard ) <EOL> del code . nodes [ <NUM_LIT:0> ] <EOL> n = Class ( name , bases , doc , code ) <EOL> n . lineno = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def stmt ( self , nodelist ) : <EOL> return self . com_stmt ( nodelist [ <NUM_LIT:0> ] ) <EOL> small_stmt = stmt <EOL> flow_stmt = stmt <EOL> compound_stmt = stmt <EOL> def simple_stmt ( self , nodelist ) : <EOL> stmts = [ ] <EOL> for i in range ( <NUM_LIT:0> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> self . com_append_stmt ( stmts , nodelist [ i ] ) <EOL> return Stmt ( stmts ) <EOL> def parameters ( self , nodelist ) : <EOL> raise error <EOL> def varargslist ( self , nodelist ) : <EOL> raise error <EOL> def fpdef ( self , nodelist ) : <EOL> raise error <EOL> def fplist ( self , nodelist ) : <EOL> raise error <EOL> def dotted_name ( self , nodelist ) : <EOL> raise error <EOL> def comp_op ( self , nodelist ) : <EOL> raise error <EOL> def trailer ( self , nodelist ) : <EOL> raise error <EOL> def sliceop ( self , nodelist ) : <EOL> raise error <EOL> def argument ( self , nodelist ) : <EOL> raise error <EOL> def expr_stmt ( self , nodelist ) : <EOL> en = nodelist [ - <NUM_LIT:1> ] <EOL> exprNode = self . lookup_node ( en ) ( en [ <NUM_LIT:1> : ] ) <EOL> if len ( nodelist ) == <NUM_LIT:1> : <EOL> n = Discard ( exprNode ) <EOL> n . lineno = exprNode . lineno <EOL> return n <EOL> if nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . EQUAL : <EOL> nodesl = [ ] <EOL> for i in range ( <NUM_LIT:0> , len ( nodelist ) - <NUM_LIT:2> , <NUM_LIT:2> ) : <EOL> nodesl . append ( self . com_assign ( nodelist [ i ] , OP_ASSIGN ) ) <EOL> n = Assign ( nodesl , exprNode ) <EOL> n . lineno = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> else : <EOL> lval = self . com_augassign ( nodelist [ <NUM_LIT:0> ] ) <EOL> op = self . com_augassign_op ( nodelist [ <NUM_LIT:1> ] ) <EOL> n = AugAssign ( lval , op [ <NUM_LIT:1> ] , exprNode ) <EOL> n . lineno = op [ <NUM_LIT:2> ] <EOL> return n <EOL> def print_stmt ( self , nodelist ) : <EOL> items = [ ] <EOL> if len ( nodelist ) == <NUM_LIT:1> : <EOL> start = <NUM_LIT:1> <EOL> dest = None <EOL> elif nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . RIGHTSHIFT : <EOL> assert len ( nodelist ) == <NUM_LIT:3> or nodelist [ <NUM_LIT:3> ] [ <NUM_LIT:0> ] == token . COMMA <EOL> dest = self . com_node ( nodelist [ <NUM_LIT:2> ] ) <EOL> start = <NUM_LIT:4> <EOL> else : <EOL> dest = None <EOL> start = <NUM_LIT:1> <EOL> for i in range ( start , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> items . append ( self . com_node ( nodelist [ i ] ) ) <EOL> if nodelist [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . COMMA : <EOL> n = Print ( items , dest ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> n = Printnl ( items , dest ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def del_stmt ( self , nodelist ) : <EOL> return self . com_assign ( nodelist [ <NUM_LIT:1> ] , OP_DELETE ) <EOL> def pass_stmt ( self , nodelist ) : <EOL> n = Pass ( ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def break_stmt ( self , nodelist ) : <EOL> n = Break ( ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def continue_stmt ( self , nodelist ) : <EOL> n = Continue ( ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def return_stmt ( self , nodelist ) : <EOL> if len ( nodelist ) < <NUM_LIT:2> : <EOL> n = Return ( Const ( None ) ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> n = Return ( self . com_node ( nodelist [ <NUM_LIT:1> ] ) ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def yield_stmt ( self , nodelist ) : <EOL> n = Yield ( self . com_node ( nodelist [ <NUM_LIT:1> ] ) ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def raise_stmt ( self , nodelist ) : <EOL> if len ( nodelist ) > <NUM_LIT:5> : <EOL> expr3 = self . com_node ( nodelist [ <NUM_LIT:5> ] ) <EOL> else : <EOL> expr3 = None <EOL> if len ( nodelist ) > <NUM_LIT:3> : <EOL> expr2 = self . com_node ( nodelist [ <NUM_LIT:3> ] ) <EOL> else : <EOL> expr2 = None <EOL> if len ( nodelist ) > <NUM_LIT:1> : <EOL> expr1 = self . com_node ( nodelist [ <NUM_LIT:1> ] ) <EOL> else : <EOL> expr1 = None <EOL> n = Raise ( expr1 , expr2 , expr3 ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def import_stmt ( self , nodelist ) : <EOL> if nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> names = [ ] <EOL> if nodelist [ <NUM_LIT:3> ] [ <NUM_LIT:0> ] == token . NAME : <EOL> for i in range ( <NUM_LIT:3> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> names . append ( ( nodelist [ i ] [ <NUM_LIT:1> ] , None ) ) <EOL> else : <EOL> for i in range ( <NUM_LIT:3> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> names . append ( self . com_import_as_name ( nodelist [ i ] ) ) <EOL> n = From ( self . com_dotted_name ( nodelist [ <NUM_LIT:1> ] ) , names ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> if nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == symbol . dotted_name : <EOL> names = [ ( self . com_dotted_name ( nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] ) , None ) ] <EOL> else : <EOL> names = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> names . append ( self . com_dotted_as_name ( nodelist [ i ] ) ) <EOL> n = Import ( names ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def global_stmt ( self , nodelist ) : <EOL> names = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> names . append ( nodelist [ i ] [ <NUM_LIT:1> ] ) <EOL> n = Global ( names ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def exec_stmt ( self , nodelist ) : <EOL> expr1 = self . com_node ( nodelist [ <NUM_LIT:1> ] ) <EOL> if len ( nodelist ) >= <NUM_LIT:4> : <EOL> expr2 = self . com_node ( nodelist [ <NUM_LIT:3> ] ) <EOL> if len ( nodelist ) >= <NUM_LIT:6> : <EOL> expr3 = self . com_node ( nodelist [ <NUM_LIT:5> ] ) <EOL> else : <EOL> expr3 = None <EOL> else : <EOL> expr2 = expr3 = None <EOL> n = Exec ( expr1 , expr2 , expr3 ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def assert_stmt ( self , nodelist ) : <EOL> expr1 = self . com_node ( nodelist [ <NUM_LIT:1> ] ) <EOL> if ( len ( nodelist ) == <NUM_LIT:4> ) : <EOL> expr2 = self . com_node ( nodelist [ <NUM_LIT:3> ] ) <EOL> else : <EOL> expr2 = None <EOL> n = Assert ( expr1 , expr2 ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def if_stmt ( self , nodelist ) : <EOL> tests = [ ] <EOL> for i in range ( <NUM_LIT:0> , len ( nodelist ) - <NUM_LIT:3> , <NUM_LIT:4> ) : <EOL> testNode = self . com_node ( nodelist [ i + <NUM_LIT:1> ] ) <EOL> suiteNode = self . com_node ( nodelist [ i + <NUM_LIT:3> ] ) <EOL> tests . append ( ( testNode , suiteNode ) ) <EOL> if len ( nodelist ) % <NUM_LIT:4> == <NUM_LIT:3> : <EOL> elseNode = self . com_node ( nodelist [ - <NUM_LIT:1> ] ) <EOL> else : <EOL> elseNode = None <EOL> n = If ( tests , elseNode ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def while_stmt ( self , nodelist ) : <EOL> testNode = self . com_node ( nodelist [ <NUM_LIT:1> ] ) <EOL> bodyNode = self . com_node ( nodelist [ <NUM_LIT:3> ] ) <EOL> if len ( nodelist ) > <NUM_LIT:4> : <EOL> elseNode = self . com_node ( nodelist [ <NUM_LIT:6> ] ) <EOL> else : <EOL> elseNode = None <EOL> n = While ( testNode , bodyNode , elseNode ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def for_stmt ( self , nodelist ) : <EOL> assignNode = self . com_assign ( nodelist [ <NUM_LIT:1> ] , OP_ASSIGN ) <EOL> listNode = self . com_node ( nodelist [ <NUM_LIT:3> ] ) <EOL> bodyNode = self . com_node ( nodelist [ <NUM_LIT:5> ] ) <EOL> if len ( nodelist ) > <NUM_LIT:8> : <EOL> elseNode = self . com_node ( nodelist [ <NUM_LIT:8> ] ) <EOL> else : <EOL> elseNode = None <EOL> n = For ( assignNode , listNode , bodyNode , elseNode ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def try_stmt ( self , nodelist ) : <EOL> if nodelist [ <NUM_LIT:3> ] [ <NUM_LIT:0> ] != symbol . except_clause : <EOL> return self . com_try_finally ( nodelist ) <EOL> return self . com_try_except ( nodelist ) <EOL> def suite ( self , nodelist ) : <EOL> if len ( nodelist ) == <NUM_LIT:1> : <EOL> return self . com_stmt ( nodelist [ <NUM_LIT:0> ] ) <EOL> stmts = [ ] <EOL> for node in nodelist : <EOL> if node [ <NUM_LIT:0> ] == symbol . stmt : <EOL> self . com_append_stmt ( stmts , node ) <EOL> return Stmt ( stmts ) <EOL> def testlist ( self , nodelist ) : <EOL> return self . com_binary ( Tuple , nodelist ) <EOL> testlist_safe = testlist <EOL> testlist1 = testlist <EOL> exprlist = testlist <EOL> def test ( self , nodelist ) : <EOL> if len ( nodelist ) == <NUM_LIT:1> and nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] == symbol . lambdef : <EOL> return self . lambdef ( nodelist [ <NUM_LIT:0> ] ) <EOL> return self . com_binary ( Or , nodelist ) <EOL> def and_test ( self , nodelist ) : <EOL> return self . com_binary ( And , nodelist ) <EOL> def not_test ( self , nodelist ) : <EOL> result = self . com_node ( nodelist [ - <NUM_LIT:1> ] ) <EOL> if len ( nodelist ) == <NUM_LIT:2> : <EOL> n = Not ( result ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> return result <EOL> def comparison ( self , nodelist ) : <EOL> node = self . com_node ( nodelist [ <NUM_LIT:0> ] ) <EOL> if len ( nodelist ) == <NUM_LIT:1> : <EOL> return node <EOL> results = [ ] <EOL> for i in range ( <NUM_LIT:2> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> nl = nodelist [ i - <NUM_LIT:1> ] <EOL> n = nl [ <NUM_LIT:1> ] <EOL> if n [ <NUM_LIT:0> ] == token . NAME : <EOL> type = n [ <NUM_LIT:1> ] <EOL> if len ( nl ) == <NUM_LIT:3> : <EOL> if type == '<STR_LIT>' : <EOL> type = '<STR_LIT>' <EOL> else : <EOL> type = '<STR_LIT>' <EOL> else : <EOL> type = _cmp_types [ n [ <NUM_LIT:0> ] ] <EOL> lineno = nl [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> results . append ( ( type , self . com_node ( nodelist [ i ] ) ) ) <EOL> n = Compare ( node , results ) <EOL> n . lineno = lineno <EOL> return n <EOL> def expr ( self , nodelist ) : <EOL> return self . com_binary ( Bitor , nodelist ) <EOL> def xor_expr ( self , nodelist ) : <EOL> return self . com_binary ( Bitxor , nodelist ) <EOL> def and_expr ( self , nodelist ) : <EOL> return self . com_binary ( Bitand , nodelist ) <EOL> def shift_expr ( self , nodelist ) : <EOL> node = self . com_node ( nodelist [ <NUM_LIT:0> ] ) <EOL> for i in range ( <NUM_LIT:2> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> right = self . com_node ( nodelist [ i ] ) <EOL> if nodelist [ i - <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . LEFTSHIFT : <EOL> node = LeftShift ( [ node , right ] ) <EOL> node . lineno = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> elif nodelist [ i - <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . RIGHTSHIFT : <EOL> node = RightShift ( [ node , right ] ) <EOL> node . lineno = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> else : <EOL> raise ValueError , "<STR_LIT>" % nodelist [ i - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> return node <EOL> def arith_expr ( self , nodelist ) : <EOL> node = self . com_node ( nodelist [ <NUM_LIT:0> ] ) <EOL> for i in range ( <NUM_LIT:2> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> right = self . com_node ( nodelist [ i ] ) <EOL> if nodelist [ i - <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . PLUS : <EOL> node = Add ( [ node , right ] ) <EOL> node . lineno = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> elif nodelist [ i - <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . MINUS : <EOL> node = Sub ( [ node , right ] ) <EOL> node . lineno = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> else : <EOL> raise ValueError , "<STR_LIT>" % nodelist [ i - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> return node <EOL> def term ( self , nodelist ) : <EOL> node = self . com_node ( nodelist [ <NUM_LIT:0> ] ) <EOL> for i in range ( <NUM_LIT:2> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> right = self . com_node ( nodelist [ i ] ) <EOL> t = nodelist [ i - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> if t == token . STAR : <EOL> node = Mul ( [ node , right ] ) <EOL> elif t == token . SLASH : <EOL> node = Div ( [ node , right ] ) <EOL> elif t == token . PERCENT : <EOL> node = Mod ( [ node , right ] ) <EOL> elif t == token . DOUBLESLASH : <EOL> node = FloorDiv ( [ node , right ] ) <EOL> else : <EOL> raise ValueError , "<STR_LIT>" % t <EOL> node . lineno = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> return node <EOL> def factor ( self , nodelist ) : <EOL> elt = nodelist [ <NUM_LIT:0> ] <EOL> t = elt [ <NUM_LIT:0> ] <EOL> node = self . com_node ( nodelist [ - <NUM_LIT:1> ] ) <EOL> if t == token . PLUS : <EOL> node = UnaryAdd ( node ) <EOL> node . lineno = elt [ <NUM_LIT:2> ] <EOL> elif t == token . MINUS : <EOL> node = UnarySub ( node ) <EOL> node . lineno = elt [ <NUM_LIT:2> ] <EOL> elif t == token . TILDE : <EOL> node = Invert ( node ) <EOL> node . lineno = elt [ <NUM_LIT:2> ] <EOL> return node <EOL> def power ( self , nodelist ) : <EOL> node = self . com_node ( nodelist [ <NUM_LIT:0> ] ) <EOL> for i in range ( <NUM_LIT:1> , len ( nodelist ) ) : <EOL> elt = nodelist [ i ] <EOL> if elt [ <NUM_LIT:0> ] == token . DOUBLESTAR : <EOL> n = Power ( [ node , self . com_node ( nodelist [ i + <NUM_LIT:1> ] ) ] ) <EOL> n . lineno = elt [ <NUM_LIT:2> ] <EOL> return n <EOL> node = self . com_apply_trailer ( node , elt ) <EOL> return node <EOL> def atom ( self , nodelist ) : <EOL> n = self . _atom_dispatch [ nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ] ( nodelist ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def atom_lpar ( self , nodelist ) : <EOL> if nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . RPAR : <EOL> n = Tuple ( ( ) ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> return self . com_node ( nodelist [ <NUM_LIT:1> ] ) <EOL> def atom_lsqb ( self , nodelist ) : <EOL> if nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . RSQB : <EOL> n = List ( ( ) ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> return self . com_list_constructor ( nodelist [ <NUM_LIT:1> ] ) <EOL> def atom_lbrace ( self , nodelist ) : <EOL> if nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . RBRACE : <EOL> return Dict ( ( ) ) <EOL> return self . com_dictmaker ( nodelist [ <NUM_LIT:1> ] ) <EOL> def atom_backquote ( self , nodelist ) : <EOL> n = Backquote ( self . com_node ( nodelist [ <NUM_LIT:1> ] ) ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def atom_number ( self , nodelist ) : <EOL> k = eval ( nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> n = Const ( k ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def decode_literal ( self , lit ) : <EOL> if self . encoding : <EOL> if self . encoding not in [ '<STR_LIT:utf-8>' , '<STR_LIT>' ] : <EOL> lit = unicode ( lit , '<STR_LIT:utf-8>' ) . encode ( self . encoding ) <EOL> return eval ( "<STR_LIT>" % ( self . encoding , lit ) ) <EOL> else : <EOL> return eval ( lit ) <EOL> def atom_string ( self , nodelist ) : <EOL> k = '<STR_LIT>' <EOL> for node in nodelist : <EOL> k += self . decode_literal ( node [ <NUM_LIT:1> ] ) <EOL> n = Const ( k ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def atom_name ( self , nodelist ) : <EOL> n = Name ( nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def lookup_node ( self , node ) : <EOL> return self . _dispatch [ node [ <NUM_LIT:0> ] ] <EOL> def com_node ( self , node ) : <EOL> return self . _dispatch [ node [ <NUM_LIT:0> ] ] ( node [ <NUM_LIT:1> : ] ) <EOL> def com_NEWLINE ( self , * args ) : <EOL> return Discard ( Const ( None ) ) <EOL> def com_arglist ( self , nodelist ) : <EOL> names = [ ] <EOL> defaults = [ ] <EOL> flags = <NUM_LIT:0> <EOL> i = <NUM_LIT:0> <EOL> while i < len ( nodelist ) : <EOL> node = nodelist [ i ] <EOL> if node [ <NUM_LIT:0> ] == token . STAR or node [ <NUM_LIT:0> ] == token . DOUBLESTAR : <EOL> if node [ <NUM_LIT:0> ] == token . STAR : <EOL> node = nodelist [ i + <NUM_LIT:1> ] <EOL> if node [ <NUM_LIT:0> ] == token . NAME : <EOL> names . append ( node [ <NUM_LIT:1> ] ) <EOL> flags = flags | CO_VARARGS <EOL> i = i + <NUM_LIT:3> <EOL> if i < len ( nodelist ) : <EOL> t = nodelist [ i ] [ <NUM_LIT:0> ] <EOL> if t == token . DOUBLESTAR : <EOL> node = nodelist [ i + <NUM_LIT:1> ] <EOL> else : <EOL> raise ValueError , "<STR_LIT>" % t <EOL> names . append ( node [ <NUM_LIT:1> ] ) <EOL> flags = flags | CO_VARKEYWORDS <EOL> break <EOL> names . append ( self . com_fpdef ( node ) ) <EOL> i = i + <NUM_LIT:1> <EOL> if i >= len ( nodelist ) : <EOL> break <EOL> if nodelist [ i ] [ <NUM_LIT:0> ] == token . EQUAL : <EOL> defaults . append ( self . com_node ( nodelist [ i + <NUM_LIT:1> ] ) ) <EOL> i = i + <NUM_LIT:2> <EOL> elif len ( defaults ) : <EOL> defaults . append ( Const ( None ) ) <EOL> i = i + <NUM_LIT:1> <EOL> return names , defaults , flags <EOL> def com_fpdef ( self , node ) : <EOL> if node [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . LPAR : <EOL> return self . com_fplist ( node [ <NUM_LIT:2> ] ) <EOL> return node [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> def com_fplist ( self , node ) : <EOL> if len ( node ) == <NUM_LIT:2> : <EOL> return self . com_fpdef ( node [ <NUM_LIT:1> ] ) <EOL> list = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( node ) , <NUM_LIT:2> ) : <EOL> list . append ( self . com_fpdef ( node [ i ] ) ) <EOL> return tuple ( list ) <EOL> def com_dotted_name ( self , node ) : <EOL> name = "<STR_LIT>" <EOL> for n in node : <EOL> if type ( n ) == type ( ( ) ) and n [ <NUM_LIT:0> ] == <NUM_LIT:1> : <EOL> name = name + n [ <NUM_LIT:1> ] + '<STR_LIT:.>' <EOL> return name [ : - <NUM_LIT:1> ] <EOL> def com_dotted_as_name ( self , node ) : <EOL> dot = self . com_dotted_name ( node [ <NUM_LIT:1> ] ) <EOL> if len ( node ) <= <NUM_LIT:2> : <EOL> return dot , None <EOL> if node [ <NUM_LIT:0> ] == symbol . dotted_name : <EOL> pass <EOL> else : <EOL> assert node [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert node [ <NUM_LIT:3> ] [ <NUM_LIT:0> ] == token . NAME <EOL> return dot , node [ <NUM_LIT:3> ] [ <NUM_LIT:1> ] <EOL> def com_import_as_name ( self , node ) : <EOL> if node [ <NUM_LIT:0> ] == token . STAR : <EOL> return '<STR_LIT:*>' , None <EOL> assert node [ <NUM_LIT:0> ] == symbol . import_as_name <EOL> node = node [ <NUM_LIT:1> : ] <EOL> if len ( node ) == <NUM_LIT:1> : <EOL> assert node [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] == token . NAME <EOL> return node [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , None <EOL> assert node [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == '<STR_LIT>' , node <EOL> assert node [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] == token . NAME <EOL> return node [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , node [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] <EOL> def com_bases ( self , node ) : <EOL> bases = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( node ) , <NUM_LIT:2> ) : <EOL> bases . append ( self . com_node ( node [ i ] ) ) <EOL> return bases <EOL> def com_try_finally ( self , nodelist ) : <EOL> n = TryFinally ( self . com_node ( nodelist [ <NUM_LIT:2> ] ) , <EOL> self . com_node ( nodelist [ <NUM_LIT:5> ] ) ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def com_try_except ( self , nodelist ) : <EOL> stmt = self . com_node ( nodelist [ <NUM_LIT:2> ] ) <EOL> clauses = [ ] <EOL> elseNode = None <EOL> for i in range ( <NUM_LIT:3> , len ( nodelist ) , <NUM_LIT:3> ) : <EOL> node = nodelist [ i ] <EOL> if node [ <NUM_LIT:0> ] == symbol . except_clause : <EOL> if len ( node ) > <NUM_LIT:2> : <EOL> expr1 = self . com_node ( node [ <NUM_LIT:2> ] ) <EOL> if len ( node ) > <NUM_LIT:4> : <EOL> expr2 = self . com_assign ( node [ <NUM_LIT:4> ] , OP_ASSIGN ) <EOL> else : <EOL> expr2 = None <EOL> else : <EOL> expr1 = expr2 = None <EOL> clauses . append ( ( expr1 , expr2 , self . com_node ( nodelist [ i + <NUM_LIT:2> ] ) ) ) <EOL> if node [ <NUM_LIT:0> ] == token . NAME : <EOL> elseNode = self . com_node ( nodelist [ i + <NUM_LIT:2> ] ) <EOL> n = TryExcept ( self . com_node ( nodelist [ <NUM_LIT:2> ] ) , clauses , elseNode ) <EOL> n . lineno = nodelist [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> return n <EOL> def com_augassign_op ( self , node ) : <EOL> assert node [ <NUM_LIT:0> ] == symbol . augassign <EOL> return node [ <NUM_LIT:1> ] <EOL> def com_augassign ( self , node ) : <EOL> """<STR_LIT>""" <EOL> l = self . com_node ( node ) <EOL> if l . __class__ in ( Name , Slice , Subscript , Getattr ) : <EOL> return l <EOL> raise SyntaxError , "<STR_LIT>" % l . __class__ . __name__ <EOL> def com_assign ( self , node , assigning ) : <EOL> while <NUM_LIT:1> : <EOL> t = node [ <NUM_LIT:0> ] <EOL> if t == symbol . exprlist or t == symbol . testlist : <EOL> if len ( node ) > <NUM_LIT:2> : <EOL> return self . com_assign_tuple ( node , assigning ) <EOL> node = node [ <NUM_LIT:1> ] <EOL> elif t in _assign_types : <EOL> if len ( node ) > <NUM_LIT:2> : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> node = node [ <NUM_LIT:1> ] <EOL> elif t == symbol . power : <EOL> if node [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] != symbol . atom : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> if len ( node ) > <NUM_LIT:2> : <EOL> primary = self . com_node ( node [ <NUM_LIT:1> ] ) <EOL> for i in range ( <NUM_LIT:2> , len ( node ) - <NUM_LIT:1> ) : <EOL> ch = node [ i ] <EOL> if ch [ <NUM_LIT:0> ] == token . DOUBLESTAR : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> primary = self . com_apply_trailer ( primary , ch ) <EOL> return self . com_assign_trailer ( primary , node [ - <NUM_LIT:1> ] , <EOL> assigning ) <EOL> node = node [ <NUM_LIT:1> ] <EOL> elif t == symbol . atom : <EOL> t = node [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> if t == token . LPAR : <EOL> node = node [ <NUM_LIT:2> ] <EOL> if node [ <NUM_LIT:0> ] == token . RPAR : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> elif t == token . LSQB : <EOL> node = node [ <NUM_LIT:2> ] <EOL> if node [ <NUM_LIT:0> ] == token . RSQB : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> return self . com_assign_list ( node , assigning ) <EOL> elif t == token . NAME : <EOL> return self . com_assign_name ( node [ <NUM_LIT:1> ] , assigning ) <EOL> else : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> else : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> def com_assign_tuple ( self , node , assigning ) : <EOL> assigns = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( node ) , <NUM_LIT:2> ) : <EOL> assigns . append ( self . com_assign ( node [ i ] , assigning ) ) <EOL> return AssTuple ( assigns ) <EOL> def com_assign_list ( self , node , assigning ) : <EOL> assigns = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( node ) , <NUM_LIT:2> ) : <EOL> if i + <NUM_LIT:1> < len ( node ) : <EOL> if node [ i + <NUM_LIT:1> ] [ <NUM_LIT:0> ] == symbol . list_for : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> assert node [ i + <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . COMMA , node [ i + <NUM_LIT:1> ] <EOL> assigns . append ( self . com_assign ( node [ i ] , assigning ) ) <EOL> return AssList ( assigns ) <EOL> def com_assign_name ( self , node , assigning ) : <EOL> n = AssName ( node [ <NUM_LIT:1> ] , assigning ) <EOL> n . lineno = node [ <NUM_LIT:2> ] <EOL> return n <EOL> def com_assign_trailer ( self , primary , node , assigning ) : <EOL> t = node [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> if t == token . DOT : <EOL> return self . com_assign_attr ( primary , node [ <NUM_LIT:2> ] , assigning ) <EOL> if t == token . LSQB : <EOL> return self . com_subscriptlist ( primary , node [ <NUM_LIT:2> ] , assigning ) <EOL> if t == token . LPAR : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> raise SyntaxError , "<STR_LIT>" % t <EOL> def com_assign_attr ( self , primary , node , assigning ) : <EOL> return AssAttr ( primary , node [ <NUM_LIT:1> ] , assigning ) <EOL> def com_binary ( self , constructor , nodelist ) : <EOL> "<STR_LIT>" <EOL> l = len ( nodelist ) <EOL> if l == <NUM_LIT:1> : <EOL> n = nodelist [ <NUM_LIT:0> ] <EOL> return self . lookup_node ( n ) ( n [ <NUM_LIT:1> : ] ) <EOL> items = [ ] <EOL> for i in range ( <NUM_LIT:0> , l , <NUM_LIT:2> ) : <EOL> n = nodelist [ i ] <EOL> items . append ( self . lookup_node ( n ) ( n [ <NUM_LIT:1> : ] ) ) <EOL> return constructor ( items ) <EOL> def com_stmt ( self , node ) : <EOL> result = self . lookup_node ( node ) ( node [ <NUM_LIT:1> : ] ) <EOL> assert result is not None <EOL> if isinstance ( result , Stmt ) : <EOL> return result <EOL> return Stmt ( [ result ] ) <EOL> def com_append_stmt ( self , stmts , node ) : <EOL> result = self . com_node ( node ) <EOL> assert result is not None <EOL> if isinstance ( result , Stmt ) : <EOL> stmts . extend ( result . nodes ) <EOL> else : <EOL> stmts . append ( result ) <EOL> if hasattr ( symbol , '<STR_LIT>' ) : <EOL> def com_list_constructor ( self , nodelist ) : <EOL> values = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( nodelist ) ) : <EOL> if nodelist [ i ] [ <NUM_LIT:0> ] == symbol . list_for : <EOL> assert len ( nodelist [ i : ] ) == <NUM_LIT:1> <EOL> return self . com_list_comprehension ( values [ <NUM_LIT:0> ] , <EOL> nodelist [ i ] ) <EOL> elif nodelist [ i ] [ <NUM_LIT:0> ] == token . COMMA : <EOL> continue <EOL> values . append ( self . com_node ( nodelist [ i ] ) ) <EOL> return List ( values ) <EOL> def com_list_comprehension ( self , expr , node ) : <EOL> lineno = node [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> fors = [ ] <EOL> while node : <EOL> t = node [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> if t == '<STR_LIT>' : <EOL> assignNode = self . com_assign ( node [ <NUM_LIT:2> ] , OP_ASSIGN ) <EOL> listNode = self . com_node ( node [ <NUM_LIT:4> ] ) <EOL> newfor = ListCompFor ( assignNode , listNode , [ ] ) <EOL> newfor . lineno = node [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> fors . append ( newfor ) <EOL> if len ( node ) == <NUM_LIT:5> : <EOL> node = None <EOL> else : <EOL> node = self . com_list_iter ( node [ <NUM_LIT:5> ] ) <EOL> elif t == '<STR_LIT>' : <EOL> test = self . com_node ( node [ <NUM_LIT:2> ] ) <EOL> newif = ListCompIf ( test ) <EOL> newif . lineno = node [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] <EOL> newfor . ifs . append ( newif ) <EOL> if len ( node ) == <NUM_LIT:3> : <EOL> node = None <EOL> else : <EOL> node = self . com_list_iter ( node [ <NUM_LIT:3> ] ) <EOL> else : <EOL> raise SyntaxError , ( "<STR_LIT>" <EOL> % ( node , lineno ) ) <EOL> n = ListComp ( expr , fors ) <EOL> n . lineno = lineno <EOL> return n <EOL> def com_list_iter ( self , node ) : <EOL> assert node [ <NUM_LIT:0> ] == symbol . list_iter <EOL> return node [ <NUM_LIT:1> ] <EOL> else : <EOL> def com_list_constructor ( self , nodelist ) : <EOL> values = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> values . append ( self . com_node ( nodelist [ i ] ) ) <EOL> return List ( values ) <EOL> def com_dictmaker ( self , nodelist ) : <EOL> items = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( nodelist ) , <NUM_LIT:4> ) : <EOL> items . append ( ( self . com_node ( nodelist [ i ] ) , <EOL> self . com_node ( nodelist [ i + <NUM_LIT:2> ] ) ) ) <EOL> return Dict ( items ) <EOL> def com_apply_trailer ( self , primaryNode , nodelist ) : <EOL> t = nodelist [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> if t == token . LPAR : <EOL> return self . com_call_function ( primaryNode , nodelist [ <NUM_LIT:2> ] ) <EOL> if t == token . DOT : <EOL> return self . com_select_member ( primaryNode , nodelist [ <NUM_LIT:2> ] ) <EOL> if t == token . LSQB : <EOL> return self . com_subscriptlist ( primaryNode , nodelist [ <NUM_LIT:2> ] , OP_APPLY ) <EOL> raise SyntaxError , '<STR_LIT>' % t <EOL> def com_select_member ( self , primaryNode , nodelist ) : <EOL> if nodelist [ <NUM_LIT:0> ] != token . NAME : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> n = Getattr ( primaryNode , nodelist [ <NUM_LIT:1> ] ) <EOL> n . lineno = nodelist [ <NUM_LIT:2> ] <EOL> return n <EOL> def com_call_function ( self , primaryNode , nodelist ) : <EOL> if nodelist [ <NUM_LIT:0> ] == token . RPAR : <EOL> return CallFunc ( primaryNode , [ ] ) <EOL> args = [ ] <EOL> kw = <NUM_LIT:0> <EOL> len_nodelist = len ( nodelist ) <EOL> for i in range ( <NUM_LIT:1> , len_nodelist , <NUM_LIT:2> ) : <EOL> node = nodelist [ i ] <EOL> if node [ <NUM_LIT:0> ] == token . STAR or node [ <NUM_LIT:0> ] == token . DOUBLESTAR : <EOL> break <EOL> kw , result = self . com_argument ( node , kw ) <EOL> args . append ( result ) <EOL> else : <EOL> i = i + <NUM_LIT:1> <EOL> if i < len_nodelist and nodelist [ i ] [ <NUM_LIT:0> ] == token . COMMA : <EOL> i = i + <NUM_LIT:1> <EOL> star_node = dstar_node = None <EOL> while i < len_nodelist : <EOL> tok = nodelist [ i ] <EOL> ch = nodelist [ i + <NUM_LIT:1> ] <EOL> i = i + <NUM_LIT:3> <EOL> if tok [ <NUM_LIT:0> ] == token . STAR : <EOL> if star_node is not None : <EOL> raise SyntaxError , '<STR_LIT>' <EOL> star_node = self . com_node ( ch ) <EOL> elif tok [ <NUM_LIT:0> ] == token . DOUBLESTAR : <EOL> if dstar_node is not None : <EOL> raise SyntaxError , '<STR_LIT>' <EOL> dstar_node = self . com_node ( ch ) <EOL> else : <EOL> raise SyntaxError , '<STR_LIT>' % tok <EOL> return CallFunc ( primaryNode , args , star_node , dstar_node ) <EOL> def com_argument ( self , nodelist , kw ) : <EOL> if len ( nodelist ) == <NUM_LIT:2> : <EOL> if kw : <EOL> raise SyntaxError , "<STR_LIT>" <EOL> return <NUM_LIT:0> , self . com_node ( nodelist [ <NUM_LIT:1> ] ) <EOL> result = self . com_node ( nodelist [ <NUM_LIT:3> ] ) <EOL> n = nodelist [ <NUM_LIT:1> ] <EOL> while len ( n ) == <NUM_LIT:2> and n [ <NUM_LIT:0> ] != token . NAME : <EOL> n = n [ <NUM_LIT:1> ] <EOL> if n [ <NUM_LIT:0> ] != token . NAME : <EOL> raise SyntaxError , "<STR_LIT>" % n [ <NUM_LIT:0> ] <EOL> node = Keyword ( n [ <NUM_LIT:1> ] , result ) <EOL> node . lineno = n [ <NUM_LIT:2> ] <EOL> return <NUM_LIT:1> , node <EOL> def com_subscriptlist ( self , primary , nodelist , assigning ) : <EOL> if len ( nodelist ) == <NUM_LIT:2> : <EOL> sub = nodelist [ <NUM_LIT:1> ] <EOL> if ( sub [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . COLON or ( len ( sub ) > <NUM_LIT:2> and sub [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] == token . COLON ) ) and sub [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] != symbol . sliceop : <EOL> return self . com_slice ( primary , sub , assigning ) <EOL> subscripts = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> subscripts . append ( self . com_subscript ( nodelist [ i ] ) ) <EOL> return Subscript ( primary , assigning , subscripts ) <EOL> def com_subscript ( self , node ) : <EOL> ch = node [ <NUM_LIT:1> ] <EOL> t = ch [ <NUM_LIT:0> ] <EOL> if t == token . DOT and node [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] == token . DOT : <EOL> return Ellipsis ( ) <EOL> if t == token . COLON or len ( node ) > <NUM_LIT:2> : <EOL> return self . com_sliceobj ( node ) <EOL> return self . com_node ( ch ) <EOL> def com_sliceobj ( self , node ) : <EOL> items = [ ] <EOL> if node [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . COLON : <EOL> items . append ( Const ( None ) ) <EOL> i = <NUM_LIT:2> <EOL> else : <EOL> items . append ( self . com_node ( node [ <NUM_LIT:1> ] ) ) <EOL> i = <NUM_LIT:3> <EOL> if i < len ( node ) and node [ i ] [ <NUM_LIT:0> ] == symbol . test : <EOL> items . append ( self . com_node ( node [ i ] ) ) <EOL> i = i + <NUM_LIT:1> <EOL> else : <EOL> items . append ( Const ( None ) ) <EOL> for j in range ( i , len ( node ) ) : <EOL> ch = node [ j ] <EOL> if len ( ch ) == <NUM_LIT:2> : <EOL> items . append ( Const ( None ) ) <EOL> else : <EOL> items . append ( self . com_node ( ch [ <NUM_LIT:2> ] ) ) <EOL> return Sliceobj ( items ) <EOL> def com_slice ( self , primary , node , assigning ) : <EOL> lower = upper = None <EOL> if len ( node ) == <NUM_LIT:3> : <EOL> if node [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . COLON : <EOL> upper = self . com_node ( node [ <NUM_LIT:2> ] ) <EOL> else : <EOL> lower = self . com_node ( node [ <NUM_LIT:1> ] ) <EOL> elif len ( node ) == <NUM_LIT:4> : <EOL> lower = self . com_node ( node [ <NUM_LIT:1> ] ) <EOL> upper = self . com_node ( node [ <NUM_LIT:3> ] ) <EOL> return Slice ( primary , assigning , lower , upper ) <EOL> def get_docstring ( self , node , n = None ) : <EOL> if n is None : <EOL> n = node [ <NUM_LIT:0> ] <EOL> node = node [ <NUM_LIT:1> : ] <EOL> if n == symbol . suite : <EOL> if len ( node ) == <NUM_LIT:1> : <EOL> return self . get_docstring ( node [ <NUM_LIT:0> ] ) <EOL> for sub in node : <EOL> if sub [ <NUM_LIT:0> ] == symbol . stmt : <EOL> return self . get_docstring ( sub ) <EOL> return None <EOL> if n == symbol . file_input : <EOL> for sub in node : <EOL> if sub [ <NUM_LIT:0> ] == symbol . stmt : <EOL> return self . get_docstring ( sub ) <EOL> return None <EOL> if n == symbol . atom : <EOL> if node [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] == token . STRING : <EOL> s = '<STR_LIT>' <EOL> for t in node : <EOL> s = s + eval ( t [ <NUM_LIT:1> ] ) <EOL> return s <EOL> return None <EOL> if n == symbol . stmt or n == symbol . simple_stmt or n == symbol . small_stmt : <EOL> return self . get_docstring ( node [ <NUM_LIT:0> ] ) <EOL> if n in _doc_nodes and len ( node ) == <NUM_LIT:1> : <EOL> return self . get_docstring ( node [ <NUM_LIT:0> ] ) <EOL> return None <EOL> _doc_nodes = [ <EOL> symbol . expr_stmt , <EOL> symbol . testlist , <EOL> symbol . testlist_safe , <EOL> symbol . test , <EOL> symbol . and_test , <EOL> symbol . not_test , <EOL> symbol . comparison , <EOL> symbol . expr , <EOL> symbol . xor_expr , <EOL> symbol . and_expr , <EOL> symbol . shift_expr , <EOL> symbol . arith_expr , <EOL> symbol . term , <EOL> symbol . factor , <EOL> symbol . power , <EOL> ] <EOL> _cmp_types = { <EOL> token . LESS : '<STR_LIT:<>' , <EOL> token . GREATER : '<STR_LIT:>>' , <EOL> token . EQEQUAL : '<STR_LIT>' , <EOL> token . EQUAL : '<STR_LIT>' , <EOL> token . LESSEQUAL : '<STR_LIT>' , <EOL> token . GREATEREQUAL : '<STR_LIT>' , <EOL> token . NOTEQUAL : '<STR_LIT>' , <EOL> } <EOL> _legal_node_types = [ <EOL> symbol . funcdef , <EOL> symbol . classdef , <EOL> symbol . stmt , <EOL> symbol . small_stmt , <EOL> symbol . flow_stmt , <EOL> symbol . simple_stmt , <EOL> symbol . compound_stmt , <EOL> symbol . expr_stmt , <EOL> symbol . print_stmt , <EOL> symbol . del_stmt , <EOL> symbol . pass_stmt , <EOL> symbol . break_stmt , <EOL> symbol . continue_stmt , <EOL> symbol . return_stmt , <EOL> symbol . raise_stmt , <EOL> symbol . import_stmt , <EOL> symbol . global_stmt , <EOL> symbol . exec_stmt , <EOL> symbol . assert_stmt , <EOL> symbol . if_stmt , <EOL> symbol . while_stmt , <EOL> symbol . for_stmt , <EOL> symbol . try_stmt , <EOL> symbol . suite , <EOL> symbol . testlist , <EOL> symbol . testlist_safe , <EOL> symbol . test , <EOL> symbol . and_test , <EOL> symbol . not_test , <EOL> symbol . comparison , <EOL> symbol . exprlist , <EOL> symbol . expr , <EOL> symbol . xor_expr , <EOL> symbol . and_expr , <EOL> symbol . shift_expr , <EOL> symbol . arith_expr , <EOL> symbol . term , <EOL> symbol . factor , <EOL> symbol . power , <EOL> symbol . atom , <EOL> ] <EOL> if hasattr ( symbol , '<STR_LIT>' ) : <EOL> _legal_node_types . append ( symbol . yield_stmt ) <EOL> _assign_types = [ <EOL> symbol . test , <EOL> symbol . and_test , <EOL> symbol . not_test , <EOL> symbol . comparison , <EOL> symbol . expr , <EOL> symbol . xor_expr , <EOL> symbol . and_expr , <EOL> symbol . shift_expr , <EOL> symbol . arith_expr , <EOL> symbol . term , <EOL> symbol . factor , <EOL> ] <EOL> import types <EOL> _names = { } <EOL> for k , v in symbol . sym_name . items ( ) : <EOL> _names [ k ] = v <EOL> for k , v in token . tok_name . items ( ) : <EOL> _names [ k ] = v <EOL> def debug_tree ( tree ) : <EOL> l = [ ] <EOL> for elt in tree : <EOL> if type ( elt ) == types . IntType : <EOL> l . append ( _names . get ( elt , elt ) ) <EOL> elif type ( elt ) == types . StringType : <EOL> l . append ( elt ) <EOL> else : <EOL> l . append ( debug_tree ( elt ) ) <EOL> return l </s>
