[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - classifier.py:1.5.2.1 ofsserial.py:1.5.2.1 scripts.py:1.3.6.1 security.py:1.3.6.1 fsmapper.py:NONE sqlmapper.py:NONE

Shane Hathaway shane at zope.com
Fri Dec 19 21:52:51 EST 2003


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

Modified Files:
      Tag: ape-0_8-branch
	classifier.py ofsserial.py scripts.py security.py 
Removed Files:
      Tag: ape-0_8-branch
	fsmapper.py sqlmapper.py 
Log Message:
Cleaned up to the point that ApelibImplTests pass.


=== Products/Ape/lib/apelib/zope2/classifier.py 1.5 => 1.5.2.1 ===
--- Products/Ape/lib/apelib/zope2/classifier.py:1.5	Wed Jul 30 18:11:42 2003
+++ Products/Ape/lib/apelib/zope2/classifier.py	Fri Dec 19 21:52:50 2003
@@ -22,7 +22,7 @@
 from OFS.ObjectManager import ObjectManager
 
 from apelib.core.interfaces import IConfigurableClassifier
-from apelib.core.exceptions import SerializationError, DeserializationError
+from apelib.core.interfaces import SerializationError, DeserializationError
 
 # guess_extension() is useful, but it's unoptimized and sometimes
 # chooses strange extensions.  fixed_extensions does nothing other than
@@ -78,7 +78,7 @@
         self.options[(mapper_name, option)] = value
             
 
-    def classifyObject(self, value, keychain):
+    def classifyObject(self, event):
         """Chooses a mapper and classification for storing an object."""
         mapper_name = self.key_to_mapper.get(keychain[-1])
         if mapper_name is not None:


=== Products/Ape/lib/apelib/zope2/ofsserial.py 1.5 => 1.5.2.1 ===
--- Products/Ape/lib/apelib/zope2/ofsserial.py:1.5	Wed Jul 30 18:11:42 2003
+++ Products/Ape/lib/apelib/zope2/ofsserial.py	Fri Dec 19 21:52:50 2003
@@ -25,9 +25,8 @@
 from OFS.Image import File
 from OFS.PropertyManager import PropertyManager
 
-from apelib.core.interfaces import ISerializer
+from apelib.core.interfaces import ISerializer, SerializationError
 from apelib.core.schemas import FieldSchema, RowSequenceSchema
-from apelib.core.exceptions import SerializationError
 from apelib.core.serializers import OptionalSerializer
 from apelib.zodb3.gateways import ReadOnlyItems
 
@@ -53,30 +52,27 @@
 
     schema = FieldSchema('data', 'string')
 
-    def getSchema(self):
-        return self.schema
-
     def canSerialize(self, object):
         return isinstance(object, File)
 
-    def serialize(self, object, event):
-        event.notifySerialized('data', object.data, 1)
-        event.ignoreAttribute('size')
-        event.ignoreAttribute('width')
-        event.ignoreAttribute('height')
-        return str(object.data)
-
-    def deserialize(self, object, event, state):
-        data, size = object._read_data(state)
-        if not object.__dict__.get('content_type'):
+    def serialize(self, event):
+        obj = event.obj
+        event.serialized('data', obj.data, 1)
+        event.ignore(('size', 'width', 'height'))
+        return str(obj.data)
+
+    def deserialize(self, event, state):
+        obj = event.obj
+        data, size = obj._read_data(state)
+        if not obj.__dict__.get('content_type'):
             # Guess the content type.
-            content_type = object._get_content_type(
-                state, data, object.__name__)
+            content_type = obj._get_content_type(
+                state, data, obj.__name__)
         else:
             # The properties serializer is authoritative.  Defer to it.
             content_type = None
-        object.update_data(data, content_type, size)
-        event.notifyDeserialized('data', object.data)
+        obj.update_data(data, content_type, size)
+        event.seserialized('data', obj.data)
 
 
 class FolderItems:
@@ -86,7 +82,7 @@
 
     schema = RowSequenceSchema()
     schema.addField('id', 'string', 1)
-    schema.addField('keychain', 'keychain')
+    schema.addField('oid', 'string')
 
     # The fixed_oids flag must be turned on when serializing to
     # an object system with meaningful OIDs (like the filesystem.)
@@ -94,43 +90,42 @@
     # OIDs such as SQL databases.
     fixed_oids = 1
 
-    def getSchema(self):
-        return self.schema
-
     def canSerialize(self, obj):
         return isinstance(obj, ObjectManager)
 
-    def serialize(self, obj, event):
+    def serialize(self, event):
+        obj = event.obj
         assert isinstance(obj, ObjectManager), repr(obj)
         state = []
-        event.ignoreAttribute('_objects')
+        event.ignore('_objects')
         mps = getattr(obj, '_mount_points', None)
         for id, subob in obj.objectItems():
             if mps and mps.has_key(id):
                 # Store the mount point rather than the mounted object.
                 subob = mps[id]
             base = aq_base(subob)
-            keychain = event.identifyObject(base)
-            if keychain is None:
-                keychain = event.makeKeychain(id, 1)
-            event.notifySerializedRef(id, base, 1, keychain)
-            state.append((id, keychain))
+            oid = event.obj_db.identify(base)
+            if oid is None:
+                oid = event.conf.oid_gen.new_oid(event, id, True)
+            event.referenced(id, base, True, oid)
+            state.append((id, oid))
         if self.fixed_oids:
-            event.ignoreAttribute('_use_fixed_oids_')
+            event.ignore('_use_fixed_oids_')
             # Add a marker that tells the folder it has to move/rename
             # in a special way.  The _setOb patch sees this attribute.
             obj._use_fixed_oids_ = 1
         return state
 
-    def deserialize(self, obj, event, state):
+    def deserialize(self, event, state):
+        obj = event.obj
         assert isinstance(obj, ObjectManager)
         if self.fixed_oids:
             obj._use_fixed_oids_ = 1
-        for (id, keychain) in state:
-            subob = event.dereference(id, keychain)
+        for (id, oid) in state:
+            subob = event.resolve(id, oid)
             setattr(obj, id, subob)
             obj._objects += ({'id': id, 'meta_type':
-                                 subob.__class__.meta_type},)
+                              subob.__class__.meta_type},)
 
 
 
@@ -141,31 +136,30 @@
 
     schema = FieldSchema('id', 'string')
 
-    def getSchema(self):
-        return self.schema
-
-    def canSerialize(self, object):
+    def canSerialize(self, obj):
         return 1
 
-    def getAttrNameFor(self, object):
-        if isinstance(object, Item_w__name__):
+    def getAttrNameFor(self, obj):
+        if isinstance(obj, Item_w__name__):
             return '__name__'
         else:
             return 'id'
 
-    def serialize(self, object, event):
-        attrname = self.getAttrNameFor(object)
-        id = getattr(object, attrname)
-        assert id, 'ID of %r is %r' % (object, id)
-        event.notifySerialized(attrname, id, 1)
+    def serialize(self, event):
+        obj = event.obj
+        attrname = self.getAttrNameFor(obj)
+        id = getattr(obj, attrname)
+        assert id, 'ID of %r is %r' % (obj, id)
+        event.serialized(attrname, id, 1)
         return id
 
-    def deserialize(self, object, event, state):
-        attrname = self.getAttrNameFor(object)
-        setattr(object, attrname, state)
+    def deserialize(self, event, state):
+        obj = event.obj
+        attrname = self.getAttrNameFor(obj)
+        setattr(obj, attrname, state)
         # Allow references under either attribute name.
-        event.notifyDeserialized('id', state)
-        event.notifyDeserialized('__name__', state)
+        event.deserialized('id', state)
+        event.deserialized('__name__', state)
 
 
 
@@ -179,22 +173,20 @@
     schema.addField('type', 'string')
     schema.addField('data', 'string')
 
-    def getSchema(self):
-        return self.schema
-
-    def canSerialize(self, object):
-        return isinstance(object, PropertyManager)
+    def canSerialize(self, obj):
+        return isinstance(obj, PropertyManager)
 
-    def serialize(self, object, event):
+    def serialize(self, event):
         res = []
-        assert isinstance(object, PropertyManager), repr(object)
-        assert object._properties is object._propertyMap()
+        obj = event.obj
+        assert isinstance(obj, PropertyManager), repr(obj)
+        assert obj._properties is obj._propertyMap()
         event.ignoreAttribute('_properties')
-        for p in object._properties:
+        for p in obj._properties:
             name = p['id']
             t = p['type']
             event.ignoreAttribute(name)
-            data = object.getProperty(name)
+            data = obj.getProperty(name)
             if t == 'lines':
                 v = '\n'.join(data)
             elif string_repr_types.get(t):
@@ -212,17 +204,18 @@
             res.append((name, t, v))
         return res
 
-    def deserialize(self, object, event, state):
-        assert isinstance(object, PropertyManager)
-        assert object._properties is object._propertyMap()
+    def deserialize(self, event, state):
+        obj = event.obj
+        assert isinstance(obj, PropertyManager)
+        assert obj._properties is obj._propertyMap()
         if not state:
             # No stored properties.  Revert the object to its
             # class-defined property schema.
-            if object.__dict__.has_key('_properties'):
-                del object._properties
+            if obj.__dict__.has_key('_properties'):
+                del obj._properties
             return
 
-        old_props = object.propdict()
+        old_props = obj.propdict()
         new_props = {}
         for id, t, v in state:
             p = old_props.get(id)
@@ -244,7 +237,7 @@
             new_props[id] = p
 
         if old_props != new_props:
-            object._properties = tuple(new_props.values())
+            obj._properties = tuple(new_props.values())
 
         for id, t, v in state:
             if t == 'lines':
@@ -268,11 +261,12 @@
             else:
                 # Fall back to a default.
                 data = ''
-            object._updateProperty(id, data)
+            obj._updateProperty(id, data)
 
 
 class ReadOnlyRoot(ReadOnlyItems):
-    """Zope 2 application root."""
+    """Zope 2 application root.
+    """
 
     def __init__(self, root_key):
         try:


=== Products/Ape/lib/apelib/zope2/scripts.py 1.3 => 1.3.6.1 ===
--- Products/Ape/lib/apelib/zope2/scripts.py:1.3	Fri Apr 11 23:39:38 2003
+++ Products/Ape/lib/apelib/zope2/scripts.py	Fri Dec 19 21:52:50 2003
@@ -43,17 +43,14 @@
 
     schema = FieldSchema('data', 'string')
 
-    def getSchema(self):
-        return self.schema
+    def canSerialize(self, obj):
+        return isinstance(obj, PythonScript)
 
-    def canSerialize(self, object):
-        return isinstance(object, PythonScript)
-
-    def serialize(self, object, event):
-        assert isinstance(object, PythonScript)
-        data = object.read()
+    def serialize(self, event):
+        assert isinstance(event.obj, PythonScript)
+        data = event.obj.read()
         assert isinstance(data, StringType)
-        event.ignoreAttributes((
+        event.ignore((
             'title', '_params', '_body', '_bind_names',
             'warnings', 'errors', '_code', 'Python_magic', 
             'Script_magic', 'func_defaults', 'func_code', 
@@ -61,17 +58,18 @@
             ))
         return data
 
-    def deserialize(self, object, event, state):
+    def deserialize(self, event, state):
+        obj = event.obj
         assert isinstance(state, StringType)
-        assert isinstance(object, PythonScript)
+        assert isinstance(event.obj, PythonScript)
         # Circumvent proxy role checking while deserializing the script.
-        object._validateProxy = lambda: 0
+        obj._validateProxy = lambda: 0
         try:
-            object.write(state) 
-            object._makeFunction()
+            obj.write(state) 
+            obj._makeFunction()
         finally:
             # Remove the proxy circumvention
-            del object._validateProxy
+            del obj._validateProxy
 
 
 
@@ -89,34 +87,32 @@
 
     params_re = re.compile(r'\s*<params>(.*)</params>\s*\n', re.I | re.S)
 
-    def getSchema(self):
-        return self.schema
-
-    def canSerialize(self, object):
-        return isinstance(object, SQL)
+    def canSerialize(self, obj):
+        return isinstance(obj, SQL)
 
-    def serialize(self, object, event):
-        data = object.document_src()
-        event.ignoreAttributes(('_arg', 'template', 'arguments_src', 'src'))
+    def serialize(self, event):
+        data = event.obj.document_src()
+        event.ignore(('_arg', 'template', 'arguments_src', 'src'))
         return data
 
-    def deserialize(self, object, event, state):
+    def deserialize(self, event, state):
+        obj = event.obj
         assert isinstance(state, StringType)
-        assert isinstance(object, SQL)
+        assert isinstance(obj, SQL)
         body = state
         m = self.params_re.match(body)
         if m:
-            object.arguments_src = m.group(1)
+            obj.arguments_src = m.group(1)
             body = body[m.end():]
         else:
-            object.arguments_src = ''
-        object._arg = parse(object.arguments_src)
-        object.src = body
-        object.template = object.template_class(body)
-        object.template.cook()
-        object._v_cache = ({}, Bucket())
-        if not hasattr(object, 'connection_id'):
-            object.connection_id = ''
+            obj.arguments_src = ''
+        obj._arg = parse(obj.arguments_src)
+        obj.src = body
+        obj.template = obj.template_class(body)
+        obj.template.cook()
+        obj._v_cache = ({}, Bucket())
+        if not hasattr(obj, 'connection_id'):
+            obj.connection_id = ''
 
 
 class ZSQLMethodPropertiesSerializer:
@@ -140,19 +136,17 @@
         'connection_hook': str, 
     }
 
-    def getSchema(self):
-        return self.schema
-
-    def canSerialize(self, object):
-        return isinstance(object, SQL)
+    def canSerialize(self, obj):
+        return isinstance(obj, SQL)
 
-    def serialize(self, object, event):
-        assert isinstance(object, SQL)
+    def serialize(self, event):
+        obj = event.obj
+        assert isinstance(obj, SQL)
         res = []
         for attribute, factory in self.attributes.items():
-            if not hasattr(object, attribute):
+            if not hasattr(obj, attribute):
                 continue
-            value = getattr(object, attribute)
+            value = getattr(obj, attribute)
             t = factory.__name__
             if value is None:
                 if factory in (int, long):
@@ -160,20 +154,21 @@
                 else: 
                     value = ''
             value = str(value)
-            event.notifySerialized(attribute, value, 1)
+            event.serialized(attribute, value, 1)
             res.append((attribute, t, value))
-        event.ignoreAttribute('_col') 
+        event.ignore('_col') 
         return res 
 
-    def deserialize(self, object, event, state):
-        assert isinstance(object, SQL)
+    def deserialize(self, event, state):
+        obj = event.obj
+        assert isinstance(obj, SQL)
         for attribute, t, value in state:
             factory = self.attributes.get(attribute)
             if factory is None:
                 continue
             value = factory(value)
-            setattr(object, attribute, value)
-            event.notifyDeserialized(attribute, value)
-        if not hasattr(object, 'connection_id'):
-            object.connection_id = ''
+            setattr(obj, attribute, value)
+            event.deserialized(attribute, value)
+        if not hasattr(obj, 'connection_id'):
+            obj.connection_id = ''
 


=== Products/Ape/lib/apelib/zope2/security.py 1.3 => 1.3.6.1 ===
--- Products/Ape/lib/apelib/zope2/security.py:1.3	Mon Apr 14 04:22:19 2003
+++ Products/Ape/lib/apelib/zope2/security.py	Fri Dec 19 21:52:50 2003
@@ -81,18 +81,16 @@
     schema.addField('permission', 'string')
     schema.addField('username', 'string')
 
-    def getSchema(self):
-        return self.schema
-
     def canSerialize(self, obj):
         return 1
 
-    def serialize(self, obj, event):
+    def serialize(self, event):
         res = []
 
+        obj = event.obj
         eo = getattr(obj, '_owner', None)
         if eo is not None:
-            event.ignoreAttribute('_owner')
+            event.ignore('_owner')
             path, username = eo
             if '/' in username:
                 raise ValueError, '/ not allowed in user names'
@@ -101,21 +99,21 @@
 
         roles = getattr(obj, '__ac_roles__', None)
         if roles is not None:
-            event.ignoreAttribute('__ac_roles__')
+            event.ignore('__ac_roles__')
             for role in roles:
                 if not STANDARD_ROLES.has_key(role):
                     res.append(('define-role', role, '', ''))
 
         local_roles = getattr(obj, '__ac_local_roles__', None)
         if local_roles is not None:
-            event.ignoreAttribute('__ac_local_roles__')
+            event.ignore('__ac_local_roles__')
             for username, roles in local_roles.items():
                 for role in roles:
                     res.append(('local-role', role, '', username))
 
         proxy_roles = getattr(obj, '_proxy_roles', None)
         if proxy_roles is not None:
-            event.ignoreAttribute('_proxy_roles')
+            event.ignore('_proxy_roles')
             for role in proxy_roles:
                 res.append(('proxy-role', role, '', ''))
 
@@ -126,7 +124,7 @@
                     p_dict = getPermissionDict()
                 p = p_dict.get(attr)
                 if p is not None:
-                    event.ignoreAttribute(attr)
+                    event.ignore(attr)
                     for role in value:
                         res.append(('permission-role', role, p, ''))
                     # List means acquired, tuple means not acquired.
@@ -136,13 +134,14 @@
         return res
         
 
-    def deserialize(self, obj, event, state):
+    def deserialize(self, event, state):
         local_roles = {}       # { username -> [role,] }
         defined_roles = []     # [role,]
         proxy_roles = []       # [role,]
         permission_roles = {}  # { permission -> [role,] }
         permission_acquired = {}  # { permission -> 0 or 1 }
 
+        obj = event.obj
         for decl_type, role, permission, username in state:
             if decl_type == 'executable-owner':
                 assert not role
@@ -233,33 +232,32 @@
     schema.addField('roles', 'string:list')
     schema.addField('domains', 'string:list')
 
-    def getSchema(self):
-        return self.schema
-
-    def canSerialize(self, object):
-        return isinstance(object, UserFolder)
+    def canSerialize(self, obj):
+        return isinstance(obj, UserFolder)
 
-    def serialize(self, object, event):
-        assert isinstance(object, UserFolder), repr(object)
+    def serialize(self, event):
+        obj = event.obj
+        assert isinstance(obj, UserFolder), repr(obj)
         state = []
-        event.ignoreAttribute('data')
-        for id, user in object.data.items():
+        event.ignore('data')
+        for id, user in obj.data.items():
             assert isinstance(user, User), repr(user)
             assert len(user.__dict__.keys()) == 4, user.__dict__.keys()
             state.append((id, user.__,
                           tuple(user.roles), tuple(user.domains)))
-            event.notifySerialized(id, user, 0)
-        event.addUnmanagedPersistentObjects([object.data])
-        event.addUnmanagedPersistentObjects(object.data.values())
+            event.serialized(id, user, 0)
+        event.upos.append(obj.data)
+        event.upos.extend(obj.data.values())
         return state
 
-    def deserialize(self, object, event, state):
-        assert isinstance(object, UserFolder)
-        object.data = PersistentMapping()
+    def deserialize(self, event, state):
+        obj = event.obj
+        assert isinstance(obj, UserFolder)
+        obj.data = PersistentMapping()
         for id, password, roles, domains in state:
             user = User(id, password, roles, domains)
-            object.data[id] = user
-            event.notifyDeserialized(id, user)
-        event.addUnmanagedPersistentObjects([object.data])
-        event.addUnmanagedPersistentObjects(object.data.values())
+            obj.data[id] = user
+            event.deserialized(id, user)
+        event.upos.append(obj.data)
+        event.upos.extend(obj.data.values())
 

=== Removed File Products/Ape/lib/apelib/zope2/fsmapper.py ===

=== Removed File Products/Ape/lib/apelib/zope2/sqlmapper.py ===




More information about the Zope-CVS mailing list