Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install z3c.mountpoint

How to install z3c.mountpoint

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install z3c.mountpoint
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1 Available View build log
Windows (64-bit)
0.1 Available View build log
Mac OS X (10.5+)
0.1 Available View build log
Linux (32-bit)
0.1 Available View build log
Linux (64-bit)
0.1 Available View build log
ZPL 2.1
Lastest release
version 0.1 on Jan 5th, 2011

ZODB Mount Point

This package provides a very simple implementation of a mount point for an object in another ZODB connection. If you have multiple connections defined in your zope.conf configuration file or multiple databases defined in your Python code, you can use this package to mount any object from any database at any location of another database.

Let's start by creating two databases in the typical Zope 3 application layout:

>>> from ZODB.tests.test_storage import MinimalMemoryStorage
>>> from ZODB import DB
>>> from zope.site.folder import rootFolder, Folder
>>> import transaction
>>> dbmap = {}
>>> db1 = DB(MinimalMemoryStorage(), database_name='db1', databases=dbmap)
>>> conn1 = db1.open()
>>> conn1.root()['Application'] = rootFolder()
>>> db2 = DB(MinimalMemoryStorage(), database_name='db2', databases=dbmap)
>>> conn2 = db2.open()
>>> conn2.root()['Application'] = rootFolder()
>>> transaction.commit()

Let's now add a sub-folder to the second database, which will serve as the object which we wish to mount:

>>> conn2.root()['Application']['Folder2-1'] = Folder()
>>> transaction.commit()

We can now create a mount point:

>>> from z3c.mountpoint import mountpoint
>>> mountPoint = mountpoint.MountPoint(
...     'db2', objectPath=u'/Folder2-1', objectName=u'F2-1')

The first argument to the constructor is the connection name of the database, the second argument is the path to the mounted object within the mounted DB and the object name is the name under which the object is mounted.

Now we can add the mount point to the first database:

>>> conn1.root()['Application']['mp'] = mountPoint
>>> transaction.commit()

We can now access the mounted object as follows:

>>> conn1.root()['Application']['mp'].object
<zope.site.folder.Folder object at ...>

Note that the object name is not yet used; it is for traversal only.


So let's have a look at the traversal next. Before being able to traverse, we need to register the special mount point traverser:

>>> import zope.component
>>> zope.component.provideAdapter(mountpoint.MountPointTraverser)

We should now be able to traverse to the mounted object now:

>>> from zope.publisher.browser import TestRequest
>>> req = TestRequest()
>>> from zope.traversing.publicationtraverse import PublicationTraverser
>>> traverser = PublicationTraverser()
>>> traverser.traversePath(req, conn1.root()['Application'], 'mp/F2-1')
<zope.site.folder.Folder object at ...>

When we add a new object remotely, it available via the mount point as well:

>>> conn2.root()['Application']['Folder2-1']['Folder2-1.1'] = Folder()
>>> transaction.commit()
>>> tuple(traverser.traversePath(
...    req, conn1.root()['Application'], 'mp/F2-1').keys())

Now, by default the objects refer to their original path:

>>> f211 = traverser.traversePath(
...    req, conn1.root()['Application'], 'mp/F2-1/Folder2-1.1')
>>> from zope.traversing.browser import absoluteurl
>>> absoluteurl.absoluteURL(f211, req)

This package solves that problem by wrapping all object by a special remote location proxy and providing a special wrapping traverser for those proxies:

>>> from z3c.mountpoint import remoteproxy
>>> zope.component.provideAdapter(remoteproxy.RemoteLocationProxyTraverser)
>>> f211 = traverser.traversePath(
...    req, conn1.root()['Application'], 'mp/F2-1/Folder2-1.1')
>>> absoluteurl.absoluteURL(f211, req)
Updating the Mount Point

Whenever any attribute on the mount point is modified, the mount object is updated. For example, when the object path is changed, the object is adjusted as well. This is done with an event subscriber:

>>> mountPoint.objectPath = u'/Folder2-1/Folder2-1.1'
>>> modifiedEvent = object()
>>> mountpoint.updateMountedObject(mountPoint, modifiedEvent)
>>> f211 == mountPoint.object

Change log

0.1 (2010-08-03)
  • Initial release.

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.