Commit ab820183 authored by Toby Dickenson's avatar Toby Dickenson

Merged toby-extension-method-branch - ZEO now asks its storages if there are...

Merged toby-extension-method-branch - ZEO now asks its storages if there are extra methods that should be proxied by the ClientStorage. This is useful for storages which have features not covered by the standard storage API
parent f3a6b8cd
......@@ -398,6 +398,18 @@ class ClientStorage:
"""Storage API: an approximate size of the database, in bytes."""
return self._info['size']
def getExtensionMethods(self):
"""getExtensionMethods
This returns a dictionary whose keys are names of extra methods
provided by this storage. Storage proxies (such as ZEO) should
call this method to determine the extra methods that they need
to proxy in addition to the standard storage methods.
Dictionary values should be None; this will be a handy place
for extra marshalling information, should we need it
"""
return self._info['extensionMethods']
def supportsUndo(self):
"""Storage API: return whether we support undo."""
return self._info['supportsUndo']
......@@ -465,6 +477,12 @@ class ClientStorage:
"""
return self._server.history(oid, version, length)
def __getattr__(self, name):
if self.getExtensionMethods().has_key(name):
return self._server.extensionMethod(name)
else:
raise AttributeError(name)
def loadSerial(self, oid, serial):
"""Storage API: load a historical revision of an object."""
return self._server.loadSerial(oid, serial)
......@@ -792,3 +810,5 @@ class ClientStorage:
invalidate = invalidateVerify
end = endVerify
Invalidate = invalidateTrans
......@@ -33,6 +33,9 @@ class StorageServer:
"""
self.rpc = rpc
def extensionMethod(self, name):
return ExtensionMethodWrapper(self.rpc, name).call
def _update(self):
"""Handle pending incoming messages.
......@@ -137,3 +140,10 @@ class StorageServer:
return self.rpc.call('versions')
else:
return self.rpc.call('versions', max)
class ExtensionMethodWrapper:
def __init__(self, rpc, name):
self.rpc = rpc
self.name = name
def call(self, *a, **kwa):
return apply(self.rpc.call, (self.name,)+a, kwa)
......@@ -249,6 +249,18 @@ class ZEOStorage:
self.load = self.storage.load
self.loadSerial = self.storage.loadSerial
self.modifiedInVersion = self.storage.modifiedInVersion
try:
fn = self.storage.getExtensionMethods
except AttributeError:
# We must be running with a ZODB which
# predates adding getExtensionMethods to
# BaseStorage. Eventually this try/except
# can be removed
pass
else:
for name in fn().keys():
if not hasattr(self,name):
setattr(self, name, getattr(self.storage, name))
def check_tid(self, tid, exc=None):
if self.read_only:
......@@ -300,6 +312,7 @@ class ZEOStorage:
'supportsVersions': self.storage.supportsVersions(),
'supportsTransactionalUndo':
self.storage.supportsTransactionalUndo(),
'extensionMethods': self.getExtensionMethods(),
}
def get_size_info(self):
......@@ -307,6 +320,14 @@ class ZEOStorage:
'size': self.storage.getSize(),
}
def getExtensionMethods(self):
try:
e = self.storage.getExtensionMethods
except AttributeError:
return {}
else:
return e()
def zeoLoad(self, oid):
v = self.storage.modifiedInVersion(oid)
if v:
......
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