def prepare_response(self, result, method=""): """ convert result to a valid xmlrpc or soap response """ if self.protocol == 'xmlrpclib': if not isinstance(result, SfaFault): result = (result,) response = xmlrpclib.dumps(result, methodresponse = True, encoding = self.encoding, allow_none = 1) elif self.protocol == 'soap': if isinstance(result, Exception): result = faultParameter(NS.ENV_T + ":Server", "Method Failed", method) result._setDetail("Fault %d: %s" % (result.faultCode, result.faultString)) else: response = buildSOAP(kw = {'%sResponse' % method: {'Result': result}}, encoding = self.encoding) else: if isinstance(result, Exception): raise result return response
def __call(self, name, args, kw, ns = None, sa = None, hd = None, ma = None): ns = ns or self.namespace ma = ma or self.methodattrs if sa: # Get soapaction if type(sa) == TupleType: sa = sa[0] else: if self.soapaction: sa = self.soapaction else: sa = name if hd: # Get header if type(hd) == TupleType: hd = hd[0] else: hd = self.header hd = hd or self.header if ma: # Get methodattrs if type(ma) == TupleType: ma = ma[0] else: ma = self.methodattrs ma = ma or self.methodattrs m = buildSOAP(args = args, kw = kw, method = name, namespace = ns, header = hd, methodattrs = ma, encoding = self.encoding, config = self.config, noroot = self.noroot) call_retry = 0 try: r, self.namespace = self.transport.call(self.proxy, m, ns, sa, key_file = self.key_file, cert_file = self.cert_file, encoding = self.encoding, http_proxy = self.http_proxy, config = self.config) except Exception, ex: # # Call failed. # # See if we have a fault handling vector installed in our # config. If we do, invoke it. If it returns a true value, # retry the call. # # In any circumstance other than the fault handler returning # true, reraise the exception. This keeps the semantics of this # code the same as without the faultHandler code. # if hasattr(self.config, "faultHandler"): if callable(self.config.faultHandler): call_retry = self.config.faultHandler(self.proxy, ex) if not call_retry: raise else: raise else: raise
# Handle expected faults if interface == xmlrpclib: result = fault methodresponse = None elif interface == SOAPpy: result = faultParameter(NS.ENV_T + ":Server", "Method Failed", method) result._setDetail("Fault %d: %s" % (fault.faultCode, fault.faultString)) # Return result if interface == xmlrpclib: if not isinstance(result, MDException): result = (result, ) data = xmlrpclib.dumps(result, methodresponse=True, encoding=self.encoding, allow_none=1) elif interface == SOAPpy: data = buildSOAP(kw={'%sResponse' % method: { 'Result': result }}, encoding=self.encoding) return data """ end of borrowed code """
method = r._name args = r._aslist() # XXX Support named arguments else: raise e try: result = self.call(source, method, *args) except MDException, fault: # Handle expected faults if interface == xmlrpclib: result = fault methodresponse = None elif interface == SOAPpy: result = faultParameter(NS.ENV_T + ":Server", "Method Failed", method) result._setDetail("Fault %d: %s" % (fault.faultCode, fault.faultString)) # Return result if interface == xmlrpclib: if not isinstance(result, MDException): result = (result,) data = xmlrpclib.dumps(result, methodresponse = True, encoding = self.encoding, allow_none = 1) elif interface == SOAPpy: data = buildSOAP(kw = {'%sResponse' % method: {'Result': result}}, encoding = self.encoding) return data """ end of borrowed code """