[Zope-CVS] CVS: Products/Ape/lib/apelib/core - events.py:1.6 interfaces.py:1.9 io.py:1.6

Shane Hathaway shane at zope.com
Sat Aug 9 12:17:08 EDT 2003


Update of /cvs-repository/Products/Ape/lib/apelib/core
In directory cvs.zope.org:/tmp/cvs-serv21364/core

Modified Files:
	events.py interfaces.py io.py 
Log Message:
Made classifications accessible to load and store events.

This is useful for allowing gateways to change behavior based on the class
of the instance being (de)serialized.  Gateways that expect a fixed class
schema will expect this.



=== Products/Ape/lib/apelib/core/events.py 1.5 => 1.6 ===
--- Products/Ape/lib/apelib/core/events.py:1.5	Wed Jul 30 17:32:59 2003
+++ Products/Ape/lib/apelib/core/events.py	Sat Aug  9 11:16:32 2003
@@ -76,13 +76,18 @@
 
     __implements__ = interfaces.IGatewayEvent
 
-    def __init__(self, mapper, keychain, connections):
+    def __init__(self, mapper, keychain, connections, classification):
         MapperEvent.__init__(self, mapper, keychain)
         self._connections = connections
+        self._classification = classification
 
     def getConnection(self, name):
         """Returns the named connection."""
         return self._connections[name]
+
+    def getClassification(self):
+        """Returns the innermost classification or None."""
+        return self._classification
 
 
 class LoadEvent (GatewayEvent):


=== Products/Ape/lib/apelib/core/interfaces.py 1.8 => 1.9 ===
--- Products/Ape/lib/apelib/core/interfaces.py:1.8	Wed Jul 30 17:32:59 2003
+++ Products/Ape/lib/apelib/core/interfaces.py	Sat Aug  9 11:16:32 2003
@@ -143,6 +143,15 @@
     def getConnection(name):
         """Returns the named connection."""
 
+    def getClassification():
+        """Returns the innermost classification (for reading only) or None.
+
+        The innermost classification is the classification of the last
+        key in the keychain.  During traversal of the first element of
+        a keychain, no classification has been determined yet, so this
+        method returns None.
+        """
+
 
 class ILoadEvent (IGatewayEvent):
     """Interface for events involved in loading objects."""


=== Products/Ape/lib/apelib/core/io.py 1.5 => 1.6 ===
--- Products/Ape/lib/apelib/core/io.py:1.5	Wed Jul 30 17:32:59 2003
+++ Products/Ape/lib/apelib/core/io.py	Sat Aug  9 11:16:32 2003
@@ -108,7 +108,7 @@
             k = keychain[:i + 1]
             cfr = mapper.getClassifier()
             assert cfr is not None, keychain
-            event = LoadEvent(mapper, k, self._conn_map)
+            event = LoadEvent(mapper, k, self._conn_map, classification)
             classification, sub_mapper_name = cfr.classifyState(event)
             mapper_names.append(sub_mapper_name)
             mapper = mapper.getSubMapper(sub_mapper_name)
@@ -117,37 +117,39 @@
 
     def load(self, keychain):
         classification, mapper_names, mapper = self.classifyState(keychain)
-        event = LoadEvent(mapper, keychain, self._conn_map)
+        event = LoadEvent(mapper, keychain, self._conn_map, classification)
         state, hash_value = mapper.getGateway().load(event)
         cs = ClassifiedState(state, classification, mapper_names)
         return event, cs, hash_value
 
 
     def store(self, keychain, classified_state):
-        assert len(keychain) == len(classified_state.mapper_names)
+        classification = classified_state.classification
+        mapper_names = classified_state.mapper_names
+        assert len(keychain) == len(mapper_names)
         mapper = self._root_mapper
         prev_mapper = mapper
-        for mapper_name in classified_state.mapper_names:
+        for mapper_name in mapper_names:
             prev_mapper = mapper
             mapper = mapper.getSubMapper(mapper_name)
         cfr = prev_mapper.getClassifier()
-        event = StoreEvent(mapper, keychain, self._conn_map)
+        event = StoreEvent(mapper, keychain, self._conn_map, classification)
         new_hash = mapper.getGateway().store(event, classified_state.state)
         if cfr is not None:
-            cfr.store(event, classified_state.classification)
+            cfr.store(event, classification)
         return event, new_hash
 
 
     def getSources(self, keychain):
         classification, mapper_names, mapper = self.classifyState(keychain)
-        event = LoadEvent(mapper, keychain, self._conn_map)
+        event = LoadEvent(mapper, keychain, self._conn_map, classification)
         return mapper.getGateway().getSources(event)
 
 
     def newKeychain(self):
         # Try to use the root keychain generator to make a keychain.
         kgen = self._root_mapper.getKeychainGenerator()
-        event = GatewayEvent(self._root_mapper, (), self._conn_map)
+        event = GatewayEvent(self._root_mapper, (), self._conn_map, None)
         return kgen.makeKeychain(event, None, 1)
 
 
@@ -210,6 +212,7 @@
         ser = mapper.getSerializer()
         return ser.createEmptyInstance(
             self._kos, classification=classified_state.classification)
+
 
 
 class ExportImport:




More information about the Zope-CVS mailing list