[Zope-CVS] CVS: Products/Ape/lib/apelib/core - classifiers.py:1.3
events.py:1.8 interfaces.py:1.11 io.py:1.8
Shane Hathaway
shane at zope.com
Tue Feb 17 00:25:42 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/core
In directory cvs.zope.org:/tmp/cvs-serv17338/lib/apelib/core
Modified Files:
classifiers.py events.py interfaces.py io.py
Log Message:
Another big pile of changes resulted from a little time. :-)
>From CHANGES.txt:
- Removed the concepts of "classified state" and "hints", now
relying on the existing concepts of classification and state. This
primarily involved changes to classifiers and the apelib.core.io
module.
- Implemented the folder item classification optimization. Now,
when Ape loads a folder, it passes along the classification of each
subitem as part of the containing folder's state. This means fewer
round-trips.
Also fixed a couple of shallow bugs that prevented Ape from starting in
Zope.
=== Products/Ape/lib/apelib/core/classifiers.py 1.2 => 1.3 ===
--- Products/Ape/lib/apelib/core/classifiers.py:1.2 Mon Feb 2 10:07:18 2004
+++ Products/Ape/lib/apelib/core/classifiers.py Tue Feb 17 00:25:11 2004
@@ -44,11 +44,11 @@
c = event.obj.__class__
class_name = "%s.%s" % (c.__module__, c.__name__)
mapper_name = self._class_to_mapper[class_name]
- return ({"class_name": class_name}, mapper_name)
+ return {"class_name": class_name, "mapper_name": mapper_name}
def classifyState(self, event):
classification, serial = self.gateway.load(event)
class_name = classification["class_name"]
mapper_name = self._class_to_mapper[class_name]
- return ({"class_name": class_name}, mapper_name)
+ return {"class_name": class_name, "mapper_name": mapper_name}
=== Products/Ape/lib/apelib/core/events.py 1.7 => 1.8 ===
--- Products/Ape/lib/apelib/core/events.py:1.7 Mon Feb 2 10:07:18 2004
+++ Products/Ape/lib/apelib/core/events.py Tue Feb 17 00:25:11 2004
@@ -62,6 +62,10 @@
"""
__implements__ = interfaces.ILoadEvent
+ def classify(self, oid):
+ sub_event = LoadEvent(self.conf, None, oid, self.connections, None)
+ return self.conf.classifier.classifyState(sub_event)
+
class StoreEvent (GatewayEvent):
"""Object storing event.
@@ -104,10 +108,10 @@
def deserialized(self, name, value):
self._loaded_refs['%s:%s' % (self.serializer_name, name)] = value
- def resolve(self, name, oid, hints=None):
+ def resolve(self, name, oid, classification=None):
"""Retrieves a referenced subobject (usually ghosted initially).
"""
- ob = self.obj_db.getObject(oid, hints)
+ ob = self.obj_db.getObject(oid, classification)
self.external.append((oid, ob))
self.deserialized(name, ob)
return ob
=== Products/Ape/lib/apelib/core/interfaces.py 1.10 => 1.11 ===
--- Products/Ape/lib/apelib/core/interfaces.py:1.10 Mon Feb 2 10:07:18 2004
+++ Products/Ape/lib/apelib/core/interfaces.py Tue Feb 17 00:25:11 2004
@@ -62,18 +62,13 @@
an IObjectDatabase.
"""
- def getObject(oid, hints=None):
+ def getObject(oid, classification=None):
"""Returns a class instance, possibly ghosted.
Used during deserialization (loading/import).
- The hints argument, a mapping, may be provided as an
+ The classification argument, a mapping, may be provided as an
optimization. Without it, implementations of this method may
have to load a full object rather than a ghosted object.
-
- Some hints may be:
-
- classification
- mapper_name
"""
def identify(obj):
@@ -135,6 +130,10 @@
class ILoadEvent (IGatewayEvent):
"""Interface for events involved in loading objects."""
+ def classify(oid):
+ """Returns the classification of the referenced object.
+ """
+
class IStoreEvent (IGatewayEvent):
"""Interface for events involved in storing objects."""
@@ -187,7 +186,7 @@
this method.
"""
- def resolve(name, oid, hints=None):
+ def resolve(name, oid, classification=None):
"""Returns the object identified by an inter-record reference.
The object should have been stored earlier through a call to
@@ -382,17 +381,17 @@
""")
def classifyObject(event):
- """Returns a classification and mapper_name.
+ """Returns a classification with at least a mapper_name.
- event is an ISerializationEvent without a mapper (since this
- method chooses the mapper).
+ event is an ILoadEvent without a mapper or classification
+ (since this method chooses them).
"""
def classifyState(event):
- """Returns a classification and mapper_name.
+ """Returns a classification with at least a mapper_name.
- event is an ILoadEvent without a mapper (since this method
- chooses the mapper).
+ event is an ILoadEvent without a mapper or classification
+ (since this method chooses them).
May load the classification from storage by calling
self.gateway.load().
@@ -447,8 +446,7 @@
def new_oid(event, name, stored):
"""Returns a new oid.
- event is an IMapperEvent. Additionally, it is always either
- an ISDEvent or an IGatewayEvent.
+ event is an ISDEvent or IGatewayEvent.
name is the name of the subobject.
=== Products/Ape/lib/apelib/core/io.py 1.7 => 1.8 ===
--- Products/Ape/lib/apelib/core/io.py:1.7 Mon Feb 2 10:07:18 2004
+++ Products/Ape/lib/apelib/core/io.py Tue Feb 17 00:25:11 2004
@@ -26,15 +26,6 @@
from interfaces import IMapperConfiguration, ITPCConnection, IObjectDatabase
-class ClassifiedState:
- """Object state with classification information."""
-
- def __init__(self, state, classification, mapper_name):
- self.state = state
- self.classification = classification
- self.mapper_name = mapper_name
-
-
class GatewayIO:
"""Gateway operations facade."""
@@ -96,30 +87,31 @@
def classifyState(self, oid):
event = LoadEvent(self.conf, None, oid, self.conn_map, None)
- # Return (classification, mapper_name)
+ # Returns classification
return self.conf.classifier.classifyState(event)
def load(self, oid):
- classification, mapper_name = self.classifyState(oid)
+ classification = self.classifyState(oid)
+ mapper_name = classification['mapper_name']
mapper = self.conf.mappers[mapper_name]
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
+ return event, classification, state, hash_value
- def store(self, oid, classified_state, is_new):
- mapper = self.conf.mappers[classified_state.mapper_name]
+ def store(self, oid, classification, state, is_new):
+ mapper_name = classification['mapper_name']
+ mapper = self.conf.mappers[mapper_name]
event = StoreEvent(self.conf, mapper, oid, self.conn_map,
- classified_state.classification, is_new)
+ classification, is_new)
# Store the classification first
- self.conf.classifier.gateway.store(
- event, classified_state.classification)
+ self.conf.classifier.gateway.store(event, classification)
# Store the state second
- new_hash = mapper.gateway.store(event, classified_state.state)
+ new_hash = mapper.gateway.store(event, state)
return event, new_hash
def getPollSources(self, oid):
- classification, mapper_name = self.classifyState(oid)
+ classification = self.classifyState(oid)
+ mapper_name = classification['mapper_name']
mapper = self.conf.mappers[mapper_name]
event = LoadEvent(self.conf, mapper, oid, self.conn_map, classification)
return mapper.gateway.getPollSources(event)
@@ -141,27 +133,29 @@
def classifyObject(self, obj, oid):
event = SerializationEvent(self.conf, None, oid, self.obj_db, obj)
- # Returns (classification, mapper_name)
+ # Returns classification
return self.conf.classifier.classifyObject(event)
def serialize(self, oid, obj):
- classification, mapper_name = self.classifyObject(obj, oid)
+ classification = self.classifyObject(obj, oid)
+ mapper_name = classification['mapper_name']
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
+ return event, classification, state
- def deserialize(self, oid, obj, classified_state):
- mapper = self.conf.mappers[classified_state.mapper_name]
+ def deserialize(self, oid, obj, classification, state):
+ mapper_name = classification['mapper_name']
+ mapper = self.conf.mappers[mapper_name]
event = DeserializationEvent(self.conf, mapper, oid, self.obj_db, obj)
- mapper.serializer.deserialize(event, classified_state.state)
+ mapper.serializer.deserialize(event, state)
return event
- def newObject(self, classified_state):
- mapper = self.conf.mappers[classified_state.mapper_name]
+ def newObject(self, classification):
+ mapper_name = classification['mapper_name']
+ mapper = self.conf.mappers[mapper_name]
return mapper.serializer.createEmptyInstance(
- self.obj_db, classification=classified_state.classification)
+ self.obj_db, classification=classification)
@@ -216,11 +210,11 @@
todo = [(dest_oid, src_obj)]
while todo:
oid, obj = todo.pop()
- event, classified_state = self.obj_io.serialize(oid, obj)
+ event, classification, state = self.obj_io.serialize(oid, obj)
count += 1
if deactivate_func is not None:
deactivate_func(obj, count)
- self.gw_io.store(oid, classified_state, False)
+ self.gw_io.store(oid, classification, state, False)
ext_refs = event.external
if ext_refs:
for ext_oid, ext_obj in ext_refs:
@@ -238,8 +232,8 @@
todo = [(src_oid, dest_obj)]
while todo:
oid, obj = todo.pop()
- e, classified_state, hash_value = self.gw_io.load(oid)
- event = self.obj_io.deserialize(oid, obj, classified_state)
+ e, classification, state, hash_value = self.gw_io.load(oid)
+ event = self.obj_io.deserialize(oid, obj, classification, state)
if self._incomplete.has_key(oid):
del self._incomplete[oid]
count += 1
@@ -264,14 +258,14 @@
m = __import__(module, {}, {}, ('__doc__',))
return getattr(m, name)
- def getObject(self, oid, hints=None):
+ def getObject(self, oid, classification=None):
# Should be called only while importing
try:
return self._objects[oid]
except KeyError:
# This object has not been loaded yet. Make a stub.
- e, classified_state, hash_value = self.gw_io.load(oid)
- obj = self.obj_io.newObject(classified_state)
+ e, classification, state, hash_value = self.gw_io.load(oid)
+ obj = self.obj_io.newObject(classification)
# Don't fill in the state yet, to avoid infinite
# recursion. Just register it.
self._incomplete[oid] = 1
More information about the Zope-CVS
mailing list