[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - ape.conf:1.2
apeconf.xml:1.4 classifier.py:1.6 mapper.py:1.3
ofsserial.py:1.6 scripts.py:1.4 security.py:1.4
fsmapper.py:NONE sqlmapper.py:NONE
Shane Hathaway
shane at zope.com
Mon Feb 2 10:07:54 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/zope2
In directory cvs.zope.org:/tmp/cvs-serv26672/lib/apelib/zope2
Modified Files:
apeconf.xml classifier.py mapper.py ofsserial.py scripts.py
security.py
Added Files:
ape.conf
Removed Files:
fsmapper.py sqlmapper.py
Log Message:
Moved ape-0_8-branch to the HEAD.
>From CHANGES.txt:
- Major restructuring to reduce the number of concepts in
Ape. Keychains and keys have been replaced with simple string OIDs.
There is now a flat namespace of mappers instead of a tree. Only
one classifier and one OID generator are used in any object
database.
- The ZODB root object is now stored on the filesystem.
=== Products/Ape/lib/apelib/zope2/ape.conf 1.1 => 1.2 ===
--- /dev/null Mon Feb 2 10:07:54 2004
+++ Products/Ape/lib/apelib/zope2/ape.conf Mon Feb 2 10:07:23 2004
@@ -0,0 +1,324 @@
+# This file specifies the basic Zope 2 configuration for Ape.
+
+# Classifier
+
+<classifier>
+ factory apelib.zope2.classifier.Classifier
+ <gateway [filesystem]>
+ factory apelib.fs.classification.FSClassificationSection
+ </gateway>
+ <gateway [sql]>
+ factory apelib.sql.classification.SQLClassification
+ </gateway>
+</classifier>
+
+
+# OID Generator
+
+<oid-generator [filesystem]>
+ factory apelib.core.oidgen.PathOIDGenerator
+</oid-generator>
+<oid-generator [sql]>
+ factory apelib.sql.oidgen.SQLOIDGenerator
+</oid-generator>
+
+
+# Root object mapper (the root object is a PersistentMapping.)
+
+<mapper root>
+ class Persistence.PersistentMapping
+ <serializer items>
+ factory apelib.zodb3.serializers.StringToPersistentPM
+ </serializer>
+ <gateway items[filesystem]>
+ factory apelib.fs.structure.RootDirectoryItems
+ </gateway>
+ <gateway items[sql]>
+ factory apelib.sql.structure.SQLFolderItems
+ </gateway>
+ <serializer roll_call>
+ order z
+ factory apelib.zodb3.serializers.RollCall
+ </serializer>
+ <register>
+ register-class false
+ for-generic root-oid
+ </register>
+</mapper>
+
+
+# 'common' is an abstract mapper that provides commonly used
+# serializers and gateways.
+
+<mapper common>
+ class none
+
+ <serializer id>
+ order a
+ factory apelib.zope2.ofsserial.IdAttribute
+ </serializer>
+ <gateway id[filesystem]>
+ factory apelib.fs.structure.FSAutoId
+ </gateway>
+ <gateway id[sql]>
+ factory apelib.sql.structure.SQLItemId
+ </gateway>
+
+ <serializer modtime>
+ factory apelib.zodb3.serializers.ModTimeAttribute
+ </serializer>
+ <gateway modtime[filesystem]>
+ factory apelib.fs.structure.FSModTime
+ </gateway>
+ <gateway modtime[sql]>
+ factory apelib.sql.structure.SQLModTime
+ </gateway>
+
+ <serializer security>
+ factory apelib.zope2.security.SecurityAttributes
+ </serializer>
+ <gateway security[filesystem]>
+ factory apelib.fs.security.FSSecurityAttributes
+ </gateway>
+ <gateway security[sql]>
+ factory apelib.sql.structure.SQLSecurityAttributes
+ </gateway>
+
+ <serializer remainder>
+ order z
+ factory apelib.zodb3.serializers.RemainingState
+ </serializer>
+ <gateway remainder[filesystem]>
+ factory apelib.fs.properties.FSSectionData('remainder')
+ </gateway>
+ <gateway remainder[sql]>
+ factory apelib.sql.structure.SQLRemainder
+ </gateway>
+
+</mapper>
+
+
+# 'common_p' is an abstract mapper with properties
+
+<mapper common_p>
+ extends common
+ class none
+ <serializer properties>
+ factory apelib.zope2.ofsserial.OFSProperties
+ </serializer>
+ <gateway properties[filesystem]>
+ factory apelib.fs.properties.FSProperties
+ </gateway>
+ <gateway properties[sql]>
+ factory apelib.sql.structure.SQLProperties
+ </gateway>
+</mapper>
+
+
+# 'common_text' is an abstract mapper with properties and a text body
+<mapper common_text>
+ extends common_p
+ class none
+ <serializer text>
+ factory apelib.core.serializers.StringDataAttribute('raw')
+ </serializer>
+ <gateway text[filesystem]>
+ factory apelib.fs.structure.FSFileData('text')
+ </gateway>
+ <gateway text[sql]>
+ factory apelib.sql.structure.SQLObjectData
+ </gateway>
+</mapper>
+
+
+# Folder mapper
+
+<mapper folder>
+ class OFS.Folder.Folder
+ extends common_p
+ <serializer items>
+ factory apelib.zope2.ofsserial.FolderItems
+ </serializer>
+ <gateway items[filesystem]>
+ factory apelib.fs.structure.FSDirectoryItems
+ </gateway>
+ <gateway items[sql]>
+ factory apelib.sql.structure.SQLFolderItems
+ </gateway>
+ <register>
+ for-generic directory
+ </register>
+</mapper>
+
+
+# File mapper
+
+<mapper file>
+ class OFS.Image.File
+ extends common_p
+ default-extension use_content_type
+ <serializer data>
+ factory apelib.zope2.ofsserial.FilePData
+ </serializer>
+ <gateway data[filesystem]>
+ factory apelib.fs.structure.FSFileData('binary')
+ </gateway>
+ <gateway data[sql]>
+ factory apelib.sql.structure.SQLObjectData
+ </gateway>
+ <register>
+ for-generic file
+ </register>
+</mapper>
+
+
+# Image mapper
+
+<mapper OFS.Image.Image>
+ extends file
+ default-extension use_content_type
+ <register>
+ for-extensions .gif .jpg .jpeg .png
+ </register>
+</mapper>
+
+
+# Page template mapper
+
+<mapper Products.PageTemplates.ZopePageTemplate.ZopePageTemplate>
+ extends common_text
+ default-extension .html
+ <serializer text>
+ factory apelib.core.serializers.StringDataAttribute('_text')
+ </serializer>
+ <register>
+ for-extensions .html .htm .zpt .pt
+ </register>
+</mapper>
+
+
+# DTML Document mapper
+
+<mapper OFS.DTMLDocument.DTMLDocument>
+ extends common_text
+ default-extension .dtml
+ <serializer text>
+ factory apelib.core.serializers.StringDataAttribute('raw')
+ </serializer>
+</mapper>
+
+
+# DTML Method mapper
+
+<mapper OFS.DTMLMethod.DTMLMethod>
+ extends OFS.DTMLDocument.DTMLDocument
+ default-extension .dtml
+ disable properties
+ <register>
+ for-extensions .dtml
+ </register>
+</mapper>
+
+
+# ZSQL Method mapper
+
+<mapper Products.ZSQLMethods.SQL.SQL>
+ extends common_text
+ default-extension .sql
+ <serializer properties>
+ factory apelib.zope2.scripts.ZSQLMethodPropertiesSerializer
+ </serializer>
+ <serializer text>
+ factory apelib.zope2.scripts.ZSQLMethodSerializer
+ </serializer>
+ <register>
+ for-extensions .sql
+ </register>
+</mapper>
+
+
+# Python script mapper
+
+<mapper Products.PythonScripts.PythonScript.PythonScript>
+ extends common_text
+ default-extension .py
+ disable properties
+ <serializer text>
+ factory apelib.zope2.scripts.PythonScriptSerializer
+ </serializer>
+ <register>
+ for-extensions .py
+ </register>
+</mapper>
+
+
+# User Folder mapper
+
+<mapper AccessControl.User.UserFolder>
+ extends common
+ <serializer data>
+ factory apelib.zope2.security.UserFolderSerializer
+ </serializer>
+ <gateway data[filesystem]>
+ factory apelib.fs.security.FSUserList
+ </gateway>
+ <gateway data[sql]>
+ factory apelib.sql.structure.SQLUserList
+ </gateway>
+</mapper>
+
+
+# Mapper of anything that looks like a folder
+
+<mapper anyfolder>
+ class none
+ extends folder
+ <serializer>
+ factory apelib.core.serializers.AnyObjectSerializer
+ </serializer>
+ <serializer properties>
+ factory apelib.zope2.ofsserial.OptionalOFSProperties
+ </serializer>
+ <register>
+ for-generic folder_object
+ </register>
+</mapper>
+
+
+# Mapper of anything that looks like a file
+
+<mapper anyfile>
+ class none
+ extends common_p
+ <serializer>
+ factory apelib.core.serializers.AnyObjectSerializer
+ </serializer>
+ <serializer properties>
+ factory apelib.zope2.ofsserial.OptionalOFSProperties
+ </serializer>
+ <register>
+ for-generic file_object
+ </register>
+</mapper>
+
+
+# Application mapper
+
+<mapper OFS.Application.Application>
+ extends folder
+ disable id
+ <register [filesystem]>
+ for-oid /
+ </register>
+</mapper>
+
+
+# Workarounds for objects that don't work with the anyfolder mapper,
+# but do fine with anyfile.
+
+<mapper anyfile>
+ <register>
+ for-class Products.CMFCore.SkinsTool.SkinsTool
+ for-class App.ApplicationManager.ApplicationManager
+ </register>
+</mapper>
=== Products/Ape/lib/apelib/zope2/apeconf.xml 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/zope2/apeconf.xml:1.3 Mon Aug 11 14:02:19 2003
+++ Products/Ape/lib/apelib/zope2/apeconf.xml Mon Feb 2 10:07:23 2004
@@ -4,27 +4,35 @@
<configuration>
-<!-- Root mapper -->
+<!-- Classifier and OID generator -->
-<mapper name="root" class="Persistence.PersistentMapping">
- <serializer name="root_items"
- factory="apelib.zodb3.serializers.BasicPersistentMapping" />
- <serializer name="roll_call" factory="apelib.zodb3.serializers.RollCall" />
- <variation name="filesystem">
+<variation name="filesystem">
<classifier factory="apelib.zope2.classifier.Classifier">
- <gateway factory="apelib.fs.classification.FSClassificationSection" />
+ <gateway factory="apelib.fs.classification.FSClassificationAnnotation" />
</classifier>
- <keygen factory="apelib.core.keygen.PathKeychainGenerator" />
- <gateway name="root_items" factory="apelib.zope2.ofsserial.ReadOnlyRoot"
- param="/" />
+ <oid-generator factory="apelib.core.oidgen.PathOIDGenerator" />
</variation>
<variation name="sql">
<classifier factory="apelib.zope2.classifier.Classifier">
<gateway factory="apelib.sql.classification.SQLClassification" />
</classifier>
- <keygen factory="apelib.sql.keygen.SQLKeychainGenerator" />
- <gateway name="root_items" factory="apelib.zope2.ofsserial.ReadOnlyRoot"
- param="0" />
+ <oid-generator factory="apelib.sql.oidgen.SQLOIDGenerator" />
+</variation>
+
+<!-- Root mapper -->
+
+<mapper name="root" register-class="false"
+ class="Persistence.PersistentMapping">
+ <serializer name="items"
+ factory="apelib.zodb3.serializers.StringToPersistentPM" />
+ <serializer name="roll_call" factory="apelib.zodb3.serializers.RollCall" />
+ <variation name="filesystem">
+ <gateway name="items" factory="apelib.fs.structure.RootDirectoryItems" />
+ <use-for oid="/_root" />
+ </variation>
+ <variation name="sql">
+ <gateway name="items" factory="apelib.sql.structure.SQLFolderItems" />
+ <use-for oid="0" />
</variation>
</mapper>
@@ -42,7 +50,7 @@
<variation name="filesystem">
<gateway name="id" factory="apelib.fs.structure.FSAutoId" />
<gateway name="modtime" factory="apelib.fs.structure.FSModTime" />
- <gateway name="remainder" factory="apelib.fs.properties.FSSectionData"
+ <gateway name="remainder" factory="apelib.fs.properties.FSAnnotationData"
param="remainder" />
<gateway name="security" factory="apelib.fs.security.FSSecurityAttributes" />
</variation>
@@ -97,33 +105,33 @@
<!-- Mappers for particular content types -->
-<mapper name="OFS.Folder.Folder" extends="base_p" parent="root">
+<mapper name="OFS.Folder.Folder" extends="base_p">
<serializer name="items" use="folder_items" />
<gateway name="items" use="dir_items" />
- <use-for fallback="directory" />
+ <use-for generic="directory" />
</mapper>
-<mapper name="OFS.Image.File" extends="base_p" parent="root">
+<mapper name="OFS.Image.File" extends="base_p">
<serializer name="data" factory="apelib.zope2.ofsserial.FilePData" />
<gateway name="data" use="binary_data" />
- <use-for fallback="file" />
+ <use-for generic="file" />
<option name="content_type_attr" value="content_type" />
</mapper>
-<mapper name="OFS.Image.Image" extends="OFS.Image.File" parent="root">
+<mapper name="OFS.Image.Image" extends="OFS.Image.File">
<use-for extensions=".gif .jpg .jpeg .png" />
<option name="content_type_attr" value="content_type" />
</mapper>
<mapper name="Products.PageTemplates.ZopePageTemplate.ZopePageTemplate"
- extends="base_p" parent="root">
+ extends="base_p">
<serializer name="text" factory="apelib.core.serializers.StringDataAttribute"
param="_text" />
<gateway name="text" use="text_data" />
<use-for extensions=".html .htm .zpt .pt" />
</mapper>
-<mapper name="OFS.DTMLMethod.DTMLMethod" extends="base" parent="root">
+<mapper name="OFS.DTMLMethod.DTMLMethod" extends="base">
<serializer name="text" factory="apelib.core.serializers.StringDataAttribute"
param="raw" />
<gateway name="text" use="text_data" />
@@ -131,11 +139,11 @@
</mapper>
<mapper name="OFS.DTMLMethod.DTMLDocument"
- extends="OFS.DTMLMethod.DTMLMethod" parent="root">
+ extends="OFS.DTMLMethod.DTMLMethod">
<serializer name="properties" enabled="false" />
</mapper>
-<mapper name="Products.ZSQLMethods.SQL.SQL" extends="base" parent="root">
+<mapper name="Products.ZSQLMethods.SQL.SQL" extends="base">
<serializer name="properties"
factory="apelib.zope2.scripts.ZSQLMethodPropertiesSerializer" />
<serializer name="text"
@@ -152,14 +160,14 @@
</mapper>
<mapper name="Products.PythonScripts.PythonScript.PythonScript"
- extends="base" parent="root">
+ extends="base">
<serializer name="body"
factory="apelib.zope2.scripts.PythonScriptSerializer" />
<gateway name="body" use="text_data" />
<use-for extensions=".py" />
</mapper>
-<mapper name="AccessControl.User.UserFolder" extends="base" parent="root">
+<mapper name="AccessControl.User.UserFolder" extends="base">
<serializer name="data"
factory="apelib.zope2.security.UserFolderSerializer" />
<variation name="filesystem">
@@ -170,29 +178,26 @@
</variation>
</mapper>
-<mapper name="anyfolder" class="any" extends="base_p" parent="root">
+<mapper name="anyfolder" class="any" extends="base_p">
<serializer name="properties" use="optional_properties" />
<serializer name="items" use="folder_items" />
<gateway name="items" use="dir_items" />
- <use-for fallback="folderish_object" />
+ <use-for generic="folder_object" />
</mapper>
-<mapper name="anyfile" class="any" extends="base_p" parent="root">
+<mapper name="anyfile" class="any" extends="base_p">
<serializer name="properties" use="optional_properties" />
<gateway name="remainder" use="binary_data" />
- <use-for fallback="fileish_object" />
+ <use-for generic="file_object" />
</mapper>
-<mapper name="OFS.Application.Application" extends="base_p" parent="root">
+<mapper name="OFS.Application.Application" extends="base_p">
<serializer name="items" use="folder_items" />
<serializer name="id" enabled="false" />
<gateway name="id" enabled="false" />
<gateway name="items" use="dir_items" />
<variation name="filesystem">
- <use-for key="/" />
- </variation>
- <variation name="sql">
- <use-for key="0" />
+ <use-for oid="/" />
</variation>
</mapper>
=== Products/Ape/lib/apelib/zope2/classifier.py 1.5 => 1.6 ===
--- Products/Ape/lib/apelib/zope2/classifier.py:1.5 Wed Jul 30 18:11:42 2003
+++ Products/Ape/lib/apelib/zope2/classifier.py Mon Feb 2 10:07:23 2004
@@ -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
@@ -43,59 +43,55 @@
"""A classifier with some minimal Zope 2 extensions.
"""
__implements__ = IConfigurableClassifier
-
+ gateway = None
def __init__(self, gw=None):
- self.gw = gw
- self.key_to_mapper = {}
+ self.gateway = gw
+ self.oid_to_mapper = {}
self.class_to_mapper = {}
self.ext_to_mapper = {}
- self.fallback_to_mapper = {}
+ self.generic_to_mapper = {}
self.options = {} # { (mapper_name, option) -> value }
- def getGateway(self):
- return self.gw
-
-
def register(self, condition, value, mapper_name):
- if condition == 'key':
- self.key_to_mapper[value] = mapper_name
- elif condition == 'extension':
+ value = str(value) # Avoid unicode
+ if condition == 'extension':
self.ext_to_mapper[value] = mapper_name
elif condition == 'class':
self.class_to_mapper[value] = mapper_name
- elif condition == 'fallback':
- assert value in ('directory', 'file',
- 'folderish_object', 'fileish_object'), value
- self.fallback_to_mapper[value] = mapper_name
+ elif condition == 'generic':
+ assert value in (
+ 'directory', 'file', 'folder_object', 'file_object'), value
+ self.generic_to_mapper[value] = mapper_name
+ elif condition == 'oid':
+ self.oid_to_mapper[value] = mapper_name
else:
raise ValueError('Unknown classification condition: %s'
% repr(condition))
-
def setOption(self, mapper_name, option, value):
assert option in ('default_extension', 'content_type_attr'), option
self.options[(mapper_name, option)] = value
-
- def classifyObject(self, value, keychain):
- """Chooses a mapper and classification for storing an object."""
- mapper_name = self.key_to_mapper.get(keychain[-1])
+
+ def classifyObject(self, event):
+ """Chooses a mapper and classification for storing an object.
+ """
+ mapper_name = self.oid_to_mapper.get(event.oid)
if mapper_name is not None:
- # Shortcut.
return {'mapper_name': mapper_name}, mapper_name
- klass = value.__class__
+ klass = event.obj.__class__
class_name = '%s.%s' % (klass.__module__, klass.__name__)
classification = {'class_name': class_name}
mapper_name = self.class_to_mapper.get(class_name)
if mapper_name is None:
- folderish = isinstance(value, ObjectManager)
- # Store in a fallback format
+ folderish = isinstance(event.obj, ObjectManager)
+ # Store in a generic format
if folderish:
- fallback = 'folderish_object'
+ generic = 'folder_object'
else:
- fallback = 'fileish_object'
- mapper_name = self.fallback_to_mapper.get(fallback)
+ generic = 'file_object'
+ mapper_name = self.generic_to_mapper.get(generic)
if mapper_name is not None:
# Force a particular mapper
classification['mapper_name'] = mapper_name
@@ -104,7 +100,7 @@
'No mapper known for class %s' % repr(class_name))
cta = self.options.get((mapper_name, 'content_type_attr'))
if cta is not None:
- ct = str(getattr(aq_base(value), cta, None))
+ ct = str(getattr(aq_base(event.obj), cta, None))
ext = fixed_extensions.get(ct)
if ext is None:
ext = guess_extension(ct)
@@ -117,12 +113,12 @@
def classifyState(self, event):
- """Chooses a mapper and classification for loading an object."""
- mapper_name = self.key_to_mapper.get(event.getKey())
+ """Chooses a mapper and classification for loading an object.
+ """
+ mapper_name = self.oid_to_mapper.get(event.oid)
if mapper_name is not None:
- # Shortcut.
return {'mapper_name': mapper_name}, mapper_name
- classification, serial = self.gw.load(event)
+ classification, serial = self.gateway.load(event)
class_name = classification.get('class_name')
if class_name and ':' in class_name:
# Backward compatibility
@@ -133,16 +129,16 @@
# bw compat: look for certain meta_types.
mt = classification.get('meta_type')
if mt == '(folderish object)':
- mapper_name = self.fallback_to_mapper.get('folderish_object')
+ mapper_name = self.generic_to_mapper.get('folder_object')
elif mt == '(fileish object)':
- mapper_name = self.fallback_to_mapper.get('fileish_object')
+ mapper_name = self.generic_to_mapper.get('file_object')
if mapper_name is None and class_name is not None:
mapper_name = self.class_to_mapper.get(class_name)
if mapper_name is None:
t = classification.get('node_type')
if t == 'd':
# Directory
- mapper_name = self.fallback_to_mapper.get('directory')
+ mapper_name = self.generic_to_mapper.get('directory')
elif t == 'f':
# File
ext = classification.get('extension')
@@ -151,14 +147,8 @@
ext = '.' + ext
mapper_name = self.ext_to_mapper.get(ext.lower())
if not mapper_name:
- mapper_name = self.fallback_to_mapper.get('file')
+ mapper_name = self.generic_to_mapper.get('file')
if mapper_name is None:
raise DeserializationError(
'No mapper known for class %s' % repr(class_name))
return classification, mapper_name
-
-
- def store(self, event, classification):
- """Stores the classification of an object."""
- return self.gw.store(event, classification)
-
=== Products/Ape/lib/apelib/zope2/mapper.py 1.2 => 1.3 ===
--- Products/Ape/lib/apelib/zope2/mapper.py:1.2 Wed Jul 9 11:40:15 2003
+++ Products/Ape/lib/apelib/zope2/mapper.py Mon Feb 2 10:07:23 2004
@@ -18,10 +18,10 @@
import os
import Products
-from apelib.config.apeconf import wireMapper
+from apelib.config.apeconf import configure
-def createMapper(vname, search_products=0):
+def loadConf(vname, search_products=0):
"""Builds a mapper from apeconf.xml files.
"""
here = os.path.dirname(__file__)
@@ -35,7 +35,7 @@
fn = os.path.join(path, name, 'apeconf.xml')
if os.path.exists(fn):
filenames.append(fn)
- return wireMapper(filenames, vname, 'root')
+ return configure(filenames, vname)
def createFSMapper(basepath, **kw):
@@ -49,7 +49,7 @@
"""
from apelib.fs.connection import FSConnection
- mapper = createMapper('filesystem', search_products=1)
+ mapper = loadConf('filesystem', search_products=1)
conn = FSConnection(basepath, **kw)
return mapper, {'fs': conn}
@@ -68,7 +68,7 @@
"""
from apelib.sql.dbapi import DBAPIConnector
- mapper = createMapper('sql', search_products=1)
+ mapper = loadConf('sql', search_products=1)
conn = DBAPIConnector(module_name, **kw)
return mapper, {'db': conn}
=== Products/Ape/lib/apelib/zope2/ofsserial.py 1.5 => 1.6 ===
--- Products/Ape/lib/apelib/zope2/ofsserial.py:1.5 Wed Jul 30 18:11:42 2003
+++ Products/Ape/lib/apelib/zope2/ofsserial.py Mon Feb 2 10:07:23 2004
@@ -25,11 +25,9 @@
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
string_repr_types = {
@@ -53,30 +51,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.deserialized('data', obj.data)
class FolderItems:
@@ -85,8 +80,8 @@
__implements__ = ISerializer
schema = RowSequenceSchema()
- schema.addField('id', 'string', 1)
- schema.addField('keychain', 'keychain')
+ schema.addField('key', 'string', 1)
+ 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 +89,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 +135,31 @@
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)
+ if not id:
+ raise SerializationError('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()
- event.ignoreAttribute('_properties')
- for p in object._properties:
+ obj = event.obj
+ assert isinstance(obj, PropertyManager), repr(obj)
+ assert obj._properties is obj._propertyMap()
+ event.ignore('_properties')
+ for p in obj._properties:
name = p['id']
t = p['type']
- event.ignoreAttribute(name)
- data = object.getProperty(name)
+ event.ignore(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,18 +261,7 @@
else:
# Fall back to a default.
data = ''
- object._updateProperty(id, data)
-
-
-class ReadOnlyRoot(ReadOnlyItems):
- """Zope 2 application root."""
-
- def __init__(self, root_key):
- try:
- root_key = int(root_key)
- except ValueError:
- root_key = str(root_key)
- ReadOnlyItems.__init__(self, {'Application': (root_key,)})
+ obj._updateProperty(id, data)
class OptionalOFSProperties(OptionalSerializer):
=== Products/Ape/lib/apelib/zope2/scripts.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/zope2/scripts.py:1.3 Fri Apr 11 23:39:38 2003
+++ Products/Ape/lib/apelib/zope2/scripts.py Mon Feb 2 10:07:23 2004
@@ -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.4 ===
--- Products/Ape/lib/apelib/zope2/security.py:1.3 Mon Apr 14 04:22:19 2003
+++ Products/Ape/lib/apelib/zope2/security.py Mon Feb 2 10:07:23 2004
@@ -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