[Zope-CVS] CVS: Products/AdaptableStorage/mapper - FieldSchema.py:1.1.2.1 MapperEvent.py:1.1.2.1 ObjectMapper.py:1.1.2.1 SerializationEvent.py:1.1.2.2 exceptions.py:1.1.2.1 public.py:1.1.2.1

Christian Zagrodnick cz@gocept.com
Mon, 13 Jan 2003 14:18:10 -0500


Update of /cvs-repository/Products/AdaptableStorage/mapper
In directory cvs.zope.org:/tmp/cvs-serv19385

Modified Files:
      Tag: zagy-patches
	FieldSchema.py MapperEvent.py ObjectMapper.py 
	SerializationEvent.py exceptions.py public.py 
Log Message:
merging HEAD into zagy-patches branch

=== Products/AdaptableStorage/mapper/FieldSchema.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper/FieldSchema.py:1.1	Tue Dec 31 16:47:46 2002
+++ Products/AdaptableStorage/mapper/FieldSchema.py	Mon Jan 13 14:17:38 2003
@@ -16,12 +16,19 @@
 $Id$
 """
 
+from types import StringType
+
 from interfaces.public import ISchema
 
-# ok_types just constrains the possible types until we figure out
-# what we really want to do here.
-ok_types = ('unicode', 'string', 'int', 'float', 'bool', 'object',
-            'classification', 'keychain')
+ok_types = ['unicode', 'string', 'int', 'float', 'bool', 'object',
+            'classification', 'keychain', 'string:list']
+
+
+def addFieldType(t):
+    """Adds an allowable field type."""
+    assert isinstance(t, StringType)
+    if t not in ok_types:
+        ok_types.append(t)
 
 
 class FieldSchema:


=== Products/AdaptableStorage/mapper/MapperEvent.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper/MapperEvent.py:1.1	Tue Dec 31 16:47:46 2002
+++ Products/AdaptableStorage/mapper/MapperEvent.py	Mon Jan 13 14:17:38 2003
@@ -16,7 +16,8 @@
 $Id$
 """
 
-from interfaces.public import IMapperEvent
+from interfaces.public import IMapperEvent, ILoadEvent, IStoreEvent
+
 
 class MapperEvent:
 
@@ -39,4 +40,16 @@
     def makeKeychain(self, name, stored):
         kcg = self.getObjectMapper().getKeychainGenerator()
         return kcg.makeKeychain(self, name, stored)
+
+
+class LoadEvent (MapperEvent):
+    """Object loading event."""
+
+    __implements__ = ILoadEvent
+
+
+class StoreEvent (MapperEvent):
+    """Object storing event."""
+
+    __implements__ = IStoreEvent
 


=== Products/AdaptableStorage/mapper/ObjectMapper.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper/ObjectMapper.py:1.1	Tue Dec 31 16:47:46 2002
+++ Products/AdaptableStorage/mapper/ObjectMapper.py	Mon Jan 13 14:17:38 2003
@@ -65,24 +65,24 @@
         self._sub_mappers[name] = m
         return m
 
-    def checkConfiguration(self, names=(), recursive=1):
+    def checkConfiguration(self, path='root', recursive=1):
         s = self._serializer
         if s is None:
             raise RuntimeError(
-                'No serializer configured for mapper %s' % repr(names))
+                'No serializer configured for mapper %s' % repr(path))
         if not IObjectSerializer.isImplementedBy(s):
             raise RuntimeError(
                 'Not an IObjectSerializer: %s' % repr(s))
         g = self._gateway
         if g is None:
             raise RuntimeError(
-                'No gateway configured for mapper %s' % repr(names))
+                'No gateway configured for mapper %s' % repr(path))
         if not IGateway.isImplementedBy(g):
             raise RuntimeError(
                 'Not an IGateway: %s' % repr(g))
         if s.getSchema() != g.getSchema():
             raise RuntimeError('Mismatched schemas in mapper %s: %s != %s' % (
-                repr(names), s.getSchema(), g.getSchema()))
+                repr(path), s.getSchema(), g.getSchema()))
         if self._parent is None:
             if self._classifier is None:
                 raise RuntimeError('No root classifier configured')
@@ -100,8 +100,8 @@
                     'Not an IObjectMapper: %s' % repr(self._parent))
 
         if recursive:
-            for name, m in self._sub_mappers.items():
-                m.checkConfiguration((names + (name,)), recursive)
+            for n, m in self._sub_mappers.items():
+                m.checkConfiguration(('%s/%s' % (path, n)), recursive)
 
     # IObjectMapper implementation
 


=== Products/AdaptableStorage/mapper/SerializationEvent.py 1.1.2.1 => 1.1.2.2 ===
--- Products/AdaptableStorage/mapper/SerializationEvent.py:1.1.2.1	Sat Jan  4 14:06:39 2003
+++ Products/AdaptableStorage/mapper/SerializationEvent.py	Mon Jan 13 14:17:38 2003
@@ -56,13 +56,13 @@
     def notifySerialized(self, name, value, is_attribute):
         """See the ISerializationEvent interface."""
         assert self._aspect_name is not None
-        isSimple = 0
-        try:
-            if value in SIMPLE_IMMUTABLE_OBJECTS:
-                isSimple = 1
-        except UnicodeError:
-            pass
-        if not isSimple:
+        for ob in SIMPLE_IMMUTABLE_OBJECTS:
+            # If value is a simple immutable object, don't make a
+            # reference to it.  Compare by identity rather than
+            # equality, otherwise rich comparison leads to surprises.
+            if value is ob:
+                break
+        else:
             # Make internal references only for mutable or complex objects.
             idx = id(value)
             if not self._internal_refs.has_key(idx):


=== Products/AdaptableStorage/mapper/exceptions.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper/exceptions.py:1.1	Tue Dec 31 16:47:46 2002
+++ Products/AdaptableStorage/mapper/exceptions.py	Mon Jan 13 14:17:38 2003
@@ -16,9 +16,15 @@
 $Id$
 """
 
-class SerializationError(Exception):
+class MappingError(Exception):
+    """Object mapping exception"""
+
+class SerializationError(MappingError):
     """Error during serialization"""
 
-class DeserializationError(Exception):
+class DeserializationError(MappingError):
     """Error during deserialization"""
+
+class NoStateFoundError(MappingError):
+    """No state is there to load"""
 


=== Products/AdaptableStorage/mapper/public.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/mapper/public.py:1.1	Tue Dec 31 16:47:46 2002
+++ Products/AdaptableStorage/mapper/public.py	Mon Jan 13 14:17:38 2003
@@ -20,10 +20,10 @@
 from exceptions import *
 
 from DeserializationEvent import DeserializationEvent
-from MapperEvent import MapperEvent
+from MapperEvent import MapperEvent, LoadEvent, StoreEvent
 from ObjectGateway import ObjectGateway
 from ObjectMapper import ObjectMapper
 from ObjectSerializer import ObjectSerializer
-from FieldSchema import FieldSchema, RowSchema, RowSequenceSchema
+from FieldSchema import FieldSchema, RowSchema, RowSequenceSchema, addFieldType
 from SerializationEvent import SerializationEvent