[Checkins] SVN: Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/content.py use function to avoid repetition

Godefroid Chapelle gotcha at bubblenet.be
Thu Jan 13 10:56:13 EST 2011


Log message for revision 119567:
  use function to avoid repetition

Changed:
  U   Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/content.py

-=-
Modified: Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/content.py
===================================================================
--- Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/content.py	2011-01-13 15:38:42 UTC (rev 119566)
+++ Products.CMFCore/branches/2.2/Products/CMFCore/exportimport/content.py	2011-01-13 15:56:12 UTC (rev 119567)
@@ -37,6 +37,16 @@
     IFilesystemImporter(context.getSite()).import_(context, 'structure', True)
 
 
+def encode_if_needed(text, encoding):
+    if isinstance(text, unicode):
+        result = text.encode(encoding)
+    else:
+        # no need to encode;
+        # let's avoid double encoding in case of encoded string
+        result = text
+    return result
+
+
 #
 #   Filesystem export/import adapters
 #
@@ -101,17 +111,10 @@
         parser = ConfigParser()
 
         title = self.context.Title()
-        if isinstance(title, unicode):
-            title_str = title.encode(self._encoding)
-        else:
-            # avoid double encoding in case of encoded string
-            title_str = title
         description = self.context.Description()
-        if isinstance(description, unicode):
-            description_str = description.encode(self._encoding)
-        else:
-            # avoid double encoding in case of encoded string
-            description_str = description
+        # encode if needed; ConfigParser does not support unicode !
+        title_str = encode_if_needed(title, self._encoding)
+        description_str = encode_if_needed(description, self._encoding)
         parser.set('DEFAULT', 'Title', title_str)
         parser.set('DEFAULT', 'Description', description_str)
 



More information about the checkins mailing list