[Zope-CVS] CVS: Products/Ape/lib/apelib/zodb3 -
connection.py:1.6.2.2 serializers.py:1.3.2.2
Shane Hathaway
shane at zope.com
Fri Dec 19 21:53:20 EST 2003
Update of /cvs-repository/Products/Ape/lib/apelib/zodb3
In directory cvs.zope.org:/tmp/cvs-serv5534/zodb3
Modified Files:
Tag: ape-0_8-branch
connection.py serializers.py
Log Message:
Cleaned up to the point that ApelibImplTests pass.
=== Products/Ape/lib/apelib/zodb3/connection.py 1.6.2.1 => 1.6.2.2 ===
--- Products/Ape/lib/apelib/zodb3/connection.py:1.6.2.1 Sat Dec 13 23:24:47 2003
+++ Products/Ape/lib/apelib/zodb3/connection.py Fri Dec 19 21:52:49 2003
@@ -398,6 +398,9 @@
% (repr(obj), repr(obj._p_jar), repr(self)))
return oid
+ def new_oid(self):
+ return self._storage.new_oid()
+
def getClass(self, module, name):
return self._db._classFactory(self, module, name)
@@ -431,7 +434,7 @@
# a _serials dictionary.
_serials = None
- SERIAL_CLEANUP_THRESHOLD = 1000
+ serial_cleanup_threshold = 1000
def getSerial(self, ob):
oid = ob._p_oid
@@ -453,10 +456,10 @@
self._serials = serials
if not serials.has_key(oid):
# When the number of recorded serials exceeds the number of
- # cache entries by SERIAL_CLEANUP_THRESHOLD, prune the serials
+ # cache entries by serial_cleanup_threshold, prune the serials
# dictionary.
if (len(serials) >= len(self._cache) +
- self.SERIAL_CLEANUP_THRESHOLD):
+ self.serial_cleanup_threshold):
# clean up
cache_get = self._cache.get
for oid in serials.keys():
=== Products/Ape/lib/apelib/zodb3/serializers.py 1.3.2.1 => 1.3.2.2 ===
--- Products/Ape/lib/apelib/zodb3/serializers.py:1.3.2.1 Wed Dec 17 23:43:54 2003
+++ Products/Ape/lib/apelib/zodb3/serializers.py Fri Dec 19 21:52:49 2003
@@ -28,7 +28,7 @@
from apelib.core.interfaces \
import ISerializer, IFullSerializationEvent, IFullDeserializationEvent
from apelib.core.events import SerializationEvent, DeserializationEvent
-from apelib.core.exceptions import SerializationError
+from apelib.core.interfaces import SerializationError
from apelib.core.schemas import RowSequenceSchema, FieldSchema
@@ -59,58 +59,58 @@
event.ignore(('data', '_container'))
return res
- def deserialize(self, obj, event, state):
- assert self.canSerialize(obj)
+ def deserialize(self, event, state):
+ assert self.canSerialize(event.obj)
data = {}
for (key, oid) in state:
value = event.resolve(key, oid)
data[key] = value
- obj.__init__(data)
-
+ event.obj.__init__(data)
-class FixedPersistentMapping:
- """Unchanging persistent mapping.
- Generally used for a ZODB root object.
- """
+##class FixedPersistentMapping:
+## """Unchanging persistent mapping.
- __implements__ = ISerializer
- schema = None # No storage
+## Generally used for a ZODB root object.
+## """
- def __init__(self):
- # map: { name -> (oid, mapper) }
- self.map = {}
-
- def add(self, name, oid, mapper_name=None):
- self.map[name] = (oid, mapper_name)
-
- def canSerialize(self, obj):
- return isinstance(obj, PersistentMapping)
-
- def serialize(self, obj, event):
- names = obj.keys()
- names.sort()
- expected = self.map.keys()
- expected.sort()
- assert names == expected, '%s != %s' % (names, expected)
- for name in names:
- oid, mapper_name = self.map[name]
- subob = obj[name]
- event.referenced(name, subob, False, oid)
- event.ignore(('data', '_container'))
-
- def deserialize(self, obj, event, state):
- assert state is None
- data = {}
- for name, (oid, mapper_name) in self.map.items():
- subob = event.resolve(
- name, oid, {'mapper_name': mapper_name})
- data[name] = subob
- # The PersistentMapping doesn't have its data or _container
- # attribute yet, and we don't know what its name should be
- # since PersistentMapping's internal structure is not fixed.
- # So call the PersistentMapping's constructor.
- obj.__init__(data)
+## __implements__ = ISerializer
+## schema = None # No storage
+
+## def __init__(self):
+## # map: { name -> (oid, mapper) }
+## self.map = {}
+
+## def add(self, name, oid, mapper_name=None):
+## self.map[name] = (oid, mapper_name)
+
+## def canSerialize(self, obj):
+## return isinstance(obj, PersistentMapping)
+
+## def serialize(self, obj, event):
+## names = obj.keys()
+## names.sort()
+## expected = self.map.keys()
+## expected.sort()
+## assert names == expected, '%s != %s' % (names, expected)
+## for name in names:
+## oid, mapper_name = self.map[name]
+## subob = obj[name]
+## event.referenced(name, subob, False, oid)
+## event.ignore(('data', '_container'))
+
+## def deserialize(self, obj, event, state):
+## assert state is None
+## data = {}
+## for name, (oid, mapper_name) in self.map.items():
+## subob = event.resolve(
+## name, oid, {'mapper_name': mapper_name})
+## data[name] = subob
+## # The PersistentMapping doesn't have its data or _container
+## # attribute yet, and we don't know what its name should be
+## # since PersistentMapping's internal structure is not fixed.
+## # So call the PersistentMapping's constructor.
+## obj.__init__(data)
class RollCall:
@@ -124,14 +124,14 @@
def canSerialize(self, obj):
return 1
- def serialize(self, obj, event):
+ def serialize(self, event):
assert IFullSerializationEvent.isImplementedBy(event)
attrs = event.getSerializedAttributeNames()
attrs_map = {}
for attr in attrs:
attrs_map[attr] = 1
missed = []
- for k in obj.__dict__.keys():
+ for k in event.obj.__dict__.keys():
if not k.startswith('_v_') and not attrs_map.has_key(k):
missed.append(repr(k))
if missed:
@@ -140,7 +140,7 @@
(', '.join(missed), repr(event.getOid())))
return None
- def deserialize(self, obj, event, state):
+ def deserialize(self, event, state):
assert state is None
@@ -159,15 +159,15 @@
return 0
- def serialize(self, obj, event):
+ def serialize(self, event):
assert IFullSerializationEvent.isImplementedBy(event)
- assert isinstance(obj, Persistent)
+ assert isinstance(event.obj, Persistent)
# Allow pickling of cyclic references to the object.
- event.serialized('self', obj, False)
+ event.serialized('self', event.obj, False)
# Ignore previously serialized attributes
- state = obj.__dict__.copy()
+ state = event.obj.__dict__.copy()
for key in state.keys():
if key.startswith('_v_'):
del state[key]
@@ -222,7 +222,7 @@
raise RuntimeError(
'Unable to pickle the %s attribute, %s, '
'of %s at %s. %s.' % (
- repr(attrname), repr(attrvalue), repr(obj),
+ repr(attrname), repr(attrvalue), repr(event.obj),
repr(event.oid), str(exc)))
else:
# Couldn't help.
@@ -235,19 +235,19 @@
return s
- def deserialize(self, obj, event, state):
+ def deserialize(self, event, state):
assert IFullDeserializationEvent.isImplementedBy(event)
- assert isinstance(obj, Persistent)
+ assert isinstance(event.obj, Persistent)
# Set up to resolve cyclic references to the object.
- event.deserialized('self', obj)
+ event.deserialized('self', event.obj)
if state:
infile = StringIO(state)
u = Unpickler(infile)
u.persistent_load = event.resolveInternal
s = u.load()
- obj.__dict__.update(s)
+ event.obj.__dict__.update(s)
try:
unmanaged = u.load()
except EOFError:
@@ -281,14 +281,14 @@
args = time.gmtime(t)[:5] + (t%60,)
obj._p_serial = repr(TimeStamp(*args))
- def serialize(self, obj, event):
+ def serialize(self, event):
now = long(time.time())
- if obj._p_changed:
+ if event.obj._p_changed:
# Indicate that this object just changed. Note that the time
# is a guess.
- self.setTime(obj, now)
+ self.setTime(event.obj, now)
return now
- def deserialize(self, obj, event, state):
- self.setTime(obj, state)
+ def deserialize(self, event, state):
+ self.setTime(event.obj, state)
More information about the Zope-CVS
mailing list