[XML-SIG] DOM and Proxies

Paul Prescod paul@prescod.net
Fri, 18 Feb 2000 07:54:03 -0800

I propose that for Python 1.6 we define a generic Proxy mechanism with
the following properties:

You wrap an object by calling Proxy( object ). For an object to be
proxy-wrappable it must have an __unlink__ method. The object that you
pass to the original Proxy() call is calld the LemmingLeader.

Proxies proxy all method calls, field accesses and tp_...methods. 

When a field is accessed or a method called it looks at the returned
object. If it is proxy-wrappable, (e.g. a DOM or grove node) it is
wrapped. If it isn't, (e.g. an integer) it isn't. 

Proxied objects have "families". All objects in a family live for the
same length of time. Families are expected to be completely internally
linked. There is one proxy "family" for every LemmingLeader (created
through an explicit call to the proxy method) (e.g. one per DOM).

There is a hidden "proxy family object" -- it is used only for its
refcount and its reference to the patriarch. When a proxy generates a
proxy, it passes a reference to the family object.

When all proxies go away (the user is no longer interested in the object
family) the family object calls the LemmingLeader's __unlink__ method
which is presumed to unlink the object and recursively unlink and thus
destroy all children.

Proxies have an __realnode__ method to get back the real, real node. If
you hold a real reference to a real node and throw away the last proxy
then you will find that everything in that node's family except the node
is gone.

All of the proxy stuff is implemented in C so that it is very efficient.
Proxied objects can be implemented in C or Python.

We would use this class for both xml.dom and a minidom in the standard
library. It would also be usable from Pyxie, groves easysax, and
anywhere else that reference counting of cyclic objects is necessary.

Opinions? I would actually sneak this class into a C-coded minidom
library (built directly on top of expat) for use by anyone who knows it
is there.

 Paul Prescod  - ISOGEN Consulting Engineer speaking for himself
"The calculus and the rich body of mathematical analysis to which it
gave rise made modern science possible, but it was the algorithm that
made possible the modern world." 
        - from "Advent of the Algorithm" David Berlinski