[CMF-checkins] SVN: CMF/trunk/C - improved properties handler
Yvo Schubbe
y.2007- at wcm-solutions.de
Tue Jan 16 06:06:30 EST 2007
Log message for revision 72049:
- improved properties handler
Changed:
U CMF/trunk/CHANGES.txt
U CMF/trunk/CMFCore/exportimport/properties.py
U CMF/trunk/CMFCore/exportimport/tests/test_properties.py
-=-
Modified: CMF/trunk/CHANGES.txt
===================================================================
--- CMF/trunk/CHANGES.txt 2007-01-16 10:49:54 UTC (rev 72048)
+++ CMF/trunk/CHANGES.txt 2007-01-16 11:06:30 UTC (rev 72049)
@@ -2,6 +2,9 @@
New Features
+ - setup handlers: Improved properties handler.
+ It now works with properties using a default_charset other than UTF-8.
+
- Merged patches from Martin Aspeli to enable generating events before
and after DCWorkflow transitions, and in the 'notify' methods of the
workflow tool (http://www.zope.org/Collectors/CMF/461).
Modified: CMF/trunk/CMFCore/exportimport/properties.py
===================================================================
--- CMF/trunk/CMFCore/exportimport/properties.py 2007-01-16 10:49:54 UTC (rev 72048)
+++ CMF/trunk/CMFCore/exportimport/properties.py 2007-01-16 11:06:30 UTC (rev 72049)
@@ -40,6 +40,8 @@
def _exportNode(self):
"""Export the object as a DOM node.
"""
+ self._encoding = self.context.getProperty('default_charset', 'utf-8')
+
node = self._doc.createElement('site')
node.appendChild(self._extractProperties())
@@ -49,6 +51,14 @@
def _importNode(self, node):
"""Import the object from the DOM node.
"""
+ for child in node.childNodes:
+ if child.nodeName != 'property':
+ continue
+ if child.getAttribute('name') != 'default_charset':
+ continue
+ self._encoding = self._getNodeText(child) or 'utf-8'
+ break
+
if self.environ.shouldPurge():
self._purgeProperties()
Modified: CMF/trunk/CMFCore/exportimport/tests/test_properties.py
===================================================================
--- CMF/trunk/CMFCore/exportimport/tests/test_properties.py 2007-01-16 10:49:54 UTC (rev 72048)
+++ CMF/trunk/CMFCore/exportimport/tests/test_properties.py 2007-01-16 11:06:30 UTC (rev 72049)
@@ -1,3 +1,4 @@
+# -*- coding: iso-8859-1 -*-
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
@@ -25,14 +26,16 @@
from Products.CMFCore.testing import ExportImportZCMLLayer
-_PROPERTIES_BODY = """\
+_PROPERTIES_BODY = u"""\
<?xml version="1.0"?>
<site>
<property name="title">Foo</property>
+ <property name="default_charset" type="string">iso-8859-1</property>
<property name="foo_string" type="string">foo</property>
+ <property name="bar_string" type="string">Bär</property>
<property name="foo_boolean" type="boolean">False</property>
</site>
-"""
+""".encode('utf-8')
_EMPTY_EXPORT = """\
<?xml version="1.0" ?>
@@ -68,9 +71,21 @@
def _populate(self, obj):
obj._setPropValue('title', 'Foo')
+ obj._setProperty('default_charset', 'iso-8859-1', 'string')
obj._setProperty('foo_string', 'foo', 'string')
+ obj._setProperty('bar_string', 'Bär', 'string')
obj._setProperty('foo_boolean', False, 'boolean')
+ def _verifyImport(self, obj):
+ self.assertEqual(type(obj.title), str)
+ self.assertEqual(obj.title, 'Foo')
+ self.assertEqual(type(obj.foo_string), str)
+ self.assertEqual(obj.foo_string, 'foo')
+ self.assertEqual(type(obj.bar_string), str)
+ self.assertEqual(obj.bar_string, 'Bär')
+ self.assertEqual(type(obj.foo_boolean), bool)
+ self.assertEqual(obj.foo_boolean, False)
+
def setUp(self):
from Products.CMFCore.PortalObject import PortalObjectBase
More information about the CMF-checkins
mailing list