<s> """<STR_LIT>""" <EOL> from twisted . internet import reactor <EOL> from starpy import fastagi <EOL> import utilapplication <EOL> import logging , time , pprint <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> def envVars ( agi ) : <EOL> """<STR_LIT>""" <EOL> vars = [ <EOL> x . split ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . strip ( ) <EOL> for x in agi . getVariable . __doc__ . splitlines ( ) <EOL> if len ( x . split ( '<STR_LIT>' ) ) == <NUM_LIT:2> <EOL> ] <EOL> for var in vars : <EOL> yield var <EOL> def printVar ( result , agi , vars ) : <EOL> """<STR_LIT>""" <EOL> def doPrint ( result , var ) : <EOL> print '<STR_LIT>' % ( var , result ) <EOL> def notAvailable ( reason , var ) : <EOL> print '<STR_LIT>' % ( var , ) <EOL> try : <EOL> var = vars . next ( ) <EOL> except StopIteration , err : <EOL> return None <EOL> else : <EOL> return agi . getVariable ( var ) . addCallback ( doPrint , var ) . addErrback ( <EOL> notAvailable , var , <EOL> ) . addCallback ( <EOL> printVar , agi , vars , <EOL> ) <EOL> def testFunction ( agi ) : <EOL> """<STR_LIT>""" <EOL> log . debug ( '<STR_LIT>' ) <EOL> print '<STR_LIT>' <EOL> pprint . pprint ( agi . variables ) <EOL> print '<STR_LIT>' <EOL> sequence = fastagi . InSequence ( ) <EOL> sequence . append ( printVar , None , agi , envVars ( agi ) ) <EOL> sequence . append ( agi . finish ) <EOL> def onFailure ( reason ) : <EOL> log . error ( "<STR_LIT>" , reason . getTraceback ( ) ) <EOL> agi . finish ( ) <EOL> return sequence ( ) . addErrback ( onFailure ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> logging . basicConfig ( ) <EOL> APPLICATION = utilapplication . UtilApplication ( ) <EOL> APPLICATION . handleCallsFor ( '<STR_LIT:s>' , testFunction ) <EOL> APPLICATION . agiSpecifier . run ( APPLICATION . dispatchIncomingCall ) <EOL> reactor . run ( ) </s>
