[Python-Dev] ReleaseNode interface in 4XSLT (original) (raw)

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Sun, 13 May 2001 14:08:02 +0200


Currently, 4XSLT has a dependency on the DOM implementation in terms of memory management (among other dependencies). I'd like to reduce this dependency, by providing a centralized function that knows how to release nodes.

In PyXML, I currently use

Define ReleaseNode in a DOM-independent way

import xml.dom.ext import xml.dom.minidom def _releasenode(n): if isinstance(n, xml.dom.minidom.Node): n.unlink() else: xml.dom.ext.ReleaseNode(n)

try: from Ft.Lib import pDomlette def ReleaseNode(n): if isinstance(n, pDomlette.Node): pDomlette.ReleaseNode(n) else: _releasenode(n) _XsltElementBase = pDomlette.Element except ImportError: ReleaseNode = _releasenode from minisupport import _XsltElementBase

This code knows how to release minidom, 4DOM, and pDomlette nodes, and supports installations without 4Suite (i.e. without pDomlette). I've put this into xslt/init.py, so that all callers of Ft.Lib.pDomlette.ReleaseNode now need to call xml.xslt.ReleaseNode. If desired, I could produce a patch against the public Ft CVS.

As a slightly independent question, such a function also ought to support DOM implementations not known to it; I'm thinking in particular of the Zope DOMs. I'd like to hear proposals on how such an interface should work; I see three options:

a) it is an operation on the document node (or any node), as in minidom. b) it is an operation on the DOM implementation (almost as in 4Suite; you'd need to navigate from the node to the implementation, then you'd need a well-known operation on the implementation) c) the code assumes that no release activity is necessary for unknown DOMs, effectively believing in reference counting, garbage collection, acquisition, and other black art.

Any comments appreciated, in particular

  1. from the Ft maintainers on introducing xml.xslt.ReleaseNode, and
  2. from authors of other DOMs on a general memory management API for Python DOM.

Regards, Martin