51 self.__send(args,recipients) |
54 self.__send(args,recipients) |
52 |
55 |
53 def sendFAX(self,fax,recipients): |
56 def sendFAX(self,fax,recipients): |
54 """send the PDF file $fax to $recipients""" |
57 """send the PDF file $fax to $recipients""" |
55 logger.debug('sipgate.sendFAX(%s,%s)'%(fax, str(recipients))) |
58 logger.debug('sipgate.sendFAX(%s,%s)'%(fax, str(recipients))) |
56 logger.debug(fax.getAttachment(0)); |
|
57 pdf=open(fax.getAttachment(0),"rb") |
|
58 args={ |
59 args={ |
59 "TOS" : "fax", |
60 "TOS" : "fax", |
60 "Content" : base64.encodestring(pdf.read()) |
61 "Content" : xmlrpclib.Binary(fax.getAttachment(0)), |
61 } |
62 } |
62 pdf.close() |
|
63 self.__send(args,recipients) |
63 self.__send(args,recipients) |
64 |
64 |
65 def __connect(self): |
65 def __connect(self): |
66 """connect to sipgate XMLRPC Server""" |
66 """connect to sipgate XMLRPC Server""" |
67 logger.debug("sipgate.__connect()-"+self.url%(self.user,"XXXXXXXX")) |
67 logger.debug("sipgate.__connect()-"+self.url%(self.user,"XXXXXXXX")) |
68 |
68 |
69 self.samurai=xmlrpclib.Server(self.url%(self.user,self.password)).samurai |
69 self.serv=xmlrpclib.ServerProxy(self.url%(self.user,self.password)) |
|
70 self.samurai=self.serv.samurai |
|
71 |
70 args_identify = { |
72 args_identify = { |
71 "ClientName" : "anbieter.py", |
73 "ClientName" : "anbieter.py", |
72 "ClientVersion" : "V1.0", |
74 "ClientVersion" : "V1.0", |
73 "ClientVendor" : "Sandro Knauss" |
75 "ClientVendor" : "Sandro Knauss" |
74 } |
76 } |
75 |
|
76 self.__send_method(self.samurai.ClientIdentify, args_identify) |
77 self.__send_method(self.samurai.ClientIdentify, args_identify) |
|
78 return self.serv |
77 |
79 |
78 def __send_method(self, func, args=None): |
80 def __send_method(self, func, args=None): |
79 """execute $func and test weather if the func ran successfully or not""" |
81 """execute $func and test weather if the func ran successfully or not""" |
|
82 logger.debug("sipgate.__send_method(func,%s)"%( args)) |
80 |
83 |
81 if args==None: |
84 if args==None: |
82 xmlrpc_result = func() |
85 xmlrpc_result = func() |
83 else: |
86 else: |
84 xmlrpc_result = func(args) |
87 xmlrpc_result = func(args) |
85 if xmlrpc_result['StatusCode'] != 200: |
88 if xmlrpc_result['StatusCode'] != 200: |
86 raise NoValidStatusCode("There was an error during identification to the server! %d %s"% (xmlrpc_result['StatusCode'], xmlrpc_result['StatusString'])) |
89 raise NoValidStatusCode("There was an error during identification to the server! %d %s"% (xmlrpc_result['StatusCode'], xmlrpc_result['StatusString'])) |
87 |
90 logger.debug("sipgate.__send_method(..):ok"); |
88 |
|
89 return xmlrpc_result |
91 return xmlrpc_result |
90 |
92 |
91 def __send(self,args,recipients): |
93 def __send(self,args,recipients): |
92 """main sending method - sending the args to $recipients""" |
94 """main sending method - sending the args to $recipients""" |
93 sended=[] |
95 sended=[] |
94 |
96 |
95 self.__connect() |
97 serv=self.__connect() |
96 logger.debug('sipgate.__send(%s,%s)'%(str(args), str(recipients))) |
98 logger.debug('sipgate.__send(%s,%s)'%(args, recipients)) |
97 for recipient in recipients: |
99 for recipient in recipients: |
98 try: |
100 try: |
99 tel = telnumber(recipient) |
101 tel = telnumber(recipient) |
100 |
102 |
101 if tel in sended: #only send message once per recipient |
103 if tel in sended: #only send message once per recipient |
102 continue |
104 continue |
103 sended.append(tel) |
105 sended.append(tel) |
104 |
106 |
105 args["RemoteUri"]="sip:%s%s@sipgate.net"%(tel.land,tel.number) |
107 args["RemoteUri"]="sip:%s%s@sipgate.net"%(tel.land,tel.number) |
106 self.__send_method(self.samurai.SessionInitiate, args) |
108 self.__send_method(serv.samurai.SessionInitiate, args) |
107 self.updateStatus(arranged=recipient) |
109 self.updateStatus(arranged=recipient) |
108 |
110 |
109 except NotATelNumber, NoValidStatusCode: |
111 except (NotATelNumber, NoValidStatusCode): |
110 self.updateStatus(failed=recipient) |
112 self.updateStatus(failed=recipient) |
111 |
113 |
112 self.__disconnect() |
114 self.__disconnect() |
113 |
115 |
114 def updateStatus(self, arranged=None, failed=None): |
116 def updateStatus(self, arranged=None, failed=None): |