iro/anbieter/sipgate.py
changeset 11 f25033cf93e0
parent 0 a3b6e531f0d2
child 20 0d7ffb9b2c7f
equal deleted inserted replaced
10:4a33882f3a49 11:f25033cf93e0
    57         pdf.close()
    57         pdf.close()
    58         self.__send(args,recipients)
    58         self.__send(args,recipients)
    59 
    59 
    60     def __connect(self):
    60     def __connect(self):
    61         """connect to sipgate XMLRPC Server"""
    61         """connect to sipgate XMLRPC Server"""
       
    62 
    62         self.samurai=xmlrpclib.Server(self.url%(self.user,self.password)).samurai
    63         self.samurai=xmlrpclib.Server(self.url%(self.user,self.password)).samurai
    63         args_identify = {
    64         args_identify = {
    64                 "ClientName"    : "anbieter.py",
    65                 "ClientName"    : "anbieter.py",
    65                 "ClientVersion" : "V1.0",
    66                 "ClientVersion" : "V1.0",
    66                 "ClientVendor"  : "Sandro Knauss"
    67                 "ClientVendor"  : "Sandro Knauss"
    68                 
    69                 
    69         self.__send_method(self.samurai.ClientIdentify, args_identify)
    70         self.__send_method(self.samurai.ClientIdentify, args_identify)
    70 
    71 
    71     def __send_method(self, func, args=None):
    72     def __send_method(self, func, args=None):
    72         """execute $func and test weather if the func  ran successfully or not"""
    73         """execute $func and test weather if the func  ran successfully or not"""
       
    74 
    73         if args==None:
    75         if args==None:
    74             xmlrpc_result = func()
    76             xmlrpc_result = func()
    75         else:
    77         else:
    76             xmlrpc_result = func(args)
    78             xmlrpc_result = func(args)
    77         if xmlrpc_result['StatusCode'] != 200:
    79         if xmlrpc_result['StatusCode'] != 200:
    78             raise NoValidStatusCode("There was an error during identification to the server! %d %s"% (xmlrpc_result['StatusCode'], xmlrpc_result['StatusString']))
    80             raise NoValidStatusCode("There was an error during identification to the server! %d %s"% (xmlrpc_result['StatusCode'], xmlrpc_result['StatusString']))
    79         
    81         
       
    82   
    80         return xmlrpc_result
    83         return xmlrpc_result
    81 
    84 
    82     def __send(self,args,recipients):
    85     def __send(self,args,recipients):
    83         """main sending method - sending the args to $recipients"""
    86         """main sending method - sending the args to $recipients"""
    84         sended=[]
    87         sended=[]
       
    88 
    85         self.__connect()
    89         self.__connect()
    86         for recipient in recipients:
    90         for recipient in recipients:
    87             try:
    91             try:
    88                 tel = telnumber(recipient)
    92                 tel = telnumber(recipient)
    89                 
    93                 
    90                 if tel in sended:                                                                           #only send message once per recipient
    94                 if tel in sended:                                                                           #only send message once per recipient
    91                   continue
    95                   continue
    92                 sended.append(tel)
    96                 sended.append(tel)
    93                 
    97 
    94                 args["RemoteUri"]="sip:%s%s@sipgate.net"%(tel.land,tel.number)
    98                 args["RemoteUri"]="sip:%s%s@sipgate.net"%(tel.land,tel.number)
    95                 xmlrpc_result = self.__send_method(self.samurai.SessionInitiate, args)
    99                 xmlrpc_result = self.__send_method(self.samurai.SessionInitiate, args)
    96                 self.updateStatus(arranged=recipient)
   100                 self.updateStatus(arranged=recipient)
    97             except NotATelNumber,NoValidStatusCode :
   101             except NotATelNumber,NoValidStatusCode :
    98                 self.updateStatus(failed=recipient)
   102                 self.updateStatus(failed=recipient)