elementsoap with Python 2.5

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Bethard

    #1

    elementsoap with Python 2.5

    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
    FancyTreeBuilde r class (since only TreeBuilder and XMLTreeBuilder are in
    the xml.etree.Eleme ntTree 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\elements oap: __init__.pyc
    Only in elementsoap-0.3-20031123-stdlib\elements oap: ElementGoogle.p yc
    diff elementsoap-0.3-20031123\elemen tsoap/ElementSOAP.py elementsoap-0.3-20031123-stdlib\elements oap/ElementSOAP.py
    23,25c23,25
    < from elementtree import ElementTree
    < from elementtree import XMLTreeBuilder
    < from elementtree.Ele mentTree import Element, QName, SubElement, tostring
    ---
    from xml.etree import ElementTree
    from xml.etree.Eleme ntTree import XMLTreeBuilder
    from xml.etree.Eleme ntTree import Element, QName, SubElement, tostring
    260a261,310
    # (experimental) An alternate builder that supports manipulation of
    # new elements.
    >
    class FancyTreeBuilde r(XMLTreeBuilde r):
    >
    def __init__(self, html=0):
    XMLTreeBuilder. __init__(self, html)
    self._parser.St artNamespaceDec lHandler = self._start_ns
    self._parser.En dNamespaceDeclH andler = self._end_ns
    self.namespaces = []
    >
    def _start(self, tag, attrib_in):
    elem = XMLTreeBuilder. _start(self, tag, attrib_in)
    self.start(elem )
    >
    def _start_list(sel f, tag, attrib_in):
    elem = XMLTreeBuilder. _start_list(sel f, 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, "implementa tion 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 .FancyTreeBuild er):
    ---
    class NamespaceParser (FancyTreeBuild er):
    Only in elementsoap-0.3-20031123-stdlib\elements oap: ElementSOAP.pyc
    diff elementsoap-0.3-20031123\elemen tsoap/HTTPClient.py elementsoap-0.3-20031123-stdlib\elements oap/HTTPClient.py
    57c57
    < from elementtree import ElementTree
    ---
    from xml.etree import ElementTree
    Only in elementsoap-0.3-20031123-stdlib\elements oap: HTTPClient.pyc

  • Fredrik Lundh

    #2
    Re: elementsoap with Python 2.5

    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
    FancyTreeBuilde r class (since only TreeBuilder and XMLTreeBuilder are in
    the xml.etree.Eleme ntTree 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.

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

    </F>

    Comment

    Working...