[Checkins] SVN: Products.CMFCore/branches/2.2/Products/CMFCore/ Fix content exportimport when Title or Description are unicode.
Godefroid Chapelle
gotcha at bubblenet.be
Thu Jan 13 05:44:41 EST 2011
Log message for revision 119560:
Fix content exportimport when Title or Description are unicode.
Changed:
U Products.CMFCore/branches/2.2/Products/CMFCore/CHANGES.txt
U Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/content.py
U Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/tests/test_content.py
-=-
Modified: Products.CMFCore/branches/2.2/Products/CMFCore/CHANGES.txt
===================================================================
--- Products.CMFCore/branches/2.2/Products/CMFCore/CHANGES.txt 2011-01-13 10:18:16 UTC (rev 119559)
+++ Products.CMFCore/branches/2.2/Products/CMFCore/CHANGES.txt 2011-01-13 10:44:41 UTC (rev 119560)
@@ -4,6 +4,7 @@
2.2.4 (unreleased)
------------------
+- Fix content exportimport when Title or Description are unicode.
2.2.3 (2010-10-31)
------------------
Modified: Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/content.py
===================================================================
--- Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/content.py 2011-01-13 10:18:16 UTC (rev 119559)
+++ Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/content.py 2011-01-13 10:44:41 UTC (rev 119560)
@@ -76,6 +76,8 @@
def export(self, export_context, subdir, root=False):
""" See IFilesystemExporter.
"""
+ self._encoding = self.context.getProperty('default_charset', 'utf-8')
+
# Enumerate exportable children
exportable = self.context.contentItems()
exportable = [x + (IFilesystemExporter(x, None),) for x in exportable]
@@ -98,8 +100,19 @@
parser = ConfigParser()
- parser.set('DEFAULT', 'Title', self.context.Title())
- parser.set('DEFAULT', 'Description', self.context.Description())
+ title = self.context.Title()
+ if isinstance(title, unicode):
+ title_str = title.encode(self._encoding)
+ else:
+ title_str = title
+ description = self.context.Description()
+ if isinstance(description, unicode):
+ description_str = description.encode(self._encoding)
+ else:
+ description_str = description
+ parser.set('DEFAULT', 'Title', title_str)
+ parser.set('DEFAULT', 'Description', description_str)
+
stream = StringIO()
parser.write(stream)
Modified: Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/tests/test_content.py
===================================================================
--- Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/tests/test_content.py 2011-01-13 10:18:16 UTC (rev 119559)
+++ Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/tests/test_content.py 2011-01-13 10:44:41 UTC (rev 119560)
@@ -229,6 +229,103 @@
self.assertEqual(parser.get('DEFAULT', 'title'), 'AAA')
self.assertEqual(parser.get('DEFAULT', 'description'), 'DESCRIPTION')
+ def test_export_site_with_exportable_simple_items_unicode_default_charset(self):
+ self._setUpAdapters()
+ ITEM_IDS = ('foo', 'bar', 'baz')
+
+ site = _makeFolder('site', site_folder=True)
+ site.title = 'AAA'
+ site.description = 'DESCRIPTION'
+ ITEMS_TITLE = u'Actualit\xe9'
+ ITEMS_DESCRIPTION = u'Actualit\xe9 r\xe9centes'
+ for id in ITEM_IDS:
+ site._setObject(id, _makeINIAware(id))
+ item = getattr(site, id)
+ item.setTitle(ITEMS_TITLE)
+ item.setDescription(ITEMS_DESCRIPTION)
+
+ context = DummyExportContext(site)
+ exporter = self._getExporter()
+ exporter(context)
+
+ self.assertEqual(len(context._wrote), 2 + len(ITEM_IDS))
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'structure/.objects')
+ self.assertEqual(content_type, 'text/comma-separated-values')
+
+ objects = [x for x in reader(StringIO(text))]
+ self.assertEqual(len(objects), 3)
+ for index in range(len(ITEM_IDS)):
+ self.assertEqual(objects[index][0], ITEM_IDS[index])
+ self.assertEqual(objects[index][1], TEST_INI_AWARE)
+
+ filename, text, content_type = context._wrote[index+2]
+ self.assertEqual(filename, 'structure/%s.ini' % ITEM_IDS[index])
+ object = site._getOb(ITEM_IDS[index])
+ self.assertEqual(text.strip(),
+ object.as_ini().strip())
+ self.assertEqual(content_type, 'text/plain')
+
+ filename, text, content_type = context._wrote[1]
+ self.assertEqual(filename, 'structure/.properties')
+ self.assertEqual(content_type, 'text/plain')
+ parser = ConfigParser()
+ parser.readfp(StringIO(text))
+
+ self.assertEqual(parser.get('DEFAULT', 'title'),
+ ITEMS_TITLE.encode('utf8'))
+ self.assertEqual(parser.get('DEFAULT', 'description'),
+ ITEMS_DESCRIPTION.encode('utf8'))
+
+ def test_export_site_with_exportable_simple_items_unicode_latin1(self):
+ self._setUpAdapters()
+ ITEM_IDS = ('foo', 'bar', 'baz')
+
+ site = _makeFolder('site', site_folder=True)
+ site._setProperty('default_charset', 'iso-8859-1', 'string')
+ site.title = 'AAA'
+ site.description = 'DESCRIPTION'
+ ITEMS_TITLE = u'Actualit\xe9'
+ ITEMS_DESCRIPTION = u'Actualit\xe9 r\xe9centes'
+ for id in ITEM_IDS:
+ site._setObject(id, _makeINIAware(id))
+ item = getattr(site, id)
+ item.setTitle(ITEMS_TITLE)
+ item.setDescription(ITEMS_DESCRIPTION)
+
+ context = DummyExportContext(site)
+ exporter = self._getExporter()
+ exporter(context)
+
+ self.assertEqual(len(context._wrote), 2 + len(ITEM_IDS))
+ filename, text, content_type = context._wrote[0]
+ self.assertEqual(filename, 'structure/.objects')
+ self.assertEqual(content_type, 'text/comma-separated-values')
+
+ objects = [x for x in reader(StringIO(text))]
+ self.assertEqual(len(objects), 3)
+ for index in range(len(ITEM_IDS)):
+ self.assertEqual(objects[index][0], ITEM_IDS[index])
+ self.assertEqual(objects[index][1], TEST_INI_AWARE)
+
+ filename, text, content_type = context._wrote[index+2]
+ self.assertEqual(filename, 'structure/%s.ini' % ITEM_IDS[index])
+ object = site._getOb(ITEM_IDS[index])
+ self.assertEqual(text.strip(),
+ object.as_ini().strip())
+ self.assertEqual(content_type, 'text/plain')
+
+ filename, text, content_type = context._wrote[1]
+ self.assertEqual(filename, 'structure/.properties')
+ self.assertEqual(content_type, 'text/plain')
+ parser = ConfigParser()
+ parser.readfp(StringIO(text))
+
+ self.assertEqual(parser.get('DEFAULT', 'title'),
+ ITEMS_TITLE.encode('latin1'))
+ self.assertEqual(parser.get('DEFAULT', 'description'),
+ ITEMS_DESCRIPTION.encode('latin1'))
+
def test_export_site_with_subfolders(self):
self._setUpAdapters()
FOLDER_IDS = ('foo', 'bar', 'baz')
More information about the checkins
mailing list