diff options
author | jortel <devnull@localhost> | 2010-01-29 23:50:51 +0000 |
---|---|---|
committer | jortel <devnull@localhost> | 2010-01-29 23:50:51 +0000 |
commit | 72e12d715efa163af7c5431f9ec731434994b98d (patch) | |
tree | 500dbeb0dcbf45ad2c42dc0bea7a2ce2f2fc7d9e | |
parent | b9edddbbf3a35579cd7fbf6c230abaff52d00124 (diff) | |
download | suds-72e12d715efa163af7c5431f9ec731434994b98d.tar.gz |
In the ElementAppender (marshaller), wrap appended Elements to make them kind of read-only and appended As-Is. This mainly prevents Element parameters from being tampered with by promotePrefixes() and normalizePrefixes() during XML message optimizations. Also, fix potential issue with normalizePrefixes() by adding (self) to branch() and looking up the ancestor list for all possible namespaces. Added Element.ancestors() method.
-rw-r--r-- | suds/mx/appender.py | 19 | ||||
-rw-r--r-- | suds/sax/element.py | 18 |
2 files changed, 31 insertions, 6 deletions
diff --git a/suds/mx/appender.py b/suds/mx/appender.py index baf7795..0501415 100644 --- a/suds/mx/appender.py +++ b/suds/mx/appender.py @@ -257,6 +257,19 @@ class DictAppender(Appender): for item in d.items(): cont = Content(tag=item[0], value=item[1]) Appender.append(self, child, cont) + + +class ElementWrapper(Element): + """ + Element wrapper. + """ + + def __init__(self, content): + Element.__init__(self, content.name, content.parent) + self.__content = content + + def str(self, indent=0): + return self.__content.str(indent) class ElementAppender(Appender): @@ -267,8 +280,8 @@ class ElementAppender(Appender): def append(self, parent, content): if content.tag.startswith('_'): raise Exception('raw XML not valid as attribute value') - child = deepcopy(content.value) - parent.append(child.detach()) + child = ElementWrapper(content.value) + parent.append(child) class ListAppender(Appender): @@ -294,4 +307,4 @@ class TextAppender(Appender): def append(self, parent, content): child = self.node(content) child.setText(content.value) - parent.append(child)
\ No newline at end of file + parent.append(child) diff --git a/suds/sax/element.py b/suds/sax/element.py index 2654bb6..ca44801 100644 --- a/suds/sax/element.py +++ b/suds/sax/element.py @@ -820,12 +820,24 @@ class Element: @return: A flat list of nodes. @rtype: [L{Element},..] """ - branch = [] + branch = [self] for c in self.children: - branch.append(c) branch += c.branch() return branch + def ancestors(self): + """ + Get a list of ancestors. + @return: A list of ancestors. + @rtype: [L{Element},..] + """ + ancestors = [] + p = self.parent + while p is not None: + ancestors.append(p) + p = p.parent + return ancestors + def walk(self, visitor): """ Walk the branch and call the visitor function @@ -955,7 +967,7 @@ class PrefixNormalizer: @rtype: set """ s = set() - for n in self.branch: + for n in self.branch + self.node.ancestors(): if self.permit(n.expns): s.add(n.expns) s = s.union(self.pset(n)) |