summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjortel <devnull@localhost>2010-10-15 13:29:37 +0000
committerjortel <devnull@localhost>2010-10-15 13:29:37 +0000
commitc42b63b29ca6e9f1d90d92eef3cc138d7b68369a (patch)
tree9a1f578663077765e8bdd2b5b178b50a5faae391
parentdac3ac9229a921b945e4d4a58fe0e7af8095e2a7 (diff)
downloadsuds-c42b63b29ca6e9f1d90d92eef3cc138d7b68369a.tar.gz
Add 'nosend' option that causes the SoapClient to return a RequestContext instead of sending the soap envelope. It is intended that the caller use another transport such as Twisted to send the envelope. The RequestContext provides re-entry points to process the reply (succeeded() & failed()). Also, fix ticket #361 by UTF-8 encoding the soap action that is added to the http headers.
-rw-r--r--suds/__init__.py4
-rw-r--r--suds/client.py27
-rw-r--r--suds/options.py6
-rw-r--r--tests/axis1.py14
4 files changed, 48 insertions, 3 deletions
diff --git a/suds/__init__.py b/suds/__init__.py
index 166a206..84c6e1d 100644
--- a/suds/__init__.py
+++ b/suds/__init__.py
@@ -26,8 +26,8 @@ import sys
# Project properties
#
-__version__ = '0.4'
-__build__="GA R699-20100913"
+__version__ = '0.4.1'
+__build__="GA R699-20101015"
#
# Exceptions
diff --git a/suds/client.py b/suds/client.py
index 5a74097..e242e44 100644
--- a/suds/client.py
+++ b/suds/client.py
@@ -620,6 +620,7 @@ class SoapClient:
binding = self.method.binding.input
transport = self.options.transport
retxml = self.options.retxml
+ nosend = self.options.nosend
prettyxml = self.options.prettyxml
log.debug('sending to (%s)\nmessage:\n%s', location, soapenv)
try:
@@ -631,7 +632,10 @@ class SoapClient:
else:
soapenv = soapenv.plain()
soapenv = soapenv.encode('utf-8')
- plugins.message.sending(envelope=soapenv)
+ ctx = plugins.message.sending(envelope=soapenv)
+ soapenv = ctx.envelope
+ if nosend:
+ return RequestContext(self, binding, soapenv)
request = Request(location, soapenv)
request.headers = self.headers()
reply = transport.send(request)
@@ -656,6 +660,8 @@ class SoapClient:
@rtype: dict
"""
action = self.method.soap.action
+ if isinstance(action, unicode):
+ action = action.encode('utf-8')
stock = { 'Content-Type' : 'text/xml; charset=utf-8', 'SOAPAction': action }
result = dict(stock, **self.options.headers)
log.debug('headers = %s', result)
@@ -783,3 +789,22 @@ class SimClient(SoapClient):
return (500, p)
else:
return (500, None)
+
+
+class RequestContext:
+
+ def __init__(self, client, binding, sent):
+ self.client = client
+ self.binding = binding
+ self.sent = sent
+
+ def succeeded(self, reply):
+ options = self.client.options
+ plugins = PluginContainer(options.plugins)
+ ctx = plugins.message.received(reply=reply)
+ reply = ctx.reply
+ return self.client.succeeded(self.binding, reply)
+
+ def failed(self, error):
+ return self.client.failed(self.binding, error)
+ \ No newline at end of file
diff --git a/suds/options.py b/suds/options.py
index 86ea245..dabd770 100644
--- a/suds/options.py
+++ b/suds/options.py
@@ -99,6 +99,11 @@ class Options(Skin):
- default: 0
- B{plugins} - A plugin container.
- type: I{list}
+ - B{nosend} - Create the soap envelope but don't send.
+ When specified, method invocation returns a I{RequestContext}
+ instead of sending it.
+ - type: I{bool}
+ - default: False
"""
def __init__(self, **kwargs):
domain = __name__
@@ -119,5 +124,6 @@ class Options(Skin):
Definition('autoblend', bool, False),
Definition('cachingpolicy', int, 0),
Definition('plugins', (list, tuple), []),
+ Definition('nosend', bool, False),
]
Skin.__init__(self, domain, definitions, kwargs)
diff --git a/tests/axis1.py b/tests/axis1.py
index e221fae..5c72867 100644
--- a/tests/axis1.py
+++ b/tests/axis1.py
@@ -137,6 +137,20 @@ try:
print 'addPersion()'
result = client.service.addPerson(person)
print '\nreply(\n%s\n)\n' % str(result)
+
+ #
+ # Async
+ #
+ client.options.nosend=True
+ reply = '<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:addPersonResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://basic.suds.fedora.org"><addPersonReturn xsi:type="xsd:string">person (jeff&#x4D2;,ortel) at age 43 with phone numbers (410-555-5138,919-555-4406,205-777-1212, and pets (Chance,) - added.</addPersonReturn></ns1:addPersonResponse></soapenv:Body></soapenv:Envelope>'
+ request = client.service.addPerson(person)
+ result = request.succeeded(reply)
+ error = Object()
+ error.httpcode = '500'
+ client.options.nosend=False
+# request.failed(error)
+
+ #
#
# create a new name object used to update the person
#