summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjortel <devnull@localhost>2010-08-31 15:25:01 +0000
committerjortel <devnull@localhost>2010-08-31 15:25:01 +0000
commitada7dd09c10865a67049a85ccd688167aefad3c2 (patch)
tree500baa56325a3becaea3e49b3818d85c2c86ed60
parent2ee83e241c78db8b1a25d5182873470137394ad1 (diff)
downloadsuds-ada7dd09c10865a67049a85ccd688167aefad3c2.tar.gz
Add option: 'prettyxml' default=0 to control output XML as pretty printed or not.
-rw-r--r--suds/__init__.py2
-rw-r--r--suds/client.py23
-rw-r--r--suds/options.py5
-rw-r--r--suds/sax/document.py24
-rw-r--r--suds/sax/element.py23
5 files changed, 60 insertions, 17 deletions
diff --git a/suds/__init__.py b/suds/__init__.py
index 896c91d..c6a35e6 100644
--- a/suds/__init__.py
+++ b/suds/__init__.py
@@ -27,7 +27,7 @@ import sys
#
__version__ = '0.4'
-__build__="(beta) R690-20100824"
+__build__="(beta) R692-20100831"
#
# Exceptions
diff --git a/suds/client.py b/suds/client.py
index d56cb99..5a74097 100644
--- a/suds/client.py
+++ b/suds/client.py
@@ -592,14 +592,14 @@ class SoapClient:
timer.start()
result = None
binding = self.method.binding.input
- msg = binding.get_message(self.method, args, kwargs)
+ soapenv = binding.get_message(self.method, args, kwargs)
timer.stop()
metrics.log.debug(
"message for '%s' created: %s",
self.method.name,
timer)
timer.start()
- result = self.send(msg)
+ result = self.send(soapenv)
timer.stop()
metrics.log.debug(
"method '%s' invoked: %s",
@@ -607,11 +607,11 @@ class SoapClient:
timer)
return result
- def send(self, msg):
+ def send(self, soapenv):
"""
Send soap message.
- @param msg: A soap message to send.
- @type msg: basestring
+ @param soapenv: A soap envelope to send.
+ @type soapenv: L{Document}
@return: The reply to the sent message.
@rtype: I{builtin} or I{subclass of} L{Object}
"""
@@ -620,12 +620,17 @@ class SoapClient:
binding = self.method.binding.input
transport = self.options.transport
retxml = self.options.retxml
- log.debug('sending to (%s)\nmessage:\n%s', location, msg)
+ prettyxml = self.options.prettyxml
+ log.debug('sending to (%s)\nmessage:\n%s', location, soapenv)
try:
- self.last_sent(Document(msg))
+ self.last_sent(soapenv)
plugins = PluginContainer(self.options.plugins)
- plugins.message.marshalled(envelope=msg.root())
- soapenv = str(msg)
+ plugins.message.marshalled(envelope=soapenv.root())
+ if prettyxml:
+ soapenv = soapenv.str()
+ else:
+ soapenv = soapenv.plain()
+ soapenv = soapenv.encode('utf-8')
plugins.message.sending(envelope=soapenv)
request = Request(location, soapenv)
request.headers = self.headers()
diff --git a/suds/options.py b/suds/options.py
index b4876d3..86ea245 100644
--- a/suds/options.py
+++ b/suds/options.py
@@ -84,6 +84,10 @@ class Options(Skin):
of the python object graph.
- type: I{bool}
- default: False
+ - B{prettyxml} - Flag that causes I{pretty} xml to be rendered when generating
+ the outbound soap envelope.
+ - type: I{bool}
+ - default: False
- B{autoblend} - Flag that ensures that the schema(s) defined within the
WSDL import each other.
- type: I{bool}
@@ -111,6 +115,7 @@ class Options(Skin):
Definition('xstq', bool, True),
Definition('prefixes', bool, True),
Definition('retxml', bool, False),
+ Definition('prettyxml', bool, False),
Definition('autoblend', bool, False),
Definition('cachingpolicy', int, 0),
Definition('plugins', (list, tuple), []),
diff --git a/suds/sax/document.py b/suds/sax/document.py
index c7129cb..5a004eb 100644
--- a/suds/sax/document.py
+++ b/suds/sax/document.py
@@ -27,6 +27,8 @@ log = getLogger(__name__)
class Document(Element):
""" simple document """
+
+ DECL = '<?xml version="1.0" encoding="UTF-8"?>'
def __init__(self, root=None):
Element.__init__(self, 'document')
@@ -34,18 +36,26 @@ class Document(Element):
self.append(root)
def root(self):
- if len(self.children) > 0:
+ if len(self.children):
return self.children[0]
else:
return None
+ def str(self):
+ s = []
+ s.append(self.DECL)
+ s.append('\n')
+ s.append(self.root().str())
+ return ''.join(s)
+
+ def plain(self):
+ s = []
+ s.append(self.DECL)
+ s.append(self.root().plain())
+ return ''.join(s)
+
def __str__(self):
return unicode(self).encode('utf-8')
def __unicode__(self):
- result = '<?xml version="1.0" encoding="UTF-8"?>'
- root = self.root()
- if root is not None:
- result += '\n'
- result += root.str()
- return unicode(result)
+ return self.str() \ No newline at end of file
diff --git a/suds/sax/element.py b/suds/sax/element.py
index 0a015f1..9dec1f9 100644
--- a/suds/sax/element.py
+++ b/suds/sax/element.py
@@ -767,6 +767,29 @@ class Element:
result.append('</%s>' % self.qname())
result = ''.join(result)
return result
+
+ def plain(self):
+ """
+ Get a string representation of this XML fragment.
+ @return: A I{plain} string.
+ @rtype: basestring
+ """
+ result = []
+ result.append('<%s' % self.qname())
+ result.append(self.nsdeclarations())
+ for a in [unicode(a) for a in self.attributes]:
+ result.append(' %s' % a)
+ if self.isempty():
+ result.append('/>')
+ return ''.join(result)
+ result.append('>')
+ if self.hasText():
+ result.append(self.text.escape())
+ for c in self.children:
+ result.append(c.plain())
+ result.append('</%s>' % self.qname())
+ result = ''.join(result)
+ return result
def nsdeclarations(self):
"""