/usr/lib/python2.7/dist-packages/examples/getvariable.py is in python-starpy 1.0.1.0.git.20140806-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #! /usr/bin/env python
"""Demonstrate usage of getVariable on the agi interface...
"""
from twisted.internet import reactor
from starpy import fastagi
import utilapplication
import logging, time, pprint
log = logging.getLogger( 'hellofastagi' )
def envVars( agi ):
"""Print out channel variables for display"""
vars = [
x.split( ' -- ' )[0].strip()
for x in agi.getVariable.__doc__.splitlines()
if len(x.split( ' -- ' )) == 2
]
for var in vars:
yield var
def printVar( result, agi, vars ):
"""Print out the variables produced by envVars"""
def doPrint( result, var ):
print '%r -- %r'%( var, result )
def notAvailable( reason, var ):
print '%r -- UNDEFINED'%( var, )
try:
var = vars.next()
except StopIteration, err:
return None
else:
return agi.getVariable( var ).addCallback( doPrint, var ).addErrback(
notAvailable, var,
).addCallback(
printVar, agi, vars,
)
def testFunction( agi ):
"""Print out known AGI variables"""
log.debug( 'testFunction' )
print 'AGI Variables'
pprint.pprint( agi.variables )
print 'Channel Variables'
sequence = fastagi.InSequence()
sequence.append( printVar, None, agi, envVars(agi) )
sequence.append( agi.finish )
def onFailure( reason ):
log.error( "Failure: %s", reason.getTraceback())
agi.finish()
return sequence().addErrback( onFailure )
if __name__ == "__main__":
logging.basicConfig()
#fastagi.log.setLevel( logging.DEBUG )
APPLICATION = utilapplication.UtilApplication()
APPLICATION.handleCallsFor( 's', testFunction )
APPLICATION.agiSpecifier.run( APPLICATION.dispatchIncomingCall )
reactor.run()
|