[sip] Utilisation d'erreur custom
This commit is contained in:
parent
a7a732ab68
commit
e1019a34b4
2 changed files with 12 additions and 6 deletions
|
@ -19,6 +19,9 @@ import lc_ldap.shortcuts
|
|||
class NullRecv(EnvironmentError):
|
||||
pass
|
||||
|
||||
class AsteriskError(ValueError):
|
||||
pass
|
||||
|
||||
class Profile(object):
|
||||
def __init__(self, sql_params, database):
|
||||
self.sql_params = sql_params
|
||||
|
@ -177,7 +180,7 @@ class Manager(object):
|
|||
self._event=[]
|
||||
self._event_callback = {}
|
||||
self._toread = ""
|
||||
self.privilege = []
|
||||
self.fullybooted = False
|
||||
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
@ -187,7 +190,7 @@ class Manager(object):
|
|||
self.connect()
|
||||
|
||||
def _FullyBooted(self, manager, params):
|
||||
manager.privilege = params['Privilege'].split(',')
|
||||
manager.fullybooted = True
|
||||
|
||||
def _recv(self):
|
||||
data = self.socket.recv(1024)
|
||||
|
@ -244,7 +247,7 @@ class Manager(object):
|
|||
del(self._response[id])
|
||||
self._pending_action.remove(id)
|
||||
if response[0] == 'Error':
|
||||
raise ValueError(response)
|
||||
raise AsteriskError('%s. Action:%s params:%s' % (response[1]['Message'], name, params))
|
||||
return response
|
||||
|
||||
def action(self, name, **params):
|
||||
|
@ -260,6 +263,7 @@ class Manager(object):
|
|||
if len(msg)>1:
|
||||
self._toread += msg[1]
|
||||
self.login()
|
||||
while not self.fullybooted:
|
||||
self.process_events()
|
||||
self.events(self.event)
|
||||
|
||||
|
@ -285,7 +289,9 @@ class Manager(object):
|
|||
|
||||
def logoff(self):
|
||||
""" Logoff Manager"""
|
||||
self.action('logoff')
|
||||
response = self.action('logoff')
|
||||
if response[0] == 'Goodbye':
|
||||
self.fullybooted = False
|
||||
|
||||
def events(self, param):
|
||||
"""Control Event Flow
|
||||
|
|
|
@ -26,7 +26,7 @@ def reload_config(config):
|
|||
manager.connect()
|
||||
for module in reload_srv[config]:
|
||||
try:manager.reload(module)
|
||||
except ValueError: pass
|
||||
except asterisk.AsteriskError: pass
|
||||
manager.logoff()
|
||||
|
||||
if __name__ == '__main__' :
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue