[XML-SIG] minidom/pulldom connection

Greg Stein gstein@lyra.org
Thu, 23 Nov 2000 01:45:45 -0800

On Thu, Nov 23, 2000 at 03:28:09AM -0700, Mike Olson wrote:
> Greg Stein wrote:
> > 
> > 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):
> >     ...
> Why not take it one step further, and pass an instance of a
> DOMImplementation into the contructor.  The reason I don't like to class
> idea, is you limit DOM implementors, now all document contructors must
> default all parameters (or not have any).  As an example, I'm working on
> a persistent DOM implementation that will probably need a database
> connection in it contructor.
> I don't rememeber if minidom has a DOMImplementation though, however its
> trivial to write.

class DatabaseDOMFactory:
    def __init__(self, dbparams):
        self.dbparams = dbparams
    def __call__(self):  # no params as a PullDOM constructor
        return DatabaseDOM(self.dbparams)

factory = DatabaseDOMFactory(some_params)
pd = PullDOM(factory)

Not so hard :-)

A callable object is alays more flexible than a single instance. The
startDocument() also needs to be able to *construct* multiple documents (one
per invocation). If you pass a single instance, then you lose that behavior.
(which was the basis of my original comment re: Fred's change)


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