[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/ Don't bomb out with an AttributeError when encoding an attribute
Maurits van Rees
m.van.rees at zestsoftware.nl
Wed Mar 3 05:48:41 EST 2010
Log message for revision 109595:
Don't bomb out with an AttributeError when encoding an attribute
with value None that is being exported; just use an empty string then.
Case in point: create a Plone Site, set the MailHost settings through
the Site Setup; an export of the mailhost settings would then fail if
some of the values (e.g. smtp_uid) were blank (None).
Changed:
U Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
U Products.GenericSetup/trunk/Products/GenericSetup/MailHost/tests/test_exportimport.py
U Products.GenericSetup/trunk/Products/GenericSetup/utils.py
-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2010-03-03 10:35:41 UTC (rev 109594)
+++ Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt 2010-03-03 10:48:41 UTC (rev 109595)
@@ -4,6 +4,10 @@
1.6.0 (unreleased)
------------------
+- Don't bomb out with an AttributeError when encoding an attribute
+ with value None that is being exported; just use an empty string
+ then.
+
- Don't try to reinitialize a tool if an instance of the tool exists but the
desired tool class was not resolvable. Show a warning instead of failing.
Modified: Products.GenericSetup/trunk/Products/GenericSetup/MailHost/tests/test_exportimport.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/MailHost/tests/test_exportimport.py 2010-03-03 10:35:41 UTC (rev 109594)
+++ Products.GenericSetup/trunk/Products/GenericSetup/MailHost/tests/test_exportimport.py 2010-03-03 10:48:41 UTC (rev 109595)
@@ -55,9 +55,30 @@
self._BODY = _MAILHOST_BODY
+class MailHostXMLAdapterTestsWithNoneValue(MailHostXMLAdapterTests):
+ def _verifyImport(self, obj):
+ self.assertEqual(type(obj.smtp_host), str)
+ self.assertEqual(obj.smtp_host, 'localhost')
+ self.assertEqual(type(obj.smtp_port), int)
+ self.assertEqual(obj.smtp_port, 25)
+ self.assertEqual(type(obj.smtp_pwd), str)
+ self.assertEqual(obj.smtp_pwd, '')
+ self.assertEqual(type(obj.smtp_uid), str)
+ self.assertEqual(obj.smtp_uid, '')
+
+ def setUp(self):
+ from Products.MailHost.MailHost import MailHost
+
+ self._obj = MailHost('foo_mailhost')
+ self._obj.smtp_uid = None
+ self._BODY = _MAILHOST_BODY
+
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(MailHostXMLAdapterTests),
+ unittest.makeSuite(MailHostXMLAdapterTestsWithNoneValue),
))
if __name__ == '__main__':
Modified: Products.GenericSetup/trunk/Products/GenericSetup/utils.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/utils.py 2010-03-03 10:35:41 UTC (rev 109594)
+++ Products.GenericSetup/trunk/Products/GenericSetup/utils.py 2010-03-03 10:48:41 UTC (rev 109595)
@@ -351,7 +351,10 @@
for a_name in a_names:
wrapper.write()
- a_value = escape(attrs[a_name].value.encode('utf-8'), quote=True)
+ a_value = attrs[a_name].value
+ if a_value is None:
+ a_value = ''
+ a_value = escape(a_value.encode('utf-8'), quote=True)
wrapper.queue(' %s="%s"' % (a_name, a_value))
if self.childNodes:
More information about the checkins
mailing list