[CMF-checkins] SVN: CMF/branches/1.5/C CMFSetup: fixed empty attribute parsing when an encoding is defined.

Florent Guillaume fg at nuxeo.com
Tue Nov 15 18:01:55 EST 2005


Log message for revision 40143:
  CMFSetup: fixed empty attribute parsing when an encoding is defined.

Changed:
  U   CMF/branches/1.5/CHANGES.txt
  U   CMF/branches/1.5/CMFSetup/tests/test_utils.py
  U   CMF/branches/1.5/CMFSetup/utils.py

-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt	2005-11-15 21:10:43 UTC (rev 40142)
+++ CMF/branches/1.5/CHANGES.txt	2005-11-15 23:01:55 UTC (rev 40143)
@@ -14,6 +14,9 @@
       in the list of events for the day starting at midnight.
       (http://www.zope.org/Collectors/CMF/246)
 
+    - CMFSetup: fixed empty attribute parsing when an encoding is
+      defined.
+
   Features
 
     - CMFCore:  added 'skinname' to the thread-specific tuple created by

Modified: CMF/branches/1.5/CMFSetup/tests/test_utils.py
===================================================================
--- CMF/branches/1.5/CMFSetup/tests/test_utils.py	2005-11-15 21:10:43 UTC (rev 40142)
+++ CMF/branches/1.5/CMFSetup/tests/test_utils.py	2005-11-15 23:01:55 UTC (rev 40143)
@@ -169,6 +169,12 @@
 </dummy>
 """
 
+_EMPTY_ATTR_IMPORT = """\
+<?xml version="1.0"?>
+<dummy title="">
+</dummy>
+"""
+
 def _testFunc( *args, **kw ):
 
     """ This is a test.
@@ -358,7 +364,10 @@
                 return {
                   'dummy':
                     { 'property':    {KEY: 'properties', DEFAULT: ()},
-                      'description': {CONVERTER: self._convertToUnique} } }
+                      'description': {CONVERTER: self._convertToUnique},
+                      'title': {},
+                      '#text': {KEY: 'text'},
+                      } }
 
         return Configurator
 
@@ -461,10 +470,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/branches/1.5/CMFSetup/utils.py
===================================================================
--- CMF/branches/1.5/CMFSetup/utils.py	2005-11-15 21:10:43 UTC (rev 40142)
+++ CMF/branches/1.5/CMFSetup/utils.py	2005-11-15 23:01:55 UTC (rev 40143)
@@ -171,7 +171,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:
@@ -188,7 +189,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