def soapcomm(self, cmd, **kwargs): """ takes a command name and a list of keyword arguments. each keyword is converted into a xml element """ if not isinstance(cmd, str) or not len(cmd): raise IsyValueError("SOAP Method name missing") if self.debug & 0x02: print "sendcomm : ", cmd soap_cmd = self._gensoap(cmd, **kwargs) xurl = self.baseurl + "/services" if self.debug & 0x02: print "xurl = ", xurl print "soap_cmd = ", soap_cmd req = URL.Request(xurl, soap_cmd, {'Content-Type': 'application/xml; charset="utf-8"'}) data = "" try: res = self._opener.open(req, None) data = res.read() if self.debug & 0x200: print("res.getcode() ", res.getcode(), len(data)) print("data ", data) res.close() except URL.HTTPError, e: self.error_str = str("Reponse Code : {0} : {1} {2}").format( e.code, xurl, cmd) if ((cmd == "DiscoverNodes" and e.code == 803) or (cmd == "CancelNodesDiscovery" and e.code == 501) # or ( cmd == "RemoveNode" and e.code == 501 ) ): if self.debug & 0x02: print "spacial case : {0} : {1}".format(cmd, e.code) print "e.code = ", e.code print "e.msg = ", e.msg print "e.hdrs = ", e.hdrs print "e.filename = ", e.filename print "e.code = ", type(e.code), e.code print "\n" return e.read() if self.debug & 0x202: print "e.code = ", type(e.code), e.code # print "e.read = ", e.read() print "e = ", e print "data = ", data mess = "{!s} : {!s} : {!s}".format(cmd, kwargs, e.code) # This a messy and should change raise IsySoapError(mess, httperr=e)
def _sendfile(self, filename="", data="", load="n"): if ( filename.startswith('/') ) : xurl = self.baseurl + "/file/upload" + filename + "?load=" + load else : xurl = self.baseurl + "/file/upload/" + filename + "?load=" + load if self.debug & 0x02: print("{0} xurl : {1}".format(__name__, xurl)) req = URL.Request(xurl, data, {'Content-Type': 'application/xml; charset="utf-8"'}) try : res = self._opener.open(req, None) responce = res.read() # print("res.getcode() ", res.getcode(), len(responce)) res.close() except URL.HTTPError, e: # print "e.read : ", e.read() mess = "{!s} : {!s} : {!s}".format("/file/upload", filename, e.code) raise IsySoapError(mess, httperr=e)