Class
zope.location.pickling.PathPersistent

Persistence hooks for pickling locations

See locationCopy above.

Unlike copy persistent, we use paths for ids of outside locations so that we can separate pickling and unpickling in time. We have to compute paths and traverse objects to load paths, but paths can be stored for later use, unlike the ids used by CopyPersistent.

We require outside locations that can be adapted to ITraversable. To simplify the example, we'll use a simple traversable location defined in zope.location.tests, TLocation.

Normally, general adapters are used to make objects traversable.

We get initialized with an initial location:

>>> o1 = Location()
>>> persistent = PathPersistent(o1)

We provide an id function that returns None when given a non-location:

>>> persistent.id(42)

Or when given a location that is inside the initial location:

>>> persistent.id(o1)
>>> o2 = Location(); o2.__parent__ = o1
>>> persistent.id(o2)

But, if we get a location outside the original location, we return it's path. To compute it's path, it must be rooted:

>>> from zope.location.tests import TLocation
>>> root = TLocation()
>>> zope.interface.directlyProvides(root, IContainmentRoot)
>>> o3 = TLocation(); o3.__name__ = 'o3'
>>> o3.__parent__ = root; root.o3 = o3
>>> persistent.id(o3)
u'/o3'
>>> o4 = TLocation(); o4.__name__ = 'o4'
>>> o4.__parent__ = o3; o3.o4 = o4
>>> persistent.id(o4)
u'/o3/o4'

We also provide a load function that returns objects by traversing given paths. It has to find the root based on the object given to the constructor. Therefore, that object must also be rooted:

>>> o1.__parent__ = root
>>> persistent.load(u'/o3') is o3
1
>>> persistent.load(u'/o3/o4') is o4
1

Base classes

Implemented Interfaces

There are no implemented interfaces.

Attributes/Properties

There are no attributes in this class.

Methods

Known Subclasses

There are no known subclasses.