From 155ed3f8e0cb4b927274a5eb9c3f7362d9debded Mon Sep 17 00:00:00 2001 From: jortel Date: Mon, 11 Jul 2011 21:05:27 +0000 Subject: Handle str() and plain() when document root is (None). --- suds/sax/document.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/suds/sax/document.py b/suds/sax/document.py index 5a004eb..b5ba22f 100644 --- a/suds/sax/document.py +++ b/suds/sax/document.py @@ -34,24 +34,43 @@ class Document(Element): Element.__init__(self, 'document') if root is not None: self.append(root) - + def root(self): + """ + Get the document root element (can be None) + @return: The document root. + @rtype: L{Element} + """ if len(self.children): return self.children[0] else: return None def str(self): + """ + Get a string representation of this XML fragment. + @return: A I{pretty} string. + @rtype: basestring + """ s = [] s.append(self.DECL) - s.append('\n') - s.append(self.root().str()) + root = self.root() + if root is not None: + s.append('\n') + s.append(root.str()) return ''.join(s) def plain(self): + """ + Get a string representation of this XML fragment. + @return: A I{plain} string. + @rtype: basestring + """ s = [] s.append(self.DECL) - s.append(self.root().plain()) + root = self.root() + if root is not None: + s.append(self.root().plain()) return ''.join(s) def __str__(self): -- cgit v1.2.1