[CMF-checkins] SVN: CMF/trunk/ oops! reverted trunk changes (my sandbox seems to be broken...)

Yvo Schubbe y.2005- at wcm-solutions.de
Sun Sep 25 11:57:11 EDT 2005


Log message for revision 38622:
  oops! reverted trunk changes (my sandbox seems to be broken...)

Changed:
  D   CMF/trunk/CMFCalendar/profiles/default/catalog.xml
  U   CMF/trunk/CMFCalendar/setuphandlers.py
  D   CMF/trunk/CMFSetup/catalog.py
  D   CMF/trunk/CMFSetup/tests/test_catalog.py
  D   CMF/trunk/GenericSetup/configure.zcml
  U   CMF/trunk/GenericSetup/interfaces.py
  D   CMF/trunk/GenericSetup/testing.py
  U   CMF/trunk/GenericSetup/utils.py

-=-
Deleted: CMF/trunk/CMFCalendar/profiles/default/catalog.xml
===================================================================
--- CMF/trunk/CMFCalendar/profiles/default/catalog.xml	2005-09-25 15:41:59 UTC (rev 38621)
+++ CMF/trunk/CMFCalendar/profiles/default/catalog.xml	2005-09-25 15:57:10 UTC (rev 38622)
@@ -1,11 +0,0 @@
-<?xml version="1.0"?>
-<object name="portal_catalog" meta_type="CMF Catalog">
- <index name="end" meta_type="DateIndex">
-  <property name="index_naive_time_as_local">True</property>
- </index>
- <index name="start" meta_type="DateIndex">
-  <property name="index_naive_time_as_local">True</property>
- </index>
- <column value="end"/>
- <column value="start"/>
-</object>

Modified: CMF/trunk/CMFCalendar/setuphandlers.py
===================================================================
--- CMF/trunk/CMFCalendar/setuphandlers.py	2005-09-25 15:41:59 UTC (rev 38621)
+++ CMF/trunk/CMFCalendar/setuphandlers.py	2005-09-25 15:57:10 UTC (rev 38622)
@@ -17,6 +17,7 @@
 
 from Products.CMFCore.utils import getToolByName
 
+from exceptions import CatalogError
 from exceptions import MetadataError
 
 
@@ -27,8 +28,27 @@
     are implemented for these steps.
     """
     site = context.getSite()
+    ctool = getToolByName(site, 'portal_catalog')
     mdtool = getToolByName(site, 'portal_metadata')
 
+    # Set up a catalog indexes and metadata
+    try:
+        ctool.addIndex('start', 'DateIndex')
+    except CatalogError:
+        pass
+    try:
+        ctool.addIndex('end', 'DateIndex')
+    except CatalogError:
+        pass
+    try:
+        ctool.addColumn('start')
+    except CatalogError:
+        pass
+    try:
+        ctool.addColumn('end')
+    except CatalogError:
+        pass
+
     # Set up a MetadataTool element policy for events
     try:
         _ = str # MetadataTool ist not aware of MessageIDs

Deleted: CMF/trunk/CMFSetup/catalog.py
===================================================================
--- CMF/trunk/CMFSetup/catalog.py	2005-09-25 15:41:59 UTC (rev 38621)
+++ CMF/trunk/CMFSetup/catalog.py	2005-09-25 15:57:10 UTC (rev 38622)
@@ -1,63 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Catalog tool setup handlers.
-
-$Id$
-"""
-
-from xml.dom.minidom import parseString
-
-from Products.CMFCore.utils import getToolByName
-from Products.GenericSetup.interfaces import INodeExporter
-from Products.GenericSetup.interfaces import INodeImporter
-from Products.GenericSetup.interfaces import PURGE, UPDATE
-from Products.GenericSetup.utils import PrettyDocument
-
-_FILENAME = 'catalog.xml'
-
-
-def importCatalogTool(context):
-    """ Import catalog tool.
-    """
-    site = context.getSite()
-    mode = context.shouldPurge() and PURGE or UPDATE
-    ctool = getToolByName(site, 'portal_catalog')
-
-    body = context.readDataFile(_FILENAME)
-    if body is None:
-        return 'Catalog tool: Nothing to import.'
-
-    importer = INodeImporter(ctool, None)
-    if importer is None:
-        return 'Catalog tool: Import adapter misssing.'
-
-    importer.importNode(parseString(body).documentElement, mode=mode)
-    return 'Catalog tool imported.'
-
-def exportCatalogTool(context):
-    """ Export catalog tool.
-    """
-    site = context.getSite()
-
-    ctool = getToolByName(site, 'portal_catalog', None)
-    if ctool is None:
-        return 'Catalog tool: Nothing to export.'
-
-    exporter = INodeExporter(ctool)
-    if exporter is None:
-        return 'Catalog tool: Export adapter misssing.'
-
-    doc = PrettyDocument()
-    doc.appendChild(exporter.exportNode(doc))
-    context.writeDataFile(_FILENAME, doc.toprettyxml(' '), 'text/xml')
-    return 'Catalog tool exported.'

Deleted: CMF/trunk/CMFSetup/tests/test_catalog.py
===================================================================
--- CMF/trunk/CMFSetup/tests/test_catalog.py	2005-09-25 15:41:59 UTC (rev 38621)
+++ CMF/trunk/CMFSetup/tests/test_catalog.py	2005-09-25 15:57:10 UTC (rev 38622)
@@ -1,227 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Catalog tool setup handler unit tests.
-
-$Id$
-"""
-
-import unittest
-import Testing
-import Zope2
-Zope2.startup()
-
-from OFS.Folder import Folder
-from Products.ZCTextIndex.Lexicon import CaseNormalizer
-from Products.ZCTextIndex.Lexicon import Splitter
-from Products.ZCTextIndex.Lexicon import StopWordRemover
-from Products.ZCTextIndex.ZCTextIndex import PLexicon
-
-from Products.CMFCore.CatalogTool import CatalogTool
-
-from common import BaseRegistryTests
-from common import DummyExportContext
-from common import DummyImportContext
-
-
-class _extra:
-
-    pass
-
-
-class _CatalogToolSetup(BaseRegistryTests):
-
-    def _initSite(self, foo=2):
-        site = self.root.site = Folder(id='site')
-        ctool = site.portal_catalog = CatalogTool()
-
-        for obj_id in ctool.objectIds():
-            ctool._delObject(obj_id)
-        for idx_id in ctool.indexes():
-            ctool.delIndex(idx_id)
-        for col in ctool.schema()[:]:
-            ctool.delColumn(col)
-
-        if foo > 0:
-            ctool._setObject('foo_plexicon', PLexicon('foo_plexicon'))
-            lex = ctool.foo_plexicon
-            lex._pipeline = (Splitter(), CaseNormalizer(), StopWordRemover())
-
-            extra = _extra()
-            extra.lexicon_id = 'foo_plexicon'
-            extra.index_type = 'Okapi BM25 Rank'
-            ctool.addIndex('foo_zctext', 'ZCTextIndex', extra)
-
-            ctool.addColumn('foo_zctext')
-
-        return site
-
-
-_EMPTY_EXPORT = """\
-<?xml version="1.0"?>
-<object meta_type="CMF Catalog" name="portal_catalog">
- <property name="title"/>
-</object>
-"""
-
-_NORMAL_EXPORT = """\
-<?xml version="1.0"?>
-<object meta_type="CMF Catalog" name="portal_catalog">
- <property name="title"/>
- <object name="foo_plexicon" meta_type="ZCTextIndex Lexicon">
-  <element name="Whitespace splitter" group="Word Splitter"/>
-  <element name="Case Normalizer" group="Case Normalizer"/>
-  <element name="Remove listed stop words only" group="Stop Words"/>
- </object>
- <index name="foo_zctext" meta_type="ZCTextIndex">
-  <indexed_attr value="foo_zctext"/>
-  <extra name="index_type" value="Okapi BM25 Rank"/>
-  <extra name="lexicon_id" value="foo_plexicon"/>
- </index>
- <column value="foo_zctext"/>
-</object>
-"""
-
-_UPDATE_IMPORT = """\
-<?xml version="1.0"?>
-<object meta_type="CMF Catalog" name="portal_catalog">
- <index name="foo_date" meta_type="DateIndex">
-  <property name="index_naive_time_as_local">True</property>
- </index>
- <column value="foo_date"/>
-</object>
-"""
-
-
-class Test_exportCatalogTool(_CatalogToolSetup):
-
-    def test_unchanged(self):
-        from Products.CMFSetup.catalog import exportCatalogTool
-
-        site = self._initSite(0)
-        context = DummyExportContext(site)
-        exportCatalogTool(context)
-
-        self.assertEqual(len(context._wrote), 1)
-        filename, text, content_type = context._wrote[0]
-        self.assertEqual(filename, 'catalog.xml')
-        self._compareDOM(text, _EMPTY_EXPORT)
-        self.assertEqual(content_type, 'text/xml')
-
-    def test_normal(self):
-        from Products.CMFSetup.catalog import exportCatalogTool
-
-        site = self._initSite(2)
-        context = DummyExportContext(site)
-        exportCatalogTool(context)
-
-        self.assertEqual(len(context._wrote), 1)
-        filename, text, content_type = context._wrote[0]
-        self.assertEqual(filename, 'catalog.xml')
-        self._compareDOM(text, _NORMAL_EXPORT)
-        self.assertEqual(content_type, 'text/xml')
-
-
-class Test_importCatalogTool(_CatalogToolSetup):
-
-    def test_empty_purge(self):
-        from Products.CMFSetup.catalog import importCatalogTool
-
-        site = self._initSite(2)
-        ctool = site.portal_catalog
-
-        self.assertEqual(len(ctool.objectIds()), 1)
-        self.assertEqual(len(ctool.indexes()), 1)
-        self.assertEqual(len(ctool.schema()), 1)
-
-        context = DummyImportContext(site, True)
-        context._files['catalog.xml'] = _EMPTY_EXPORT
-        importCatalogTool(context)
-
-        self.assertEqual(len(ctool.objectIds()), 0)
-        self.assertEqual(len(ctool.indexes()), 0)
-        self.assertEqual(len(ctool.schema()), 0)
-
-    def test_empty_update(self):
-        from Products.CMFSetup.catalog import importCatalogTool
-
-        site = self._initSite(2)
-        ctool = site.portal_catalog
-
-        self.assertEqual(len(ctool.objectIds()), 1)
-        self.assertEqual(len(ctool.indexes()), 1)
-        self.assertEqual(len(ctool.schema()), 1)
-
-        context = DummyImportContext(site, False)
-        context._files['catalog.xml'] = _EMPTY_EXPORT
-        importCatalogTool(context)
-
-        self.assertEqual(len(ctool.objectIds()), 1)
-        self.assertEqual(len(ctool.indexes()), 1)
-        self.assertEqual(len(ctool.schema()), 1)
-
-    def test_normal_purge(self):
-        from Products.CMFSetup.catalog import exportCatalogTool
-        from Products.CMFSetup.catalog import importCatalogTool
-
-        site = self._initSite(2)
-        ctool = site.portal_catalog
-
-        self.assertEqual(len(ctool.objectIds()), 1)
-        self.assertEqual(len(ctool.indexes()), 1)
-        self.assertEqual(len(ctool.schema()), 1)
-
-        context = DummyImportContext(site, True)
-        context._files['catalog.xml'] = _NORMAL_EXPORT
-        importCatalogTool(context)
-
-        self.assertEqual(len(ctool.objectIds()), 1)
-        self.assertEqual(len(ctool.indexes()), 1)
-        self.assertEqual(len(ctool.schema()), 1)
-
-        # complete the roundtrip
-        context = DummyExportContext(site)
-        exportCatalogTool(context)
-
-        self.assertEqual(len(context._wrote), 1)
-        filename, text, content_type = context._wrote[0]
-        self.assertEqual(filename, 'catalog.xml')
-        self._compareDOM(text, _NORMAL_EXPORT)
-        self.assertEqual(content_type, 'text/xml')
-
-    def test_normal_update(self):
-        from Products.CMFSetup.catalog import importCatalogTool
-
-        site = self._initSite(2)
-        ctool = site.portal_catalog
-
-        self.assertEqual(len(ctool.objectIds()), 1)
-        self.assertEqual(len(ctool.indexes()), 1)
-        self.assertEqual(len(ctool.schema()), 1)
-
-        context = DummyImportContext(site, False)
-        context._files['catalog.xml'] = _UPDATE_IMPORT
-        importCatalogTool(context)
-
-        self.assertEqual(len(ctool.objectIds()), 1)
-        self.assertEqual(len(ctool.indexes()), 2)
-        self.assertEqual(len(ctool.schema()), 2)
-
-
-def test_suite():
-    return unittest.TestSuite((
-        unittest.makeSuite(Test_exportCatalogTool),
-        unittest.makeSuite(Test_importCatalogTool),
-        ))
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')

Deleted: CMF/trunk/GenericSetup/configure.zcml
===================================================================
--- CMF/trunk/GenericSetup/configure.zcml	2005-09-25 15:41:59 UTC (rev 38621)
+++ CMF/trunk/GenericSetup/configure.zcml	2005-09-25 15:57:10 UTC (rev 38622)
@@ -1,11 +0,0 @@
-<configure
-    xmlns="http://namespaces.zope.org/zope"
-    >
-
-  <include package=".PluginIndexes"/>
-
-  <include package=".ZCatalog"/>
-
-  <include package=".ZCTextIndex"/>
-
-</configure>

Modified: CMF/trunk/GenericSetup/interfaces.py
===================================================================
--- CMF/trunk/GenericSetup/interfaces.py	2005-09-25 15:41:59 UTC (rev 38621)
+++ CMF/trunk/GenericSetup/interfaces.py	2005-09-25 15:57:10 UTC (rev 38622)
@@ -18,8 +18,7 @@
 from zope.interface import Interface
 
 
-BASE, EXTENSION = range(1,3)
-PURGE, UPDATE = range(1, 3)
+BASE, EXTENSION = range(2)
 
 
 class IPseudoInterface( Interface ):
@@ -512,23 +511,3 @@
         o If 'ignore_whitespace', then suppress diffs due only to whitespace
           (c.f:  'diff -wbB')
         """
-
-
-class INodeExporter(Interface):
-
-    """Node exporter.
-    """
-
-    def exportNode(doc):
-        """Export the object as a DOM node.
-        """
-
-
-class INodeImporter(Interface):
-
-    """Node importer.
-    """
-
-    def importNode(node, mode=PURGE):
-        """Import the object from the DOM node.
-        """

Deleted: CMF/trunk/GenericSetup/testing.py
===================================================================
--- CMF/trunk/GenericSetup/testing.py	2005-09-25 15:41:59 UTC (rev 38621)
+++ CMF/trunk/GenericSetup/testing.py	2005-09-25 15:57:10 UTC (rev 38622)
@@ -1,46 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Node adapter testing utils.
-
-$Id$
-"""
-
-import unittest
-from xml.dom.minidom import parseString
-
-from zope.interface.verify import verifyClass
-
-from interfaces import INodeExporter
-from interfaces import INodeImporter
-from utils import PrettyDocument
-
-
-class NodeAdapterTestCase(unittest.TestCase):
-
-    def _populate(self, obj):
-        pass
-
-    def test_z3interfaces(self):
-        verifyClass(INodeExporter, self._getTargetClass())
-        verifyClass(INodeImporter, self._getTargetClass())
-
-    def test_exportNode(self):
-        self._populate(self._obj)
-        node = INodeExporter(self._obj).exportNode(PrettyDocument())
-        self.assertEqual(node.toprettyxml(' '), self._XML)
-
-    def test_importNode(self):
-        node = parseString(self._XML).documentElement
-        self.assertEqual(INodeImporter(self._obj).importNode(node), None)
-        node = INodeExporter(self._obj).exportNode(PrettyDocument())
-        self.assertEqual(node.toprettyxml(' '), self._XML)

Modified: CMF/trunk/GenericSetup/utils.py
===================================================================
--- CMF/trunk/GenericSetup/utils.py	2005-09-25 15:41:59 UTC (rev 38621)
+++ CMF/trunk/GenericSetup/utils.py	2005-09-25 15:57:10 UTC (rev 38622)
@@ -17,11 +17,6 @@
 
 import os
 from inspect import getdoc
-from xml.dom.minidom import _nssplit
-from xml.dom.minidom import _write_data
-from xml.dom.minidom import Document
-from xml.dom.minidom import Element
-from xml.dom.minidom import Node
 from xml.dom.minidom import parseString as domParseString
 from xml.sax.handler import ContentHandler
 
@@ -32,12 +27,8 @@
 from Globals import InitializeClass
 from Globals import package_home
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
-from zope.interface import implements
 
 from exceptions import BadRequest
-from interfaces import INodeExporter
-from interfaces import INodeImporter
-from interfaces import PURGE
 from permissions import ManagePortal
 
 
@@ -47,7 +38,6 @@
 _xmldir = os.path.join( _pkgdir, 'xml' )
 
 CONVERTER, DEFAULT, KEY = range(3)
-I18NURI = 'http://xml.zope.org/namespaces/i18n'
 
 
 def _getDottedName( named ):
@@ -522,264 +512,3 @@
         return _coalesceTextNodeChildren(d_nodes[0], encoding)
     else:
         return ''
-
-
-# XXX: Is there any code available in Zope that generates pretty XML? If not,
-#      this code has to be improved.
-class _Element(Element):
-
-    """minidom element with 'pretty' XML output.
-    """
-
-    def writexml(self, writer, indent="", addindent="", newl=""):
-        # indent = current indentation
-        # addindent = indentation to add to higher levels
-        # newl = newline string
-        writer.write(indent+"<" + self.tagName)
-
-        attrs = self._get_attributes()
-        a_names = attrs.keys()
-        a_names.sort()
-        if 'title' in a_names:
-            a_names.remove('title')
-            a_names.insert(0, 'title')
-        if 'meta_type' in a_names:
-            a_names.remove('meta_type')
-            a_names.insert(0, 'meta_type')
-        if 'name' in a_names:
-            a_names.remove('name')
-            a_names.insert(0, 'name')
-
-        for a_name in a_names:
-            writer.write(" %s=\"" % a_name)
-            _write_data(writer, attrs[a_name].value)
-            writer.write("\"")
-        if self.childNodes:
-            if self.firstChild.nodeType == Node.TEXT_NODE:
-                writer.write(">")
-            else:
-                writer.write(">%s"%(newl))
-            for node in self.childNodes:
-                if node.nodeType == Node.TEXT_NODE:
-                    writer.write(node.data)
-                else:
-                    node.writexml(writer,indent+addindent,addindent,newl)
-            if self.lastChild.nodeType == Node.TEXT_NODE:
-                writer.write("</%s>%s" % (self.tagName,newl))
-            else:
-                writer.write("%s</%s>%s" % (indent,self.tagName,newl))
-        else:
-            writer.write("/>%s"%(newl))
-
-
-class PrettyDocument(Document):
-
-    """minidom document with 'pretty' XML output.
-    """
-
-    def createElement(self, tagName):
-        e = _Element(tagName)
-        e.ownerDocument = self
-        return e
-
-    def createElementNS(self, namespaceURI, qualifiedName):
-        prefix, localName = _nssplit(qualifiedName)
-        e = _Element(qualifiedName, namespaceURI, prefix)
-        e.ownerDocument = self
-        return e
-
-    def writexml(self, writer, indent="", addindent="", newl="",
-                 encoding = None):
-        if encoding is None:
-            writer.write('<?xml version="1.0"?>\n')
-        else:
-            writer.write('<?xml version="1.0" encoding="%s"?>\n' % encoding)
-        for node in self.childNodes:
-            node.writexml(writer, indent, addindent, newl)
-
-
-class NodeAdapterBase(object):
-
-    """Node im- and exporter base.
-    """
-
-    implements(INodeExporter, INodeImporter)
-
-    def __init__(self, context):
-        self.context = context
-
-    def exportNode(self, doc):
-        """Export the object as a DOM node.
-        """
-        self._doc = doc
-        return self._getObjectNode('object')
-
-    def importNode(self, node, mode=PURGE):
-        """Import the object from the DOM node.
-        """
-
-    def _getObjectNode(self, name):
-        node = self._doc.createElement(name)
-        node.setAttribute('name', self.context.getId())
-        node.setAttribute('meta_type', self.context.meta_type)
-        i18n_domain = getattr(self.context, 'i18n_domain', None)
-        if i18n_domain:
-            node.setAttributeNS(I18NURI, 'i18n:domain', i18n_domain)
-            self._i18n_props = ('title', 'description')
-        return node
-
-    def _getNodeText(self, node):
-        text = ''
-        for child in node.childNodes:
-            if child.nodeName != '#text':
-                continue
-            text += child.nodeValue.lstrip()
-        return text
-
-    def _getNodeTextBoolean(self, node):
-        text = self._getNodeText(node)
-        return text.lower() in ('true', 'yes', '1')
-
-
-class ObjectManagerHelpers(object):
-
-    """ObjectManager im- and export helpers.
-    """
-
-    def _extractObjects(self):
-        fragment = self._doc.createDocumentFragment()
-        for obj in self.context.objectValues():
-            exporter = INodeExporter(obj, None)
-            if exporter is None:
-                continue
-            fragment.appendChild(exporter.exportNode(self._doc))
-        return fragment
-
-    def _purgeObjects(self):
-        for obj_id in self.context.objectIds():
-            self.context._delObject(obj_id)
-
-    def _initObjects(self, node, mode):
-        for child in node.childNodes:
-            if child.nodeName != 'object':
-                continue
-            if child.hasAttribute('deprecated'):
-                continue
-            parent = self.context
-
-            obj_id = str(child.getAttribute('name'))
-            if obj_id not in parent.objectIds():
-                meta_type = str(child.getAttribute('meta_type'))
-                for mt_info in Products.meta_types:
-                    if mt_info['name'] == meta_type:
-                        parent._setObject(obj_id, mt_info['instance'](obj_id))
-                        break
-                else:
-                    raise ValueError('unknown meta_type \'%s\'' % obj_id)
-
-            if child.hasAttribute('insert-before'):
-                insert_before = child.getAttribute('insert-before')
-                if insert_before == '*':
-                    parent.moveObjectsToTop(obj_id)
-                else:
-                    try:
-                        position = parent.getObjectPosition(insert_before)
-                        parent.moveObjectToPosition(obj_id, position)
-                    except ValueError:
-                        pass
-            elif child.hasAttribute('insert-after'):
-                insert_after = child.getAttribute('insert-after')
-                if insert_after == '*':
-                    parent.moveObjectsToBottom(obj_id)
-                else:
-                    try:
-                        position = parent.getObjectPosition(insert_after)
-                        parent.moveObjectToPosition(obj_id, position+1)
-                    except ValueError:
-                        pass
-
-            obj = getattr(self.context, obj_id)
-            INodeImporter(obj).importNode(child, mode)
-
-
-class PropertyManagerHelpers(object):
-
-    """PropertyManager im- and export helpers.
-    """
-
-    def _extractProperties(self):
-        fragment = self._doc.createDocumentFragment()
-
-        for prop_map in self.context._propertyMap():
-            if prop_map['id'] == 'i18n_domain':
-                continue
-            node = self._doc.createElement('property')
-
-            prop_id = prop_map['id']
-            node.setAttribute('name', prop_id)
-
-            prop = self.context.getProperty(prop_id)
-            if isinstance(prop, (tuple, list)):
-                for value in prop:
-                    child = self._doc.createElement('element')
-                    child.setAttribute('value', value)
-                    node.appendChild(child)
-            else:
-                if not isinstance(prop, basestring):
-                    prop = str(prop)
-                child = self._doc.createTextNode(prop)
-                node.appendChild(child)
-
-            if 'd' in prop_map.get('mode', 'wd') and not prop_id == 'title':
-                type = prop_map.get('type', 'string')
-                node.setAttribute('type', type)
-                select_variable = prop_map.get('select_variable', None)
-                if select_variable is not None:
-                    node.setAttribute('select_variable', select_variable)
-
-            if hasattr(self, '_i18n_props') and prop_id in self._i18n_props:
-                node.setAttribute('i18n:translate', '')
-
-            fragment.appendChild(node)
-
-        return fragment
-
-    def _purgeProperties(self):
-        #XXX: not implemented
-        pass
-
-    def _initProperties(self, node, mode):
-        self.context.i18n_domain = node.getAttribute('i18n:domain')
-        for child in node.childNodes:
-            if child.nodeName != 'property':
-                continue
-            obj = self.context
-            prop_id = str(child.getAttribute('name'))
-            prop_map = obj.propdict().get(prop_id, None)
-
-            if prop_map is None:
-                if child.hasAttribute('type'):
-                    val = child.getAttribute('select_variable')
-                    obj._setProperty(prop_id, val, child.getAttribute('type'))
-                    prop_map = obj.propdict().get(prop_id, None)
-                else:
-                    raise ValueError('undefined property \'%s\'' % prop_id)
-
-            if not 'w' in prop_map.get('mode', 'wd'):
-                raise BadRequest('%s cannot be changed' % prop_id)
-
-            elements = []
-            for sub in child.childNodes:
-                if sub.nodeName == 'element':
-                    elements.append(sub.getAttribute('value'))
-
-            if elements or prop_map.get('type') == 'multiple selection':
-                prop_value = tuple(elements) or ()
-            elif prop_map.get('type') == 'boolean':
-                prop_value = self._getNodeTextBoolean(child)
-            else:
-                # if we pass a *string* to _updateProperty, all other values
-                # are converted to the right type
-                prop_value = self._getNodeText(child)
-
-            obj._updateProperty(prop_id, prop_value)



More information about the CMF-checkins mailing list