[Zope-CVS] CVS: Products/ZopeVersionControl - Version.py:1.2
Brian Lloyd
brian@digicool.com
Fri, 19 Oct 2001 15:03:34 -0400
Update of /cvs-repository/Products/ZopeVersionControl
In directory cvs.zope.org:/tmp/cvs-serv8983
Modified Files:
Version.py
Log Message:
implement quick-hack of read-only protection for version data
=== Products/ZopeVersionControl/Version.py 1.1 => 1.2 ===
return self.records
+ def getReadOnlyObject(self):
+ """Return the object corresponding to this version."""
+ object = Acquisition.aq_base(self.data)
+ object._p_jar = ReadOnlyJar(object._p_jar)
+ return object
+
def saveState(self, object):
baseobj = Acquisition.aq_base(object)
# xxx - fix this!
@@ -107,4 +113,41 @@
return self.id
InitializeClass(Version)
+
+
+
+
+def historicalRevision(self, serial):
+ state=self._p_jar.oldstate(self, serial)
+ rev=self.__class__.__basicnew__()
+ rev._p_jar=HystoryJar(self._p_jar)
+ rev._p_oid=self._p_oid
+ rev._p_serial=serial
+ rev.__setstate__(state)
+ rev._p_changed=0
+ return rev
+
+
+class ReadOnlyJar:
+ """A read-only ZODB connection-like object that prevents changes."""
+
+ def __init__(self, base):
+ self.__base__=base
+
+ _invalidating = []
+
+ def __getattr__(self, name):
+ return getattr(self.__base__, name)
+
+ def commit(*args, **kw):
+ raise VersionWriteError(
+ 'Old versions of objects cannot be modified.'
+ )
+
+ def abort(*args, **kw):
+ pass
+
+
+class VersionWriteError(Exception):
+ pass