Commit 6637d216 authored by Kirill Smelkov's avatar Kirill Smelkov

lib/zodb: Add zstor_2zurl - way to convert a ZODB storage into URL to access it

Wendelin.core 2 will need to spawn WCFS filesystem server that accesses
the same ZODB database as the program that spawns it. The database
argument passed to WCFS is passed in the form of URL[1,2].  Even though
zodburi provides way to convert an URL into ZODB storage instance, there
is currently no way for reverse operation - to convert ZODB storage
instance into URL to access it(*). So we have to build it by our own.

Provide zstor_2zurl stub that currently works for FileStorage only.
ZEO and NEO support is TODO.

In the future we might want to move this functionality into


(*) contrary to ZODB/go where this functionality is provided out of the box:
parent 959ae2d0
......@@ -17,8 +17,9 @@
# See COPYING file for full licensing terms.
# See for rationale and options.
from wendelin.lib.zodb import LivePersistent, deactivate_btree, dbclose, zconn_at, zmajor
from wendelin.lib.zodb import LivePersistent, deactivate_btree, dbclose, zconn_at, zstor_2zurl, zmajor
from wendelin.lib.testing import getTestDB
from wendelin.lib import testing
from persistent import Persistent, UPTODATE, GHOST, CHANGED
from ZODB import DB, POSException
from BTrees.IOBTree import IOBTree
......@@ -351,6 +352,21 @@ def test_zodb_onresync():
# test that zurl does not change from one open to another storage open.
def test_zurlstable():
if not isinstance(testdb, testing.TestDB_FileStorage):
pytest.xfail(reason="zstor_2zurl is TODO for ZEO and NEO")
zurl0 = None
for i in range(10):
zstor = testdb.getZODBStorage()
zurl = zstor_2zurl(zstor)
if i == 0:
zurl0 = zurl
assert zurl == zurl0
# ---- misc ----
# zsync syncs ZODB storage.
......@@ -299,3 +299,20 @@ elif zmajor == 4:
pass # raises in onResyncCallback
# zstor_2zurl converts a ZODB storage to URL to access it.
def zstor_2zurl(zstor):
# There is, sadly, no unified way to do it, as even if storages are created via
# zodburi, after creation its uri is lost. And storages could be created not
# only through URI but e.g. via ZConfig and manually. We want to support all
# those cases...
# For this reason extract URL with important for wcfs use-case parameters in
# ad-hoc way.
if isinstance(zstor, FileStorage):
return "file://%s" % (zstor._file_name,)
# TODO ZEO + NEO support
raise NotImplementedError("don't know how to extract zurl from %r" % zstor)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment