[Zope-CVS] CVS: Products/AdaptableStorage - patches.py:1.3
Shane Hathaway
shane@zope.com
Fri, 10 Jan 2003 13:31:41 -0500
Update of /cvs-repository/Products/AdaptableStorage
In directory cvs.zope.org:/tmp/cvs-serv2666
Modified Files:
patches.py
Log Message:
Made move/rename work with objects from the filesystem. It took some tricks,
but the tricks have unit tests, so it's not so bad. :-)
- Improved reporting of errors in failed attempts to move objects.
- Added a _setOb() patch that copies objects instead of moving or renaming
them, if that's the only thing that can be done.
- Refactored ZODB branch copying into a simple function, copyOf().
- Made FolderItems set a marker that indicates to _setOb() that it has to
copy rather than move.
Since SQL gateways use FolderItemsByKeychain instead of FolderItems, it has
always been possible to move/rename in a SQL database. None of these
changes affect SQL operations.
=== Products/AdaptableStorage/patches.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/patches.py:1.2 Wed Dec 25 00:27:35 2002
+++ Products/AdaptableStorage/patches.py Fri Jan 10 13:31:08 2003
@@ -18,10 +18,13 @@
from __future__ import nested_scopes
-from DateTime import DateTime
from cPickle import Pickler, Unpickler
from cStringIO import StringIO
+
from Acquisition import aq_base
+from DateTime import DateTime
+
+from zodb.utils import copyOf
def applyPersistentExtraPatch():
@@ -52,30 +55,28 @@
try:
return self._real_getCopy(container)
except NotImplementedError:
- last_ghost = None
- def persistent_id(ob):
- if getattr(ob, '_p_changed', 0) is None:
- # Load temporarily
- if last_ghost is not None:
- last_ghost._p_changed = None
- last_ghost = ob
- ob._p_changed = 0
- return None
- stream = StringIO()
- p = Pickler(stream, 1)
- p.dump(aq_base(self))
- if last_ghost is not None:
- last_ghost._p_changed = None
- stream.seek(0)
- u = Unpickler(stream)
- ob = u.load()
- return ob
+ return copyOf(aq_base(self))
from OFS.CopySupport import CopySource
CopySource._real_getCopy = CopySource._getCopy
CopySource._getCopy = _getCopy
+def applySetObPatch():
+ # Fall back to copying when move/rename is not possible.
+ def _setOb(self, id, object):
+ if getattr(self, '_use_fixed_oids_', 0):
+ if object._p_oid is not None:
+ old = object
+ # Forget changes to the original object
+ old._p_changed = 0
+ object = copyOf(object)
+ setattr(self, id, object)
+
+ from OFS.ObjectManager import ObjectManager
+ ObjectManager._setOb = _setOb
+
+
def applyTmpStorePatch():
from TmpStore import TmpStore as patched_TmpStore
import ZODB.TmpStore
@@ -84,5 +85,6 @@
def applyPatches():
applyPersistentExtraPatch()
applyCopySupportPatch()
+ applySetObPatch()
applyTmpStorePatch()