By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,035 Members | 1,984 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,035 IT Pros & Developers. It's quick & easy.

elementsoap with Python 2.5

P: n/a
I was trying to get elementsoap_ working with just xml.etree from Python
2.5 (and no standalone elementtree installation). I think I got
everything working by changing the imports and copying in the
FancyTreeBuilder class (since only TreeBuilder and XMLTreeBuilder are in
the xml.etree.ElementTree module). I've attached the diff. Does this
seem like the right approach? I'd rather not have to install
elementtree alongside the one in the stdlib...

... _elementsoap: http://effbot.org/downloads/#elementsoap

STeVe

Only in elementsoap-0.3-20031123-stdlib\elementsoap: __init__.pyc
Only in elementsoap-0.3-20031123-stdlib\elementsoap: ElementGoogle.pyc
diff elementsoap-0.3-20031123\elementsoap/ElementSOAP.py elementsoap-0.3-20031123-stdlib\elementsoap/ElementSOAP.py
23,25c23,25
< from elementtree import ElementTree
< from elementtree import XMLTreeBuilder
< from elementtree.ElementTree import Element, QName, SubElement, tostring
---
from xml.etree import ElementTree
from xml.etree.ElementTree import XMLTreeBuilder
from xml.etree.ElementTree import Element, QName, SubElement, tostring
260a261,310
# (experimental) An alternate builder that supports manipulation of
# new elements.

class FancyTreeBuilder(XMLTreeBuilder):

def __init__(self, html=0):
XMLTreeBuilder.__init__(self, html)
self._parser.StartNamespaceDeclHandler = self._start_ns
self._parser.EndNamespaceDeclHandler = self._end_ns
self.namespaces = []

def _start(self, tag, attrib_in):
elem = XMLTreeBuilder._start(self, tag, attrib_in)
self.start(elem)

def _start_list(self, tag, attrib_in):
elem = XMLTreeBuilder._start_list(self, tag, attrib_in)
self.start(elem)

def _end(self, tag):
elem = XMLTreeBuilder._end(self, tag)
self.end(elem)

def _start_ns(self, prefix, value):
self.namespaces.insert(0, (prefix, value))

def _end_ns(self, prefix):
assert self.namespaces.pop(0)[0] == prefix, "implementation confused"

##
# Hook method that's called when a new element has been opened.
# May access the <b>namespaces</battribute.
#
# @param element The new element. The tag name and attributes are,
# set, but it has no children, and the text and tail attributes
# are still empty.

def start(self, element):
pass

##
# Hook method that's called when a new element has been closed.
# May access the <b>namespaces</battribute.
#
# @param element The new element.

def end(self, element):
pass

##
264c314
< class NamespaceParser(XMLTreeBuilder.FancyTreeBuilder):
---
class NamespaceParser(FancyTreeBuilder):
Only in elementsoap-0.3-20031123-stdlib\elementsoap: ElementSOAP.pyc
diff elementsoap-0.3-20031123\elementsoap/HTTPClient.py elementsoap-0.3-20031123-stdlib\elementsoap/HTTPClient.py
57c57
< from elementtree import ElementTree
---
from xml.etree import ElementTree
Only in elementsoap-0.3-20031123-stdlib\elementsoap: HTTPClient.pyc

Oct 11 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Steven Bethard wrote:
I was trying to get elementsoap_ working with just xml.etree from Python
2.5 (and no standalone elementtree installation). I think I got
everything working by changing the imports and copying in the
FancyTreeBuilder class (since only TreeBuilder and XMLTreeBuilder are in
the xml.etree.ElementTree module). I've attached the diff. Does this
seem like the right approach?
the really correct approach would be to rewrite the code to use the
"iterparse" API instead.

FancyTreeBuilder relies on various internals, but your copy-and-paste
fix should work just fine for Python 2.5 and/or ElementTree 1.2.

</F>

Oct 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.