[Zope] Working with TransientObjectContainer

Chris McDonough chrism@zope.com
Thu, 27 Jun 2002 07:23:38 -0400


Hi Gliberto,

TransientObjectContainer's __init__ looks something like this:

def __init__(self, id,
              title=3D'',
              timeout_mins=3D20,
              addNotification=3DNone,
              delNotification=3DNone):

For the "addNotification" and "delNotification" parameters you can pass=20
in either a Zope object path (to a Python Script or External Method,=20
generally) that refers to a callable object or a Python reference to a=20
callable object.  The callable object needs to accept two parameters:=20
"item" and "container".  At call time, "item" is the transient object=20
being notified and "container" is the transient object container.

The addNotification happens when an item is added to the container.

The delNotification happens right before an item is removed from
the container (usually as a result of the item expiring).

So if you create your own TransientObjectContainer with add and delete=20
notifiers, it might look something like this:

def add(self, item, container):
     print "adding %s" % item

def del(self, item, container):
     print "deleting %s" % item

toc =3D TransientObjectContainer(id=3D'toc', title=3D'', timeout_mins=3D2=
0,
                                addNotification=3Dadd, delNotification=3D=
del)


transient_object =3D toc.new_or_existing()
( will print "adding <TransientObject>")
... wait 20 minutes or so ...
toc.nudge()
( might print "deleting <TransientObject>", but may require several nudge=
s)

HTH,

- C


Gilberto Gil Pereira wrote:
> Hi all!!!
>=20
> I'm working on a project that uses Zope (2.5.0) , but most of the work =
is=20
> done in Python (currently 2.1).
>=20
> The thing is that I'm trying to use the Python's class Transience to cr=
eate a=20
> transienteObjectyContainer that calls a method each time an object=20
> contained in it (mostly session objects) expires. The docs say that I c=
an do=20
> this by defining a 'delNotification' when I create that object. So far =
so=20
> good...
> But when a call the class __init__ with an callable method, it is=20
> executed in compilation time, which means that the method is executed=20
> right away, insted of being executed when the object expires. I=B4ve al=
so=20
> tried to pass that method as a string (path+method_name), but Zope asks=
=20
> for the Zope path, and not for the FS path that is used in Python.
>=20
> I'm sure I'm missing the big picture here, so if there's anyone out=20
> there that knows how i can do this, it would help a lot :)
>=20
> Cheers
> Gil
> =09
>=20
>=20
>=20
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -=20
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )

--=20
Chris McDonough                    Zope Corporation
http://www.zope.org             http://www.zope.com
"Killing hundreds of birds with thousands of stones"