<s> """<STR_LIT>""" <EOL> from mako import exceptions , pyparser , compat <EOL> import re <EOL> class PythonCode ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code , ** exception_kwargs ) : <EOL> self . code = code <EOL> self . declared_identifiers = set ( ) <EOL> self . undeclared_identifiers = set ( ) <EOL> if isinstance ( code , compat . string_types ) : <EOL> expr = pyparser . parse ( code . lstrip ( ) , "<STR_LIT>" , ** exception_kwargs ) <EOL> else : <EOL> expr = code <EOL> f = pyparser . FindIdentifiers ( self , ** exception_kwargs ) <EOL> f . visit ( expr ) <EOL> class ArgumentList ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code , ** exception_kwargs ) : <EOL> self . codeargs = [ ] <EOL> self . args = [ ] <EOL> self . declared_identifiers = set ( ) <EOL> self . undeclared_identifiers = set ( ) <EOL> if isinstance ( code , compat . string_types ) : <EOL> if re . match ( r"<STR_LIT>" , code ) and not re . match ( r"<STR_LIT>" , code ) : <EOL> code += "<STR_LIT:U+002C>" <EOL> expr = pyparser . parse ( code , "<STR_LIT>" , ** exception_kwargs ) <EOL> else : <EOL> expr = code <EOL> f = pyparser . FindTuple ( self , PythonCode , ** exception_kwargs ) <EOL> f . visit ( expr ) <EOL> class PythonFragment ( PythonCode ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code , ** exception_kwargs ) : <EOL> m = re . match ( r'<STR_LIT>' , code . strip ( ) , re . S ) <EOL> if not m : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" % <EOL> code , ** exception_kwargs ) <EOL> if m . group ( <NUM_LIT:3> ) : <EOL> code = code [ : m . start ( <NUM_LIT:3> ) ] <EOL> ( keyword , expr ) = m . group ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> if keyword in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> code = code + "<STR_LIT>" <EOL> elif keyword == '<STR_LIT>' : <EOL> code = code + "<STR_LIT>" <EOL> elif keyword == '<STR_LIT>' or keyword == '<STR_LIT>' : <EOL> code = "<STR_LIT>" + code + "<STR_LIT>" <EOL> elif keyword == '<STR_LIT>' : <EOL> code = "<STR_LIT>" + code + "<STR_LIT>" <EOL> elif keyword == '<STR_LIT>' : <EOL> code = code + "<STR_LIT>" <EOL> else : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" % <EOL> keyword , ** exception_kwargs ) <EOL> super ( PythonFragment , self ) . __init__ ( code , ** exception_kwargs ) <EOL> class FunctionDecl ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code , allow_kwargs = True , ** exception_kwargs ) : <EOL> self . code = code <EOL> expr = pyparser . parse ( code , "<STR_LIT>" , ** exception_kwargs ) <EOL> f = pyparser . ParseFunc ( self , ** exception_kwargs ) <EOL> f . visit ( expr ) <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" % code , <EOL> ** exception_kwargs ) <EOL> if not allow_kwargs and self . kwargs : <EOL> raise exceptions . CompileException ( <EOL> "<STR_LIT>" % <EOL> self . argnames [ - <NUM_LIT:1> ] , ** exception_kwargs ) <EOL> def get_argument_expressions ( self , include_defaults = True ) : <EOL> """<STR_LIT>""" <EOL> namedecls = [ ] <EOL> defaults = [ d for d in self . defaults ] <EOL> kwargs = self . kwargs <EOL> varargs = self . varargs <EOL> argnames = [ f for f in self . argnames ] <EOL> argnames . reverse ( ) <EOL> for arg in argnames : <EOL> default = None <EOL> if kwargs : <EOL> arg = "<STR_LIT>" + arg <EOL> kwargs = False <EOL> elif varargs : <EOL> arg = "<STR_LIT:*>" + arg <EOL> varargs = False <EOL> else : <EOL> default = len ( defaults ) and defaults . pop ( ) or None <EOL> if include_defaults and default : <EOL> namedecls . insert ( <NUM_LIT:0> , "<STR_LIT>" % <EOL> ( arg , <EOL> pyparser . ExpressionGenerator ( default ) . value ( ) <EOL> ) <EOL> ) <EOL> else : <EOL> namedecls . insert ( <NUM_LIT:0> , arg ) <EOL> return namedecls <EOL> class FunctionArgs ( FunctionDecl ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code , ** kwargs ) : <EOL> super ( FunctionArgs , self ) . __init__ ( "<STR_LIT>" % code , <EOL> ** kwargs ) </s>
