[XML-SIG] minidom/pulldom connection

Greg Stein gstein@lyra.org
Wed, 22 Nov 2000 14:55:14 -0800


Before: each time you called startDocument(), it would start a new document.
Now, it will only do so the first time.

I would recommend passing a class (a constructor, really) object to __init__
and storing that constructor. startDocument() can then call it
unconditionally like before.

    def __init__(self, cls=xml.dom.minidom.Document):
    ...

[ this does imply moving the import back to the global scope ]

Cheers,
-g

On Wed, Nov 22, 2000 at 03:40:07PM -0500, Fred L. Drake, Jr. wrote:
Content-Description: message body and .signature
> 
> Fred L. Drake, Jr. writes:
>  >   I'm proposing the attached patch to pulldom.
> 
>   Which I'm actually attaching this time...
> 
> 
>   -Fred
> 
> -- 
> Fred L. Drake, Jr.  <fdrake at acm.org>
> PythonLabs at Digital Creations
> 

Content-Description: patch to xml.dom.pulldom
> Index: pulldom.py
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/pulldom.py,v
> retrieving revision 1.11
> diff -c -r1.11 pulldom.py
> *** pulldom.py	2000/10/23 18:09:50	1.11
> --- pulldom.py	2000/11/22 20:38:20
> ***************
> *** 1,4 ****
> - import minidom
>   import xml.sax,xml.sax.handler
>   
>   START_ELEMENT = "START_ELEMENT"
> --- 1,3 ----
> ***************
> *** 11,17 ****
>   CHARACTERS = "CHARACTERS"
>   
>   class PullDOM(xml.sax.ContentHandler):
> !     def __init__(self):
>           self.firstEvent = [None, None]
>           self.lastEvent = self.firstEvent
>           self._ns_contexts = [{}] # contains uri -> prefix dicts
> --- 10,17 ----
>   CHARACTERS = "CHARACTERS"
>   
>   class PullDOM(xml.sax.ContentHandler):
> !     def __init__(self, document=None):
> !         self.document = document
>           self.firstEvent = [None, None]
>           self.lastEvent = self.firstEvent
>           self._ns_contexts = [{}] # contains uri -> prefix dicts
> ***************
> *** 121,127 ****
>           self.lastEvent = self.lastEvent[1]
>   
>       def startDocument(self):
> !         node = self.curNode = self.document = minidom.Document()
>           node.parentNode = None
>           self.lastEvent[1] = [(START_DOCUMENT, node), None]
>           self.lastEvent = self.lastEvent[1]
> --- 121,130 ----
>           self.lastEvent = self.lastEvent[1]
>   
>       def startDocument(self):
> !         if self.document is None:
> !             import xml.dom.minidom
> !             self.document = xml.dom.minidom.Document()
> !         node = self.curNode = self.document
>           node.parentNode = None
>           self.lastEvent[1] = [(START_DOCUMENT, node), None]
>           self.lastEvent = self.lastEvent[1]


-- 
Greg Stein, http://www.lyra.org/