[Zope-CVS] CVS: Products/Ape/lib/apelib/core -
classifiers.py:1.1.8.2 events.py:1.6.2.3 gateways.py:1.7.2.3
interfaces.py:1.9.2.3 io.py:1.6.2.3 schemas.py:1.4.4.2
Shane Hathaway
shane at zope.com
Wed Dec 17 23:44:24 EST 2003
Update of /cvs-repository/Products/Ape/lib/apelib/core
In directory cvs.zope.org:/tmp/cvs-serv13372/lib/apelib/core
Modified Files:
Tag: ape-0_8-branch
classifiers.py events.py gateways.py interfaces.py io.py
schemas.py
Log Message:
Continued renaming and refactoring.
tmp/map.py contains notes on the new names for things.
=== Products/Ape/lib/apelib/core/classifiers.py 1.1.8.1 => 1.1.8.2 ===
--- Products/Ape/lib/apelib/core/classifiers.py:1.1.8.1 Sat Dec 13 12:08:06 2003
+++ Products/Ape/lib/apelib/core/classifiers.py Wed Dec 17 23:43:53 2003
@@ -22,7 +22,7 @@
class FixedClassifier:
- """Classifies objects based purely on the keychain."""
+ """Classifies objects based purely on the OID."""
__implements__ = IConfigurableClassifier
=== Products/Ape/lib/apelib/core/events.py 1.6.2.2 => 1.6.2.3 ===
--- Products/Ape/lib/apelib/core/events.py:1.6.2.2 Sat Dec 13 23:24:46 2003
+++ Products/Ape/lib/apelib/core/events.py Wed Dec 17 23:43:53 2003
@@ -43,7 +43,8 @@
__implements__ = interfaces.IMapperEvent
- def __init__(self, mapper, oid):
+ def __init__(self, conf, mapper, oid):
+ self.conf = conf
self.mapper = mapper
self.oid = oid
@@ -52,8 +53,8 @@
__implements__ = interfaces.IGatewayEvent
- def __init__(self, mapper, oid, connections, classification):
- MapperEvent.__init__(self, mapper, oid)
+ def __init__(self, conf, mapper, oid, connections, classification):
+ MapperEvent.__init__(self, conf, mapper, oid)
self.connections = connections
self.classification = classification
@@ -69,13 +70,19 @@
__implements__ = interfaces.IStoreEvent
+ def __init__(self, conf, mapper, oid, connections, classification,
+ overwrite):
+ GatewayEvent.__init__(
+ self, conf, mapper, oid, connections, classification)
+ self.overwrite = overwrite
+
class SDEvent (MapperEvent):
__implements__ = interfaces.ISDEvent
- def __init__(self, obj_db, mapper, oid, obj):
- MapperEvent.__init__(self, mapper, oid)
+ def __init__(self, conf, mapper, oid, obj_db, obj):
+ MapperEvent.__init__(self, conf, mapper, oid)
self.obj_db = obj_db
self.obj = obj
self.serializer_name = ''
@@ -88,8 +95,8 @@
__implements__ = interfaces.IFullDeserializationEvent
- def __init__(self, obj_db, mapper, oid, obj):
- SDEvent.__init__(self, obj_db, mapper, oid, obj)
+ def __init__(self, conf, mapper, oid, obj_db, obj):
+ SDEvent.__init__(self, conf, mapper, oid, obj_db, obj)
self._loaded_refs = {} # { (serializer_name, name) -> object }
# IDeserializationEvent interface methods:
@@ -97,7 +104,7 @@
def deserialized(self, name, value):
self._loaded_refs['%s:%s' % (self.serializer_name, name)] = value
- def load(self, name, oid, hints=None):
+ def resolve(self, name, oid, hints=None):
"""Retrieves a referenced subobject (usually ghosted initially).
"""
ob = self.obj_db.getObject(oid, hints)
@@ -107,7 +114,7 @@
# IFullDeserializationEvent interface methods:
- def loadRef(self, ref):
+ def resolveInternal(self, ref):
"""Returns an object already deserialized by another serializer.
'ref' is a tuple containing (serializer_name, name).
@@ -119,8 +126,8 @@
__implements__ = interfaces.IFullSerializationEvent
- def __init__(self, obj_db, mapper, oid, obj):
- SDEvent.__init__(self, obj_db, mapper, oid, obj)
+ def __init__(self, conf, mapper, oid, obj_db, obj):
+ SDEvent.__init__(self, conf, mapper, oid, obj_db, obj)
self._attrs = {}
# _internal_refs:
# id(ob) -> (serializer_name, name)
@@ -152,7 +159,7 @@
if is_attribute and name is not None:
self._attrs[name] = 1
- def store(self, name, value, is_attribute, oid):
+ def referenced(self, name, value, is_attribute, oid):
assert oid is not None
self.external.append((oid, value))
self.serialized(name, value, is_attribute)
@@ -171,6 +178,6 @@
"""Returns the name of all attributes serialized."""
return self._attrs.keys()
- def identifyRef(self, ob):
+ def identifyInternal(self, ob):
"""Returns (serializer_name, name) or None."""
return self._internal_refs.get(id(ob))
=== Products/Ape/lib/apelib/core/gateways.py 1.7.2.2 => 1.7.2.3 ===
--- Products/Ape/lib/apelib/core/gateways.py:1.7.2.2 Sat Dec 13 23:24:46 2003
+++ Products/Ape/lib/apelib/core/gateways.py Wed Dec 17 23:43:53 2003
@@ -18,7 +18,7 @@
import time
-from interfaces import IGateway, NoStateFoundError
+from interfaces import IGateway
class CompositeGateway:
@@ -80,7 +80,7 @@
serials = {}
for name, gw in self._gws.items():
state = full_state.get(name)
- # print 'gateway storing', keychain, name, state
+ # print 'gateway storing', event.oid, name, state
serial = gw.store(event, state)
if serial is not None:
serials[name] = serial
@@ -111,10 +111,7 @@
def load(self, event):
# Returns (data, serial)
- try:
- return self.data[event.oid]
- except KeyError:
- raise NoStateFoundError(event.oid)
+ return self.data[event.oid]
def store(self, event, data):
h = time.time()
=== Products/Ape/lib/apelib/core/interfaces.py 1.9.2.2 => 1.9.2.3 ===
--- Products/Ape/lib/apelib/core/interfaces.py:1.9.2.2 Sat Dec 13 23:24:46 2003
+++ Products/Ape/lib/apelib/core/interfaces.py Wed Dec 17 23:43:53 2003
@@ -37,9 +37,6 @@
class ClassificationError(MappingError):
"""Error during classification"""
-class NoStateFoundError(MappingError):
- """No state is there to load"""
-
class ConfigurationError(Exception):
"""Invalid mapper configuration"""
@@ -116,7 +113,9 @@
class IMapperEvent (Interface):
"""The base interface for events occurring in context of a mapper."""
- mapper = Attribute(description="The mapper")
+ conf = Attribute(description="The IMapperConfiguration")
+
+ mapper = Attribute(description="The IMapper")
oid = Attribute(description="The OID of the object being mapped")
@@ -136,6 +135,13 @@
class IStoreEvent (IGatewayEvent):
"""Interface for events involved in storing objects."""
+ overwrite = Attribute(description="""True if the gateway may overwrite.
+
+ When this attribute is true, gateways should overwrite existing
+ data. When it is false, gateways should not overwrite existing
+ data and instead raise a conflict error.
+ """)
+
class ISDEvent (IMapperEvent):
"""Base for serialization and deserialization events."""
@@ -172,10 +178,20 @@
def deserialized(name, value):
"""Indicates that a named subobject was deserialized.
+
+ The event records an intra-record reference. Be careful to
+ unwrap non-persistent wrappers around the value before calling
+ this method.
"""
- def load(name, oid, hints=None):
- """Retrieves a referenced subobject (usually ghosted initially).
+ def resolve(name, oid, hints=None):
+ """Returns the object identified by an inter-record reference.
+
+ The object should have been stored earlier through a call to
+ ISerializationEvent.reference(). The return value is usually
+ ghosted initially.
+
+ The event also records an intra-record reference.
"""
@@ -183,8 +199,8 @@
"""Deserialization event with features for deserializing remainder data.
"""
- def loadRef(ref):
- """Returns an object already deserialized by another serializer.
+ def resolveInternal(ref):
+ """Returns the object identified by an intra-record reference.
'ref' is a tuple containing (serializer_name, name).
"""
@@ -201,17 +217,26 @@
def serialized(name, value, is_attribute):
"""Indicates that a named subobject was serialized.
- This allows a 'remainder pickler' to refer to subobjects by name.
- Be careful to unwrap acquisition and/or context wrappers around
- the value before calling this method.
+ The event records an intra-record reference. Be careful to
+ unwrap non-persistent wrappers around the value before calling
+ this method.
"""
- def store(name, value, is_attribute, oid):
- """Notifies the system that a subobject needs to be stored.
+ def referenced(name, value, is_attribute, oid):
+ """Notifies the system of an inter-record reference.
+
+ Be careful to unwrap non-persistent wrappers around the value
+ before calling this method. Once the referenced object gets
+ stored, the deserialize() method of the serializer will be
+ able to find the referenced object by calling
+ IDeserializationEvent.resolve().
+
+ The event also records an intra-record reference.
"""
def ignore(name_or_names):
- """Indicates that attributes should be ignored when storing."""
+ """Indicates attribute name(s) to be ignored when serializing.
+ """
class IFullSerializationEvent(ISerializationEvent):
@@ -221,10 +246,14 @@
"""
def getSerializedAttributeNames():
- """Returns the name of all attributes serialized."""
+ """Returns the names of all attributes serialized.
+ """
+
+ def identifyInternal(ob):
+ """Returns the intra-record reference for a subobject, if there is one.
- def identifyRef(ob):
- """Returns (serializer_name, name) or None."""
+ Returns (serializer_name, name) or None.
+ """
class ISerializer(Interface):
@@ -247,7 +276,7 @@
"""Fills in the state of this part of the object.
Use the IDeserializationEvent to resolve external references.
- Returns nothing.
+ No return value.
"""
@@ -427,6 +456,17 @@
'path' gives the path to the mapper, for debugging purposes.
'recursive' can be turned off to not descend into sub-mappers.
"""
+
+
+class IMapperConfiguration (Interface):
+ """A configuration of mappers.
+ """
+
+ mappers = Attribute(description="Maps mapper name to IMapper")
+
+ classifier = Attribute(description="The IClassifier")
+
+ oid_gen = Attribute(description="The IOIDGenerator")
class ITPCConnection(Interface):
=== Products/Ape/lib/apelib/core/io.py 1.6.2.2 => 1.6.2.3 ===
--- Products/Ape/lib/apelib/core/io.py:1.6.2.2 Sat Dec 13 23:24:46 2003
+++ Products/Ape/lib/apelib/core/io.py Wed Dec 17 23:43:53 2003
@@ -23,7 +23,7 @@
from events \
import DatabaseInitEvent, GatewayEvent, LoadEvent, StoreEvent, \
SerializationEvent, DeserializationEvent
-from interfaces import ITPCConnection, IObjectDatabase
+from interfaces import ITPCConnection, IObjectDatabase, IMapperConfiguration
class ClassifiedState:
@@ -36,6 +36,8 @@
class MapperConfiguration:
+ __implements__ = IMapperConfiguration
+
def __init__(self, mappers, classifier, oid_gen):
self.mappers = mappers
self.classifier = classifier
@@ -99,34 +101,35 @@
initializer.init(event)
def classifyState(self, oid):
- event = LoadEvent(None, oid, self.conn_map, None)
+ event = LoadEvent(self.conf, None, oid, self.conn_map, None)
# Return (classification, mapper_name)
return self.conf.classifier.classifyState(event)
def load(self, oid):
classification, mapper_names = self.classifyState(oid)
mapper = self.conf.mappers[mapper_name]
- event = LoadEvent(mapper, oid, self.conn_map, classification)
+ event = LoadEvent(self.conf, mapper, oid, self.conn_map, classification)
state, hash_value = mapper.gateway.load(event)
cs = ClassifiedState(state, classification, mapper_name)
return event, cs, hash_value
- def store(self, oid, classified_state):
+ def store(self, oid, classified_state, overwrite):
mapper = self.conf.mappers[classified_state.mapper_name]
- event = StoreEvent(mapper, oid, self.conn_map,
- classified_state.classification)
+ event = StoreEvent(self.conf, mapper, oid, self.conn_map,
+ classified_state.classification, overwrite)
new_hash = mapper.gateway.store(event, classified_state.state)
self.conf.classifier.store(event, classification)
return event, new_hash
def getPollSources(self, oid):
- classification, mapper_names = self.classifyState(oid)
- event = LoadEvent(mapper, oid, self.conn_map, classification)
+ classification, mapper_name = self.classifyState(oid)
+ mapper = self.conf.mappers[mapper_name]
+ event = LoadEvent(self.conf, mapper, oid, self.conn_map, classification)
return mapper.gateway.getPollSources(event)
def new_oid(self):
- event = GatewayEvent(None, None, self.conn_map, None)
- return self.oid_gen.new_oid(event, None, 1)
+ event = GatewayEvent(self.conf, None, None, self.conn_map, None)
+ return self.conf.oid_gen.new_oid(event, None, 1)
@@ -138,27 +141,27 @@
self.obj_db = obj_db
def classifyObject(self, obj, oid):
- event = SerializationEvent(self.obj_db, None, oid, obj)
+ event = SerializationEvent(self.conf, None, oid, self.obj_db, obj)
# Returns (classification, mapper_name)
return self.conf.classifier.classifyObject(event)
def serialize(self, oid, obj):
classification, mapper_name = self.classifyObject(obj, oid)
- ser = self.conf.mappers[mapper_name].serializer
- event = SerializationEvent(self.obj_db, mapper, oid, obj)
- state = ser.serialize(event)
+ mapper = self.conf.mappers[mapper_name]
+ event = SerializationEvent(self.conf, mapper, oid, self.obj_db, obj)
+ state = mapper.serializer.serialize(event)
cs = ClassifiedState(state, classification, mapper_name)
return event, cs
def deserialize(self, oid, obj, classified_state):
- ser = self.conf.mappers[classified_state.mapper_name].serializer
- event = DeserializationEvent(self.obj_db, mapper, keychain, obj)
- ser.deserialize(obj, event, classified_state.state)
+ mapper = self.conf.mappers[classified_state.mapper_name]
+ event = DeserializationEvent(self.conf, mapper, oid, self.obj_db, obj)
+ mapper.serializer.deserialize(obj, event, classified_state.state)
return event
def newObject(self, classified_state):
- ser = self.conf.mappers[classified_state.mapper_name].serializer
- return ser.createEmptyInstance(
+ mapper = self.conf.mappers[classified_state.mapper_name]
+ return mapper.serializer.createEmptyInstance(
self.obj_db, classification=classified_state.classification)
=== Products/Ape/lib/apelib/core/schemas.py 1.4.4.1 => 1.4.4.2 ===
--- Products/Ape/lib/apelib/core/schemas.py:1.4.4.1 Sat Dec 13 23:24:46 2003
+++ Products/Ape/lib/apelib/core/schemas.py Wed Dec 17 23:43:53 2003
@@ -19,7 +19,7 @@
from types import StringType
ok_types = ['unicode', 'string', 'int', 'float', 'bool', 'object',
- 'classification', 'keychain', 'string:list', 'blob']
+ 'classification', 'string:list', 'blob']
def addFieldType(t):
More information about the Zope-CVS
mailing list