Modify dispacher for differente response element name
This commit is contained in:
@@ -8,7 +8,7 @@ __author__ = "Mariano Reingart"
|
||||
__author_email__ = "reingart@gmail.com"
|
||||
__copyright__ = "Copyright (C) 2013 Mariano Reingart"
|
||||
__license__ = "LGPL 3.0"
|
||||
__version__ = "1.16"
|
||||
__version__ = "1.16.2"
|
||||
|
||||
TIMEOUT = 60
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ class SoapClient(object):
|
||||
}
|
||||
|
||||
if self.action is not None:
|
||||
headers['SOAPAction'] = soap_action
|
||||
headers['SOAPAction'] = '"' + soap_action + '"'
|
||||
|
||||
headers.update(self.http_headers)
|
||||
log.info("POST %s" % location)
|
||||
|
||||
@@ -119,11 +119,11 @@ class SoapDispatcher(object):
|
||||
xml = xml.replace('/>', ' ' + _ns_str + '/>')
|
||||
return xml
|
||||
|
||||
def register_function(self, name, fn, returns=None, args=None, doc=None):
|
||||
self.methods[name] = fn, returns, args, doc or getattr(fn, "__doc__", "")
|
||||
def register_function(self, name, fn, returns=None, args=None, doc=None, response_element_name=None):
|
||||
self.methods[name] = fn, returns, args, doc or getattr(fn, "__doc__", ""), response_element_name or '%sResponse' % name
|
||||
|
||||
def response_element_name(self, method):
|
||||
return '%sResponse' % method
|
||||
return self.methods[method][4]
|
||||
|
||||
def dispatch(self, xml, action=None, fault=None):
|
||||
"""Receive and process SOAP call, returns the xml"""
|
||||
@@ -179,7 +179,7 @@ class SoapDispatcher(object):
|
||||
prefix = method.get_prefix()
|
||||
|
||||
log.debug('dispatch method: %s', name)
|
||||
function, returns_types, args_types, doc = self.methods[name]
|
||||
function, returns_types, args_types, doc, response_element_name = self.methods[name]
|
||||
log.debug('returns_types %s', returns_types)
|
||||
|
||||
# de-serialize parameters (if type definitions given)
|
||||
@@ -286,11 +286,11 @@ class SoapDispatcher(object):
|
||||
|
||||
def list_methods(self):
|
||||
"""Return a list of aregistered operations"""
|
||||
return [(method, doc) for method, (function, returns, args, doc) in self.methods.items()]
|
||||
return [(method, doc) for method, (function, returns, args, doc, response_element_name) in self.methods.items()]
|
||||
|
||||
def help(self, method=None):
|
||||
"""Generate sample request and response messages"""
|
||||
(function, returns, args, doc) = self.methods[method]
|
||||
(function, returns, args, doc, response_element_name) = self.methods[method]
|
||||
xml = """
|
||||
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<soap:Body><%(method)s xmlns="%(namespace)s"/></soap:Body>
|
||||
@@ -307,8 +307,8 @@ class SoapDispatcher(object):
|
||||
|
||||
xml = """
|
||||
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<soap:Body><%(method)sResponse xmlns="%(namespace)s"/></soap:Body>
|
||||
</soap:Envelope>""" % {'method': method, 'namespace': self.namespace}
|
||||
<soap:Body><%(response_element_name)s xmlns="%(namespace)s"/></soap:Body>
|
||||
</soap:Envelope>""" % {'response_element_name': response_element_name, 'namespace': self.namespace}
|
||||
response = SimpleXMLElement(xml, namespace=self.namespace, prefix=self.prefix)
|
||||
if returns:
|
||||
items = returns.items()
|
||||
@@ -317,7 +317,7 @@ class SoapDispatcher(object):
|
||||
else:
|
||||
items = []
|
||||
for k, v in items:
|
||||
response('%sResponse' % method).marshall(k, v, add_comments=True, ns=False)
|
||||
response(response_element_name).marshall(k, v, add_comments=True, ns=False)
|
||||
|
||||
return request.as_xml(pretty=True), response.as_xml(pretty=True), doc
|
||||
|
||||
@@ -343,7 +343,7 @@ class SoapDispatcher(object):
|
||||
""" % {'namespace': self.namespace, 'name': self.name, 'documentation': self.documentation}
|
||||
wsdl = SimpleXMLElement(xml)
|
||||
|
||||
for method, (function, returns, args, doc) in self.methods.items():
|
||||
for method, (function, returns, args, doc, response_element_name) in self.methods.items():
|
||||
# create elements:
|
||||
|
||||
def parse_element(name, values, array=False, complex=False):
|
||||
@@ -389,20 +389,20 @@ class SoapDispatcher(object):
|
||||
e.add_attribute('type', t)
|
||||
|
||||
parse_element("%s" % method, args and args.items())
|
||||
parse_element("%sResponse" % method, returns and returns.items())
|
||||
parse_element(response_element_name, returns and returns.items())
|
||||
|
||||
# create messages:
|
||||
for m, e in ('Input', ''), ('Output', 'Response'):
|
||||
for m, e in ('Input', method), ('Output', response_element_name):
|
||||
message = wsdl.add_child('wsdl:message')
|
||||
message['name'] = "%s%s" % (method, m)
|
||||
part = message.add_child("wsdl:part")
|
||||
part[:] = {'name': 'parameters',
|
||||
'element': 'tns:%s%s' % (method, e)}
|
||||
'element': 'tns:%s' % e}
|
||||
|
||||
# create ports
|
||||
portType = wsdl.add_child('wsdl:portType')
|
||||
portType['name'] = "%sPortType" % self.name
|
||||
for method, (function, returns, args, doc) in self.methods.items():
|
||||
for method, (function, returns, args, doc, response_element_name) in self.methods.items():
|
||||
op = portType.add_child('wsdl:operation')
|
||||
op['name'] = method
|
||||
if doc:
|
||||
|
||||
+4
-4
@@ -5070,7 +5070,7 @@ class Service(object):
|
||||
return f
|
||||
return _amfrpc3
|
||||
|
||||
def soap(self, name=None, returns=None, args=None, doc=None):
|
||||
def soap(self, name=None, returns=None, args=None, doc=None, response_element_name=None):
|
||||
"""
|
||||
Example:
|
||||
Use as::
|
||||
@@ -5094,7 +5094,7 @@ class Service(object):
|
||||
"""
|
||||
|
||||
def _soap(f):
|
||||
self.soap_procedures[name or f.__name__] = f, returns, args, doc
|
||||
self.soap_procedures[name or f.__name__] = f, returns, args, doc, response_element_name
|
||||
return f
|
||||
return _soap
|
||||
|
||||
@@ -5400,8 +5400,8 @@ class Service(object):
|
||||
prefix='pys',
|
||||
documentation=documentation,
|
||||
ns=True)
|
||||
for method, (function, returns, args, doc) in iteritems(procedures):
|
||||
dispatcher.register_function(method, function, returns, args, doc)
|
||||
for method, (function, returns, args, doc, resp_elem_name) in iteritems(procedures):
|
||||
dispatcher.register_function(method, function, returns, args, doc, resp_elem_name)
|
||||
if request.env.request_method == 'POST':
|
||||
fault = {}
|
||||
# Process normal Soap Operation
|
||||
|
||||
Reference in New Issue
Block a user