def render(self, request): """Handle a SOAP command.""" data = request.content.read() p, header, body, attrs = SOAPpy.parseSOAPRPC(data, 1, 1, 1) methodName, args, kwargs, ns = p._name, p._aslist, p._asdict, p._ns # deal with changes in SOAPpy 0.11 if callable(args): args = args() if callable(kwargs): kwargs = kwargs() function = self.lookupFunction(methodName) if not function: self._methodNotFound(request, methodName) return server.NOT_DONE_YET else: if hasattr(function, "useKeywords"): keywords = {} for k, v in kwargs.items(): keywords[str(k)] = v d = defer.maybeDeferred(function, **keywords) else: d = defer.maybeDeferred(function, *args) d.addCallback(self._gotResult, request, methodName) d.addErrback(self._gotError, request, methodName) return server.NOT_DONE_YET
def _cbGotResult(self, result): result = SOAPpy.parseSOAPRPC(result) if hasattr(result, 'Result'): return result.Result elif len(result) == 1: return result[0] else: return result
def _cbGotResult(self, result): result = SOAPpy.parseSOAPRPC(result) if hasattr(result, 'Result'): return result.Result elif len(result) == 1: ## SOAPpy 0.11.6 wraps the return results in a containing structure. ## This check added to make Proxy behaviour emulate SOAPProxy, which ## flattens the structure by default. ## This behaviour is OK because even singleton lists are wrapped in ## another singleton structType, which is almost always useless. return result[0] else: return result
def _got_page(self, result): """ The http POST command was successful, we parse the SOAP answer, and return it. @param result: the xml content """ parsed = SOAPpy.parseSOAPRPC(result) logging.debug("SOAP Answer:\n%s", result) logging.debug("SOAP Parsed Answer: %r", parsed) return parsed
def _got_error(self, res): """ The HTTP POST command did not succeed, depending on the error type: - it's a SOAP error, we parse it and return a L{SoapError}. - it's another type of error (http, other), we raise it as is """ logging.debug("SOAP Error:\n%s", res) if isinstance(res.value, error.Error): try: logging.debug("SOAP Error content:\n%s", res.value.response) raise SoapError(SOAPpy.parseSOAPRPC(res.value.response)["detail"]) except: raise raise Exception(res.value)
def render(self, request): # the upload request is multipart/form-data with file and SOAP: # handle separately if request.postpath == ["upload"]: headers = request.requestHeaders content_type = headers.getRawHeaders("content-type")[0] typ, pdict = cgi.parse_header(content_type) #if typ == "multipart/x-url-encoded" form = cgi.parse_multipart(request.content, pdict) data = form['SOAPENVELOPE'][0] else: form = None data = request.content.read() p, header, body, attrs = SOAPpy.parseSOAPRPC(data, 1, 1, 1) methodName, args, kwargs, ns = p._name, p._aslist, p._asdict, p._ns if callable(args): args = args() if callable(kwargs): kwargs = kwargs() if form: kwargs["form"] = form args.insert(0, form) function = self.lookupFunction(methodName) if not function: self._methodNotFound(request, methodName) return server.NOT_DONE_YET else: if hasattr(function, "useKeywords"): keywords = {} for k, v in kwargs.items(): keywords[str(k)] = v d = defer.maybeDeferred(function, **keywords) else: d = defer.maybeDeferred(function, *args) d.addCallback(self._gotResult, request, methodName) d.addErrback(self._gotError, request, methodName) return server.NOT_DONE_YET
def _cbGotResult(self, result): return SOAPpy.simplify(SOAPpy.parseSOAPRPC(result))