elementsoap with Python 2.5

S

Steven Bethard

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</b> attribute.
#
# @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</b> attribute.
#
# @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
 
F

Fredrik Lundh

Steven said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,733
Latest member
LonaMonzon

Latest Threads

Top