[CMF-checkins] SVN: CMF/trunk/CMFSetup/ Merged 40143 from 1.5 branch:

Florent Guillaume fg at nuxeo.com
Tue Nov 15 18:13:20 EST 2005


Log message for revision 40144:
  Merged 40143 from 1.5 branch:
  CMFSetup: fixed empty attribute parsing when an encoding is defined.
  
  

Changed:
  U   CMF/trunk/CMFSetup/tests/test_utils.py
  U   CMF/trunk/CMFSetup/utils.py

-=-
Modified: CMF/trunk/CMFSetup/tests/test_utils.py
===================================================================
--- CMF/trunk/CMFSetup/tests/test_utils.py	2005-11-15 23:01:55 UTC (rev 40143)
+++ CMF/trunk/CMFSetup/tests/test_utils.py	2005-11-15 23:13:19 UTC (rev 40144)
@@ -167,6 +167,11 @@
 </dummy>
 """
 
+_EMPTY_ATTR_IMPORT = """\
+<?xml version="1.0"?>
+<dummy title="">
+</dummy>
+"""
 
 class DummyObject(Folder):
 
@@ -301,7 +306,10 @@
                 return {
                   'dummy':
                     { 'property':    {KEY: 'properties', DEFAULT: ()},
-                      'description': {CONVERTER: self._convertToUnique} } }
+                      'description': {CONVERTER: self._convertToUnique},
+                      'title': {},
+                      '#text': {KEY: 'text'},
+                      } }
 
         return Configurator
 
@@ -404,10 +412,20 @@
             self.fail('CMF Collector issue #352 (comment or empty '
                       'description bug): KeyError raised')
 
-        self.assertEqual( len(site_info), 2 )
+        self.assertEqual( len(site_info), 3 )
         self.assertEqual( site_info['description'], '' )
         self.assertEqual( len(site_info['properties']), 0 )
+        self.assertEqual( site_info['text'], '' )
 
+    def test_parseXML_empty_with_encoding(self):
+        site = self._initSite()
+        configurator = self._makeOne(site, encoding='latin-1')
+        site_info = configurator.parseXML(_EMPTY_ATTR_IMPORT)
+        self.assertEqual(site_info['title'], '')
+        self.assertEqual(type(site_info['title']), str)
+        self.assertEqual(site_info['text'], '')
+        self.assertEqual(type(site_info['text']), str)
+
     def test_initProperty_normal(self):
 
         EXPECTED = _NORMAL_PROPERTY_INFO

Modified: CMF/trunk/CMFSetup/utils.py
===================================================================
--- CMF/trunk/CMFSetup/utils.py	2005-11-15 23:01:55 UTC (rev 40143)
+++ CMF/trunk/CMFSetup/utils.py	2005-11-15 23:13:19 UTC (rev 40144)
@@ -74,7 +74,8 @@
 
         for name, val in node.attributes.items():
             key = node_map[name].get( KEY, str(name) )
-            val = self._encoding and val.encode(self._encoding) or val
+            if self._encoding is not None:
+                val = val.encode(self._encoding)
             info[key] = val
 
         for child in node.childNodes:
@@ -91,7 +92,8 @@
             elif '#text' in node_map:
                 key = node_map['#text'].get(KEY, 'value')
                 val = child.nodeValue.lstrip()
-                val = self._encoding and val.encode(self._encoding) or val
+                if self._encoding is not None:
+                    val = val.encode(self._encoding)
                 info[key] = info.setdefault(key, '') + val
 
         for k, v in node_map.items():



More information about the CMF-checkins mailing list