diff --git a/apps/click2dial/example.py b/apps/click2dial/example.py index 8548d463..fc3d7a70 100644 --- a/apps/click2dial/example.py +++ b/apps/click2dial/example.py @@ -10,6 +10,8 @@ # of the R-Uri to correctly route it to the destination. ######################################################################## +from xmlrpclib import * + proxy = "192.168.100.10" xmlrpc_url = "http://127.0.0.1:8090" @@ -24,12 +26,11 @@ auth_realm = "iptel.org" announce_file = "default_en" -from xmlrpclib import * s = ServerProxy(xmlrpc_url) s.dial_auth_b2b( - "click2dial", announce_file, - "sip:" + caller_user + "@" + caller_domain, - "sip:" + callee_user + "@" + callee_domain, + "click2dial", announce_file, + "sip:" + caller_user + "@" + caller_domain, + "sip:" + callee_user + "@" + callee_domain, "sip:" + caller_user + "@" + proxy + ";sw_domain=" + caller_domain, "sip:" + callee_user + "@" + proxy + ";sw_domain=" + callee_domain, auth_realm, auth_user, auth_pass) diff --git a/apps/conf_auth/conf_auth.py b/apps/conf_auth/conf_auth.py index 3a1ef2dd..ec8d5965 100644 --- a/apps/conf_auth/conf_auth.py +++ b/apps/conf_auth/conf_auth.py @@ -20,11 +20,13 @@ connected = 2 HINT_TIMER = 1 CONF_TIMER = 2 + def loopedTTS(str): af = IvrAudioFile.tts(str) af.loop = True return af + class IvrDialog(IvrDialogBase): welcome_msg = None auth_ok_msg = None @@ -37,7 +39,7 @@ class IvrDialog(IvrDialogBase): conf_to = '' conf_uri = '' conf_duration = 0 - + def sessionInfo(self): print("IVR Session info:") print(" user: ", self.dialog.user) @@ -59,7 +61,7 @@ class IvrDialog(IvrDialogBase): def onSessionStart(self): self.sessionInfo() self.setNoRelayonly() - self.welcome_msg = IvrAudioFile.tts("Welcome to the conferencing server. "+ \ + self.welcome_msg = IvrAudioFile.tts("Welcome to the conferencing server. " + "Please enter your PIN number, followed by the star key.") self.auth_ok_msg = IvrAudioFile.tts("Your PIN number is correct, you will be connected now.") # self.auth_fail_msg = IvrAudioFile.tts("Sorry, you have entered an invalid PIN number. " + \ @@ -68,22 +70,22 @@ class IvrDialog(IvrDialogBase): self.enqueue(self.welcome_msg,None) - def onBye(self): + def onBye(self): self.stopSession() def onDtmf(self,key,duration): if self.state == collect: self.flush() if key == 10: - + c = xmlrpclib.ServerProxy(server_path ) - erg = c.AuthorizeConference(self.dialog.remote_uri, + erg = c.AuthorizeConference(self.dialog.remote_uri, self.dialog.local_party, self.keys) debug('result of authentication: '+ str(erg)) if erg[0] == 'OK': self.flush() - self.enqueue(self.auth_ok_msg, None) + self.enqueue(self.auth_ok_msg, None) self.conf_to = erg[1] self.conf_uri = erg[2] self.conf_duration = erg[3] @@ -95,9 +97,9 @@ class IvrDialog(IvrDialogBase): self.auth_fail_msg.open(erg[1], ivr.AUDIO_READ) #self.flush() self.enqueue(self.auth_fail_msg, None) - + self.setTimer(HINT_TIMER, HINT_TIMEOUT) - else: + else: self.keys += str(key) debug("added key, PIN = " + self.keys) self.setTimer(HINT_TIMER, HINT_TIMEOUT) @@ -123,4 +125,3 @@ class IvrDialog(IvrDialogBase): self.terminateOtherLeg() self.bye() self.stopSession() - diff --git a/apps/examples/db_announce/announcement.py b/apps/examples/db_announce/announcement.py index dec79532..9371ee31 100644 --- a/apps/examples/db_announce/announcement.py +++ b/apps/examples/db_announce/announcement.py @@ -11,7 +11,8 @@ # Use, copying, modification, and distribution without written # permission is not allowed. -import os, MySQLdb +import os +import MySQLdb from log import * from ivr import * diff --git a/apps/examples/ivr_examples/b2b_out.py b/apps/examples/ivr_examples/b2b_out.py index 988f6f71..4f322a61 100644 --- a/apps/examples/ivr_examples/b2b_out.py +++ b/apps/examples/ivr_examples/b2b_out.py @@ -1,15 +1,17 @@ -# (outgoing) ivr b2bua example # +# (outgoing) ivr b2bua example # + from log import * from ivr import * + class IvrDialog(IvrDialogBase): - + def onSessionStart(self): info("starting b2bua app ...") - self.setNoRelayonly() + self.setNoRelayonly() self.audio_msg = IvrAudioFile() self.audio_msg.open("/home/stefan/sub_nautilus.wav", AUDIO_READ) self.setTimer(1, 10) @@ -21,10 +23,10 @@ class IvrDialog(IvrDialogBase): def onTimer(self, timerid): self.disconnectMedia() debug('hello kitty') - self.connectCallee(self.dialog.local_party,self.dialog.local_uri, \ + self.connectCallee(self.dialog.local_party, self.dialog.local_uri, self.dialog.remote_party,self.dialog.remote_uri,) return - def onBye(self): + def onBye(self): self.stopSession() diff --git a/apps/examples/ivr_examples/b2bua.py b/apps/examples/ivr_examples/b2bua.py index 77951f51..a6e4cd01 100644 --- a/apps/examples/ivr_examples/b2bua.py +++ b/apps/examples/ivr_examples/b2bua.py @@ -1,26 +1,28 @@ -# +# # ivr b2bua script example # + from log import * from ivr import * WELLCOME_MSG = "wav/default_en.wav" CALLEE_URI = "sip:music@iptel.org" + class IvrDialog(IvrDialogBase): - + def onSessionStart(self): info("starting b2bua test ...") self.setNoRelayonly() - + self.welcome_msg = IvrAudioFile() self.welcome_msg.open(WELLCOME_MSG, AUDIO_READ) self.enqueue(self.welcome_msg,None) def onEmptyQueue(self): - + info("connecting to To: " + CALLEE_URI + " R-URI: " + CALLEE_URI) info("\n\n\n original headers are: ---->%s<----\n\n\n" % self.invite_req.hdrs) self.invite_req.hdrs += "P-SomeMoreFunky: headervalue\r\n" @@ -32,5 +34,5 @@ class IvrDialog(IvrDialogBase): return - def onBye(self): + def onBye(self): self.stopSession() diff --git a/apps/examples/ivr_examples/call_center.py b/apps/examples/ivr_examples/call_center.py index 039c76d5..39d09331 100644 --- a/apps/examples/ivr_examples/call_center.py +++ b/apps/examples/ivr_examples/call_center.py @@ -16,6 +16,7 @@ beeping = 1 connecting = 2 connected = 3 + class IvrDialog(IvrDialogBase): def onSessionStart(self): @@ -40,7 +41,7 @@ class IvrDialog(IvrDialogBase): return return - + def onOtherReply(self, code, reason): debug('call_center: got reply: ' + str(code) + ' ' + reason) diff --git a/apps/examples/ivr_examples/db_balance.py b/apps/examples/ivr_examples/db_balance.py index f1041f26..b424f21c 100644 --- a/apps/examples/ivr_examples/db_balance.py +++ b/apps/examples/ivr_examples/db_balance.py @@ -4,7 +4,7 @@ # mysql> create database business; # mysql> create table business.accounts (user VARCHAR(100), bal_int INT, bal_decimal INT); # -# set TTS=y in apps/ivr/Makefile.defs, or rewrite with +# set TTS=y in apps/ivr/Makefile.defs, or rewrite with # enqueuing the parts of the sentence, like # self.ttsfile1 = IvrAudioFile() # self.ttsfile1.open("your_account_balance.wav", AUDIO_READ) @@ -23,6 +23,7 @@ db = MySQLdb.connection(host="127.0.0.1", user="root", passwd="sa07", db="busine # or, when using config file db_balance.conf: #db = MySQLdb.connection(host=config["db_host"], user=config["db_user"], passwd=config["db_pwd"], db=config["db_db"]) + class IvrDialog(IvrDialogBase) : ttsfile = None @@ -30,13 +31,13 @@ class IvrDialog(IvrDialogBase) : db.query("select bal_int, bal_decimal from accounts where user='%s'" % self.dialog.user) r = db.store_result() res = r.fetch_row(1) - if len(res): - self.ttsfile = IvrAudioFile().tts("Your account balance is %i dollars and %i cents" % \ + if len(res): + self.ttsfile = IvrAudioFile().tts("Your account balance is %i dollars and %i cents" % (int(res[0][0]), int(res[0][1]))) else: self.ttsfile = IvrAudioFile().tts("Sorry, I do not know your account balance.") self.enqueue(self.ttsfile, None) - + def onEmptyQueue(self): self.bye() self.stopSession() diff --git a/apps/examples/ivr_examples/play.py b/apps/examples/ivr_examples/play.py index 93a1eed1..e145bfdc 100644 --- a/apps/examples/ivr_examples/play.py +++ b/apps/examples/ivr_examples/play.py @@ -6,6 +6,7 @@ from log import * from ivr import * from p_app_param.p_app_param import * + class IvrDialog(IvrDialogBase): def onInvite(self, hdrs): @@ -19,20 +20,20 @@ class IvrDialog(IvrDialogBase): if not self.file: self.file = "/tmp/default.wav" return True - + def onSessionStart(self): self.announcement = IvrAudioFile() self.announcement.open(self.file, ivr.AUDIO_READ, False) self.enqueue(self.announcement, None) return - + def onEmptyQueue(self): if not self.queueIsEmpty(): return self.bye() self.stopSession() return - + def onBye(self): self.stopSession() return diff --git a/apps/examples/ivr_examples/rec.py b/apps/examples/ivr_examples/rec.py index 2485f005..852da2de 100644 --- a/apps/examples/ivr_examples/rec.py +++ b/apps/examples/ivr_examples/rec.py @@ -1,9 +1,11 @@ # # just recording to file # + from log import * from ivr import * + class IvrDialog(IvrDialogBase) : def onSessionStart(self) : diff --git a/apps/examples/ivr_examples/test_mp3.py b/apps/examples/ivr_examples/test_mp3.py index c8e0156e..4326d5c8 100644 --- a/apps/examples/ivr_examples/test_mp3.py +++ b/apps/examples/ivr_examples/test_mp3.py @@ -4,6 +4,8 @@ from log import * from ivr import * + + class IvrDialog(IvrDialogBase): def onSessionStart(self): @@ -12,4 +14,3 @@ class IvrDialog(IvrDialogBase): self.enqueue(self.voice_msg, None) self.voice_msg.open("record.mp3", AUDIO_WRITE, False) self.enqueue(None, self.voice_msg) - diff --git a/apps/examples/ivr_examples/tmpfile.py b/apps/examples/ivr_examples/tmpfile.py index f2d63bfb..841683a2 100644 --- a/apps/examples/ivr_examples/tmpfile.py +++ b/apps/examples/ivr_examples/tmpfile.py @@ -1,10 +1,12 @@ # # using IvrAudioFile fpopen # + from log import * from ivr import * import os + class IvrDialog(IvrDialogBase): def onSessionStart(self): diff --git a/apps/examples/mixin_announce/mix_announce.py b/apps/examples/mixin_announce/mix_announce.py index fc38199a..7b39be79 100644 --- a/apps/examples/mixin_announce/mix_announce.py +++ b/apps/examples/mixin_announce/mix_announce.py @@ -2,6 +2,7 @@ from log import * from ivr import * + class IvrDialog(IvrDialogBase): mixin = None announcement = None diff --git a/apps/examples/py_sems_ex/early_media.py b/apps/examples/py_sems_ex/early_media.py index b170037b..41da9112 100644 --- a/apps/examples/py_sems_ex/early_media.py +++ b/apps/examples/py_sems_ex/early_media.py @@ -1,4 +1,7 @@ -import base64, time, os, sip +import base64 +import time +import os +import sip from py_sems_log import * from py_sems import * @@ -37,7 +40,7 @@ class PySemsScript(PySemsDialog): if self.dlg.reply(req, 183, "OK", "application/sdp", sdp_reply, "") != 0: self.setStopped() - except: + except Exception: self.dlg.reply(req, 500, "File not found", "", "", "") self.ann = None self.setStopped() @@ -100,7 +103,7 @@ class PySemsScript(PySemsDialog): code_i = int(code) if (code_i < 300) or (code_i > 699): debug("Invalid reply code: %d", code_i) - except: + except Exception: debug("Invalid reply code: %s", code) debug("Replying %d %s" % (code_i, reason)) diff --git a/apps/examples/py_sems_ex/jukecall.py b/apps/examples/py_sems_ex/jukecall.py index 24ac3f34..d10096c1 100644 --- a/apps/examples/py_sems_ex/jukecall.py +++ b/apps/examples/py_sems_ex/jukecall.py @@ -1,4 +1,7 @@ -import base64, time, os, sip +import base64 +import time +import os +import sip from py_sems_log import * from py_sems import * @@ -49,7 +52,7 @@ class PySemsScript(PySemsB2ABDialog): self.ann = AmAudioFile() try: self.ann.open(ann_file) - except: + except Exception: self.dlg.reply(req, 500, "File not found", "", "", "") self.ann = None self.setStopped() diff --git a/apps/examples/tutorial/annc_service/annc_service.py b/apps/examples/tutorial/annc_service/annc_service.py index 0d39a5e1..63f66f8d 100644 --- a/apps/examples/tutorial/annc_service/annc_service.py +++ b/apps/examples/tutorial/annc_service/annc_service.py @@ -1,5 +1,5 @@ # -# Simple implementation of (a part) of RFC4240 +# Simple implementation of (a part) of RFC4240 # announcement service. # # supported parameters: @@ -15,6 +15,7 @@ from os import unlink TIMEOUT_TIMER_ID = 1 DELAY_TIMER_ID = 2 + class IvrDialog(IvrDialogBase): announcement=None @@ -23,13 +24,13 @@ class IvrDialog(IvrDialogBase): delay=0 duration=-1 play="" - delete_onbye = False + delete_onbye = False repeat_left = 0 def onSessionStart(self,hdrs): debug("configuration: %s" % repr(config)) - debug("local_uri = " + self.dialog.local_uri); + debug("local_uri = " + self.dialog.local_uri) # we use urlsplit as urlparse only returns the # parameters of the last path params = urlsplit(self.dialog.local_uri)[2].split(";") diff --git a/apps/examples/tutorial/cc_acc_xmlrpc/server/xmlrpcserver.py b/apps/examples/tutorial/cc_acc_xmlrpc/server/xmlrpcserver.py index 365633fe..0617e627 100644 --- a/apps/examples/tutorial/cc_acc_xmlrpc/server/xmlrpcserver.py +++ b/apps/examples/tutorial/cc_acc_xmlrpc/server/xmlrpcserver.py @@ -6,6 +6,7 @@ import string server = SimpleXMLRPCServer(("localhost", 8000)) server.register_introspection_functions() + class MyFuncs: def getCredit(self, arg): print("Function getCredit") @@ -28,5 +29,6 @@ class MyFuncs: print(" credit: ", credit) return credit + server.register_instance(MyFuncs()) server.serve_forever() diff --git a/apps/examples/tutorial/ivr_announce/ivr_announce.py b/apps/examples/tutorial/ivr_announce/ivr_announce.py index a055ce15..d11ed174 100644 --- a/apps/examples/tutorial/ivr_announce/ivr_announce.py +++ b/apps/examples/tutorial/ivr_announce/ivr_announce.py @@ -2,6 +2,7 @@ from log import * from ivr import * + class IvrDialog(IvrDialogBase): announcement = None diff --git a/apps/ivr/moc/ivr.py b/apps/ivr/moc/ivr.py index fa658f28..965b95c6 100644 --- a/apps/ivr/moc/ivr.py +++ b/apps/ivr/moc/ivr.py @@ -4,9 +4,11 @@ config = dict() AUDIO_READ = 0 AUDIO_WRITE = 1 + def getHeader(str1,str2): pass + class IvrDialogBase: def enqueue(self,a1,a2): @@ -17,10 +19,11 @@ class IvrDialogBase: def bye(self): pass - + def stopSession(self): pass + class IvrAudioFile: def open(self,filename,mode): diff --git a/apps/ivr/py/log.py b/apps/ivr/py/log.py index f5f62b81..4af960eb 100644 --- a/apps/ivr/py/log.py +++ b/apps/ivr/py/log.py @@ -7,33 +7,39 @@ L_WARN = 1 L_INFO = 2 L_DBG = 3 + def log(level, msg, args): - if args != None: + if args is not None: tmp_msg = msg % args else: tmp_msg = msg - + ivr.log(level,"Ivr-Python: " + tmp_msg + "\n") def error(msg, args=None): log(L_ERR, msg, args) + def warn(msg, args=None): log(L_WARN, msg, args) + def info(msg, args=None): log(L_INFO, msg, args) - + + def debug(msg, args=None): log(L_DBG, msg, args) def stacktrace(tb): - if tb: last_file = stacktrace(tb.tb_next) - else: return + if tb: + last_file = stacktrace(tb.tb_next) + else: + return f = tb.tb_frame.f_code.co_filename line = tb.tb_frame.f_lineno @@ -53,7 +59,6 @@ def log_excepthook(exception, value, tb): error('********** end of Ivr-Python exception report *********') - # init code sys.excepthook = log_excepthook debug("Python-Ivr logging started") diff --git a/apps/mailbox/imap_mailbox/MailboxURL.py b/apps/mailbox/imap_mailbox/MailboxURL.py index c00f05eb..792be352 100644 --- a/apps/mailbox/imap_mailbox/MailboxURL.py +++ b/apps/mailbox/imap_mailbox/MailboxURL.py @@ -1,7 +1,8 @@ import re -class InvalidMailboxURL(Exception): + +class InvalidMailboxURL(Exception): def __init__(self,value): self.value = value @@ -11,7 +12,6 @@ class InvalidMailboxURL(Exception): class MailboxURL: - url = "" user = "" passwd = "" @@ -23,7 +23,6 @@ class MailboxURL: self.url = url self._parse() - def _parse(self): m = re.match('imap://(.+):(.+)@(.+):([0-9]+)/(.+)',self.url) if m is None: @@ -42,5 +41,3 @@ class MailboxURL: ("host:\t%s\n" % self.host) + \ ("port:\t%i\n" % self.port) + \ ("path:\t%s\n" % self.path) - - diff --git a/apps/mailbox/imap_mailbox/imap4ext.py b/apps/mailbox/imap_mailbox/imap4ext.py index f946b4cc..60915732 100644 --- a/apps/mailbox/imap_mailbox/imap4ext.py +++ b/apps/mailbox/imap_mailbox/imap4ext.py @@ -1,4 +1,6 @@ -import os,base64,time +import os +import base64 +import time from imaplib import IMAP4 from MailboxURL import * @@ -20,7 +22,7 @@ class IMAP4_MsgBODY: uid = '' parts = [] ct = '' - + def __init__(self,imap,uid): self.uid = '' @@ -40,16 +42,16 @@ class IMAP4_MsgBODY: (t,d) = imap.uid('fetch',self.uid,'(BODY.PEEK[%i])' % (part+1)) if (t != "OK") or (len(d[0]) != 2): - raise IMAP4.error("could not retrieve part %s/%i" \ + raise IMAP4.error("could not retrieve part %s/%i" % (self.uid, part+1)) - + msg = d[0][1] msg = base64.decodestring(msg) if filename is None: out_file = os.tmpfile() else: out_file = open(filename,'w+') - + out_file.write(msg) out_file.seek(0) @@ -59,11 +61,10 @@ class IMAP4_MsgBODY: out_file.close() return None - def _parse_body_desc(self,desc): (_dummy,s) = self._parenthesis2seq(desc)[1] - + self.uid = s[1] if type(s[3][0]) is not str: @@ -78,7 +79,6 @@ class IMAP4_MsgBODY: self.parts.append(s[3]) self.ct = s[3][0] - def _parenthesis2seq(self,s,ibeg=0): seq = [] @@ -90,7 +90,7 @@ class IMAP4_MsgBODY: (i,tmp_seq) = self._parenthesis2seq(s,i+1) elmt_beg = i seq.append(tmp_seq) - + elif s[i] == ')': if elmt_beg < i: seq.append(s[elmt_beg:i]) @@ -110,7 +110,6 @@ class IMAP4_MsgBODY: return (i,seq) - class IMAP4_Mailbox: url = None @@ -123,25 +122,22 @@ class IMAP4_Mailbox: def __del__(self): - if self.imap != None: + if self.imap is not None: self.imap.logout() self.imap = None - def createBox(self): self._login() - debug("Creating account: " + \ + debug("Creating account: " + repr(IMAPCALL(self.imap.create(self.url.path)))) - def deleteBox(self): self._login() - debug("Deleting account: " + \ + debug("Deleting account: " + repr(IMAPCALL(self.imap.delete(self.url.path)))) - def uploadMsg(self,msg): self._login() IMAPCALL(self.imap.append(self.url.path,None,time.gmtime(),msg)) @@ -179,9 +175,8 @@ class IMAP4_Mailbox: IMAPCALL(self.imap.close()) return msg_list - def downloadWAV(self,msg_uid): - + self._login() IMAPCALL(self.imap.select(self.url.path)) body = IMAP4_MsgBODY(self.imap,msg_uid) @@ -194,13 +189,12 @@ class IMAP4_Mailbox: IMAPCALL(self.imap.close()) return fp - def downloadWAVs(self,search_criterion,file_prefix): self._login() IMAPCALL(self.imap.select(self.url.path)) - + (t,d) = self.imap.uid('SEARCH',search_criterion) IMAPCALL((t,d)) @@ -208,27 +202,26 @@ class IMAP4_Mailbox: for i in d[0].split(): body = IMAP4_MsgBODY(self.imap,i) - + for p in range(len(body.parts)): - + if body.part_ct(p).upper() == 'AUDIO/X-WAV': - + filename = file_prefix + '-' + body.uid + '.wav' msg_list.append(filename) body.fetch2file(self.imap,p,filename) - + IMAPCALL(self.imap.close()) return msg_list def _login(self): - if self.imap != None: + if self.imap is not None: return self.imap = IMAP4(self.url.host,self.url.port) try: IMAPCALL(self.imap.login(self.url.user,self.url.passwd)) - except: + except IMAP4.error: self.imap = None raise - diff --git a/apps/mailbox/mailbox.py b/apps/mailbox/mailbox.py index d4aa00ab..0992dcb0 100644 --- a/apps/mailbox/mailbox.py +++ b/apps/mailbox/mailbox.py @@ -1,4 +1,5 @@ -import base64,time +import base64 +import time from log import * from ivr import * @@ -16,7 +17,7 @@ class IvrDialog(IvrDialogBase): def onSessionStart(self): debug("config: %s" % repr(config)) - self.mailbox = IMAP4_Mailbox(getAppParam("Mailbox-URL")); + self.mailbox = IMAP4_Mailbox(getAppParam("Mailbox-URL")) debug("***** Mailbox Url: ******\n" + str(self.mailbox.url)) self.announcement = IvrAudioFile() @@ -32,27 +33,21 @@ class IvrDialog(IvrDialogBase): self.enqueue(self.announcement,None) self.enqueue(self.beep,None) self.enqueue(None,self.voice_msg) - - + def onBye(self): - + self.stopSession() self.saveMsg() - def onEmptyQueue(self): - - self.bye() self.stopSession() self.saveMsg() - def onDtmf(self,key,duration): - - pass + pass def saveMsg(self): @@ -71,5 +66,5 @@ class IvrDialog(IvrDialogBase): enc_msg #debug("msg = <%s>",msg); - + self.mailbox.uploadMsg(msg) diff --git a/apps/mailbox/mailbox_query.py b/apps/mailbox/mailbox_query.py index 14e5b929..b99c1241 100644 --- a/apps/mailbox/mailbox_query.py +++ b/apps/mailbox/mailbox_query.py @@ -1,4 +1,5 @@ -import os,weakref +import os +import weakref from log import * from ivr import * @@ -18,34 +19,28 @@ class VoiceMsg: self._mb = mb self._audio = None - def _load(self): self._fp = self._mb.downloadWAV(self._uid) self._audio = IvrAudioFile() self._audio.fpopen("tmp.wav",AUDIO_READ,self._fp) - def audio(self): - if self._audio == None: + if self._audio is None: self._load() - - return self._audio + return self._audio def save(self): self._mb.saveMsg(self._uid) - def delete(self): self._mb.deleteMsg(self._uid) - - class IvrDialog(IvrDialogBase): def __init__(self): @@ -59,12 +54,11 @@ class IvrDialog(IvrDialogBase): self.cur_msg = 0 self.exit = False - - self.key_enabled = False + self.key_enabled = False def loadVoiceLib(self): - + self.voice_lib = dict() # Parts for the welcome text @@ -95,23 +89,21 @@ class IvrDialog(IvrDialogBase): # Menu will be looped until a key is pressed self.voice_lib['msg_menu'].loop = True - def loadMsgList(self,criterion): msg_list = List() name_list = self.mailbox.getWavMsgList(criterion) for n in name_list: msg_list.append(VoiceMsg(n,self.mailbox)) - - return msg_list + return msg_list def onSessionStart(self): self.__init__() self.loadVoiceLib() - self.mailbox = IMAP4_Mailbox(getAppParam("Mailbox-URL")); + self.mailbox = IMAP4_Mailbox(getAppParam("Mailbox-URL")) debug("***** Mailbox Url: ******\n" + str(self.mailbox.url)) self.new_msgs = self.loadMsgList('UNSEEN') @@ -119,20 +111,20 @@ class IvrDialog(IvrDialogBase): if (len(self.new_msgs) == 0) and \ (len(self.saved_msgs) == 0): - + self.enqueue(self.voice_lib['no_msg'],None) self.enqueue(self.voice_lib['bye'],None) self.exit = True return - + self.enqueue(self.voice_lib['you_have'],None) if len(self.new_msgs) > 0: - + self.enqueue(self.voice_lib['new_msg'],None) self.msg_list = weakref.proxy(self.new_msgs) self.cur_list = weakref.ref(self.new_msgs) - + if len(self.saved_msgs) > 0: self.enqueue(self.voice_lib['and'],None) self.enqueue(self.voice_lib['saved_msg'],None) @@ -142,13 +134,11 @@ class IvrDialog(IvrDialogBase): self.cur_list = weakref.ref(self.saved_msgs) self.enqueueCurMsg() - def onBye(self): - + self.stopSession() - def onEmptyQueue(self): if self.exit: @@ -156,7 +146,6 @@ class IvrDialog(IvrDialogBase): self.bye() self.stopSession() - def onDtmf(self,key,duration): if not self.key_enabled: @@ -166,7 +155,6 @@ class IvrDialog(IvrDialogBase): if key == 1: self.flush() - elif key == 2: self.key_enabled = False @@ -174,7 +162,7 @@ class IvrDialog(IvrDialogBase): self.msg_list[self.cur_msg].save() self.enqueue(self.voice_lib['msg_saved'],None) self.cur_msg += 1 - + elif key == 3: self.key_enabled = False self.flush() @@ -183,27 +171,26 @@ class IvrDialog(IvrDialogBase): self.cur_msg += 1 else: return - + if not self.enqueueCurMsg(): debug("self.cur_list() is self.new_msgs = %s" % repr(self.cur_list() is self.new_msgs)) debug("len(self.saved_msgs) = %i" % len(self.saved_msgs)) - + if (self.cur_list() is self.new_msgs) and \ len(self.saved_msgs) > 0: - + self.cur_msg = 0 - + self.msg_list = weakref.proxy(self.saved_msgs) self.cur_list = weakref.ref(self.saved_msgs) - + self.enqueue(self.voice_lib['saved_msg'],None) self.enqueueCurMsg() else: self.enqueue(self.voice_lib['bye'],None) self.exit = True - def enqueueCurMsg(self): if self.cur_msg >= len(self.msg_list): @@ -213,10 +200,10 @@ class IvrDialog(IvrDialogBase): self.enqueue(self.voice_lib['next_msg'],None) else: self.enqueue(self.voice_lib['first_msg'],None) - + self.enqueue(self.msg_list[self.cur_msg].audio(),None) self.enqueue(self.voice_lib['msg_menu'],None) - + self.key_enabled = True return True diff --git a/apps/mobile_push/load_test/call_gen.py b/apps/mobile_push/load_test/call_gen.py index 724f558b..3d0eb83f 100755 --- a/apps/mobile_push/load_test/call_gen.py +++ b/apps/mobile_push/load_test/call_gen.py @@ -1,5 +1,6 @@ #!/usr/bin/env python -from xmlrpclib import * + +from xmlrpclib import * + s = ServerProxy('http://127.0.0.1:8092') print(s.setTarget(100, 1, 0, '4', '192.168.5.110', 2, 0, 30, 40)) - diff --git a/apps/mobile_push/load_test/example_server.py b/apps/mobile_push/load_test/example_server.py index 8187bd83..f7a68cab 100644 --- a/apps/mobile_push/load_test/example_server.py +++ b/apps/mobile_push/load_test/example_server.py @@ -11,6 +11,7 @@ class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): s.send_response(200) s.send_header("Content-type", "text/html") s.end_headers() + def do_GET(s): """Respond to a GET request.""" s.send_response(200) @@ -23,6 +24,7 @@ class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): s.wfile.write("
You accessed path: %s
" % s.path) s.wfile.write("