<s> """<STR_LIT>""" <EOL> try : <EOL> import json as jsonlib <EOL> except ImportError : <EOL> try : <EOL> import simplejson as jsonlib <EOL> except : <EOL> import gluon . contrib . simplejson as jsonlib <EOL> import logging <EOL> class TropoAction ( object ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def json ( self ) : <EOL> return self . _dict <EOL> @ property <EOL> def obj ( self ) : <EOL> return { self . action : self . _dict } <EOL> class Ask ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , choices , ** options ) : <EOL> self . _dict = { } <EOL> if ( isinstance ( choices , basestring ) ) : <EOL> self . _dict [ '<STR_LIT>' ] = Choices ( choices ) . json <EOL> else : <EOL> self . _dict [ '<STR_LIT>' ] = choices [ '<STR_LIT>' ] <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> if ( ( opt == '<STR_LIT>' ) and ( isinstance ( options [ '<STR_LIT>' ] , basestring ) ) ) : <EOL> self . _dict [ '<STR_LIT>' ] = Say ( options [ '<STR_LIT>' ] ) . json <EOL> else : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class Call ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , to , ** options ) : <EOL> self . _dict = { '<STR_LIT:to>' : to } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class Choices ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , value , ** options ) : <EOL> self . _dict = { '<STR_LIT:value>' : value } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class Conference ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , id , ** options ) : <EOL> self . _dict = { '<STR_LIT:id>' : id } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class Hangup ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> self . _dict = { } <EOL> class Message ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT:message>' <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , say_obj , to , ** options ) : <EOL> self . _dict = { '<STR_LIT>' : say_obj [ '<STR_LIT>' ] , '<STR_LIT:to>' : to } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class On ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , event , ** options ) : <EOL> self . _dict = { '<STR_LIT>' : event } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> if ( ( opt == '<STR_LIT>' ) and ( isinstance ( options [ '<STR_LIT>' ] , basestring ) ) ) : <EOL> self . _dict [ '<STR_LIT>' ] = Say ( options [ '<STR_LIT>' ] ) . json <EOL> else : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class Record ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT:password>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:url>' , '<STR_LIT:username>' ] <EOL> def __init__ ( self , ** options ) : <EOL> self . _dict = { } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> if ( ( opt == '<STR_LIT>' ) and ( isinstance ( options [ '<STR_LIT>' ] , basestring ) ) ) : <EOL> self . _dict [ '<STR_LIT>' ] = Say ( options [ '<STR_LIT>' ] ) . json <EOL> else : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class Redirect ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT:name>' , '<STR_LIT>' ] <EOL> def __init__ ( self , to , ** options ) : <EOL> self . _dict = { '<STR_LIT:to>' : to } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class Reject ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> self . _dict = { } <EOL> class Say ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , message , ** options ) : <EOL> dict = { } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> dict [ opt ] = options [ opt ] <EOL> self . _list = [ ] <EOL> if ( isinstance ( message , list ) ) : <EOL> for mess in message : <EOL> new_dict = dict . copy ( ) <EOL> new_dict [ '<STR_LIT:value>' ] = mess <EOL> self . _list . append ( new_dict ) <EOL> else : <EOL> dict [ '<STR_LIT:value>' ] = message <EOL> self . _list . append ( dict ) <EOL> @ property <EOL> def json ( self ) : <EOL> return self . _list [ <NUM_LIT:0> ] if len ( self . _list ) == <NUM_LIT:1> else self . _list <EOL> @ property <EOL> def obj ( self ) : <EOL> return { self . action : self . _list [ <NUM_LIT:0> ] } if len ( self . _list ) == <NUM_LIT:1> else { self . action : self . _list } <EOL> class StartRecording ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:username>' , '<STR_LIT:password>' ] <EOL> def __init__ ( self , url , ** options ) : <EOL> self . _dict = { '<STR_LIT:url>' : url } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class StopRecording ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> self . _dict = { } <EOL> class Transfer ( TropoAction ) : <EOL> """<STR_LIT>""" <EOL> action = '<STR_LIT>' <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , to , ** options ) : <EOL> self . _dict = { '<STR_LIT:to>' : to } <EOL> for opt in self . options_array : <EOL> if opt in options : <EOL> if ( opt == '<STR_LIT>' ) : <EOL> self . _dict [ '<STR_LIT>' ] = options [ '<STR_LIT>' ] <EOL> elif ( opt == '<STR_LIT>' ) : <EOL> self . _dict [ '<STR_LIT>' ] = { '<STR_LIT:value>' : options [ '<STR_LIT>' ] } <EOL> else : <EOL> self . _dict [ opt ] = options [ opt ] <EOL> class Result ( object ) : <EOL> """<STR_LIT>""" <EOL> options_array = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:error>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:state>' ] <EOL> def __init__ ( self , result_json ) : <EOL> logging . info ( "<STR_LIT>" % result_json ) <EOL> result_data = jsonlib . loads ( result_json ) <EOL> result_dict = result_data [ '<STR_LIT:result>' ] <EOL> for opt in self . options_array : <EOL> if result_dict . get ( opt , False ) : <EOL> setattr ( self , '<STR_LIT>' % opt , result_dict [ opt ] ) <EOL> def getValue ( self ) : <EOL> """<STR_LIT>""" <EOL> actions = self . _actions <EOL> if ( type ( actions ) is list ) : <EOL> logging . info ( "<STR_LIT>" ) <EOL> dict = actions [ <NUM_LIT:0> ] <EOL> else : <EOL> logging . info ( "<STR_LIT>" ) <EOL> dict = actions <EOL> logging . info ( "<STR_LIT>" % actions ) <EOL> return dict [ '<STR_LIT>' ] <EOL> class Session ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , session_json ) : <EOL> logging . info ( "<STR_LIT>" % session_json ) <EOL> session_data = jsonlib . loads ( session_json ) <EOL> session_dict = session_data [ '<STR_LIT>' ] <EOL> for key in session_dict : <EOL> val = session_dict [ key ] <EOL> logging . info ( "<STR_LIT>" % ( key , val ) ) <EOL> if key == "<STR_LIT>" : <EOL> setattr ( self , "<STR_LIT>" , val ) <EOL> else : <EOL> setattr ( self , key , val ) <EOL> setattr ( self , '<STR_LIT>' , session_dict ) <EOL> class Tropo ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _steps = [ ] <EOL> def ask ( self , choices , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( Ask ( choices , ** options ) . obj ) <EOL> def call ( self , to , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( Call ( to , ** options ) . obj ) <EOL> def conference ( self , id , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( Conference ( id , ** options ) . obj ) <EOL> def hangup ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( Hangup ( ) . obj ) <EOL> def message ( self , say_obj , to , ** options ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( say_obj , basestring ) : <EOL> say = Say ( say_obj ) . obj <EOL> else : <EOL> say = say_obj <EOL> self . _steps . append ( Message ( say , to , ** options ) . obj ) <EOL> def on ( self , event , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( On ( event , ** options ) . obj ) <EOL> def record ( self , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( Record ( ** options ) . obj ) <EOL> def redirect ( self , id , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( Redirect ( id , ** options ) . obj ) <EOL> def reject ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( Reject ( ) . obj ) <EOL> def say ( self , message , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( Say ( message , ** options ) . obj ) <EOL> def startRecording ( self , url , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( StartRecording ( url , ** options ) . obj ) <EOL> def stopRecording ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( StopRecording ( ) . obj ) <EOL> def transfer ( self , to , ** options ) : <EOL> """<STR_LIT>""" <EOL> self . _steps . append ( Transfer ( to , ** options ) . obj ) <EOL> def RenderJson ( self , pretty = False ) : <EOL> """<STR_LIT>""" <EOL> steps = self . _steps <EOL> topdict = { } <EOL> topdict [ '<STR_LIT>' ] = steps <EOL> logging . info ( "<STR_LIT>" % topdict ) <EOL> if pretty : <EOL> try : <EOL> json = jsonlib . dumps ( topdict , indent = <NUM_LIT:4> , sort_keys = False ) <EOL> except TypeError : <EOL> json = jsonlib . dumps ( topdict ) <EOL> else : <EOL> json = jsonlib . dumps ( topdict ) <EOL> return json <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print """<STR_LIT>""" </s>
