[Zope3-checkins] SVN: zope.formlib/trunk/ Fixed Action name parameter handling, since 4.0.3 all passed names were lowercased.

Adam Groszer agroszer at gmail.com
Thu Sep 16 07:43:02 EDT 2010


Log message for revision 116437:
  Fixed Action name parameter handling, since 4.0.3 all passed names were lowercased.
  

Changed:
  U   zope.formlib/trunk/CHANGES.txt
  U   zope.formlib/trunk/buildout.cfg
  U   zope.formlib/trunk/src/zope/formlib/form.py
  U   zope.formlib/trunk/src/zope/formlib/tests/test_formlib.py

-=-
Modified: zope.formlib/trunk/CHANGES.txt
===================================================================
--- zope.formlib/trunk/CHANGES.txt	2010-09-15 14:50:48 UTC (rev 116436)
+++ zope.formlib/trunk/CHANGES.txt	2010-09-16 11:43:02 UTC (rev 116437)
@@ -5,6 +5,8 @@
 4.0.5 (unreleased)
 ==================
 
+- Fixed Action name parameter handling, since 4.0.3 all passed names were
+  lowercased.
 
 4.0.4 (2010-07-06)
 ==================

Modified: zope.formlib/trunk/buildout.cfg
===================================================================
--- zope.formlib/trunk/buildout.cfg	2010-09-15 14:50:48 UTC (rev 116436)
+++ zope.formlib/trunk/buildout.cfg	2010-09-16 11:43:02 UTC (rev 116437)
@@ -1,6 +1,6 @@
 [buildout]
 develop = .
-parts = test python
+parts = test python coverage-test coverage-report
 
 [test]
 recipe = zc.recipe.testrunner
@@ -10,3 +10,14 @@
 recipe = zc.recipe.egg
 eggs = zope.formlib
 interpreter = python
+
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = ${test:eggs}
+defaults = ['--coverage', '../../coverage']
+
+[coverage-report]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+scripts = coverage=coverage-report
+arguments = ('coverage', 'coverage/report')
\ No newline at end of file

Modified: zope.formlib/trunk/src/zope/formlib/form.py
===================================================================
--- zope.formlib/trunk/src/zope/formlib/form.py	2010-09-15 14:50:48 UTC (rev 116436)
+++ zope.formlib/trunk/src/zope/formlib/form.py	2010-09-16 11:43:02 UTC (rev 116437)
@@ -566,13 +566,13 @@
         self.setName(name)
         self.bindMethods(success_handler=success,
                         failure_handler=failure,
-                        condition=condition, 
+                        condition=condition,
                         validator=validator)
 
         if data is None:
             data = {}
         self.data = data
-        
+
     def bindMethods(self, **methods):
         """Bind methods to the action"""
         for k, v in methods.items():
@@ -584,15 +584,15 @@
         """
         if name is None:
             name = self.label
-        if self._identifier.match(name):
-            name = name.lower()
-        else:
-            if isinstance(name, unicode):
-                name = name.encode("utf-8")
-            name = name.encode('hex')
+            if self._identifier.match(name):
+                name = name.lower()
+            else:
+                if isinstance(name, unicode):
+                    name = name.encode("utf-8")
+                name = name.encode('hex')
         self.name = name
         self.__name__ = self.prefix + name
- 
+
     def setPrefix(self, prefix):
         """Set prefix"""
         self.prefix = expandPrefix(prefix)

Modified: zope.formlib/trunk/src/zope/formlib/tests/test_formlib.py
===================================================================
--- zope.formlib/trunk/src/zope/formlib/tests/test_formlib.py	2010-09-15 14:50:48 UTC (rev 116436)
+++ zope.formlib/trunk/src/zope/formlib/tests/test_formlib.py	2010-09-16 11:43:02 UTC (rev 116437)
@@ -518,7 +518,118 @@
 
     """
 
+def check_action_name():
+    """
+We want to make sure that Action name setting adheres to the specification.
 
+With just label, with increasing complexity:
+
+    >>> action = zope.formlib.form.Action("MyAction")
+    >>> action.name
+    'myaction'
+
+    >>> action = zope.formlib.form.Action("8 Balls")
+    >>> action.name
+    '382042616c6c73'
+
+    >>> action = zope.formlib.form.Action(u"MyAction")
+    >>> action.name
+    u'myaction'
+
+    >>> action = zope.formlib.form.Action(u"8 Balls")
+    >>> action.name
+    '382042616c6c73'
+
+    >>> action = zope.formlib.form.Action(u'\u9001\u4fe1')
+    >>> action.name
+    'e98081e4bfa1'
+
+    >>> import zope.i18nmessageid
+    >>> _ = zope.i18nmessageid.MessageFactory('my.domain')
+
+    >>> action = zope.formlib.form.Action(_(u"MyAction"))
+    >>> action.name
+    u'myaction'
+
+    >>> action = zope.formlib.form.Action(_(u"8 Balls"))
+    >>> action.name
+    '382042616c6c73'
+
+    >>> action = zope.formlib.form.Action(_(u'\u9001\u4fe1'))
+    >>> action.name
+    'e98081e4bfa1'
+
+With all lowercase name:
+
+    >>> action = zope.formlib.form.Action("MyAction", name='foobar')
+    >>> action.name
+    'foobar'
+
+    >>> action = zope.formlib.form.Action("8 Balls", name='foobar')
+    >>> action.name
+    'foobar'
+
+    >>> action = zope.formlib.form.Action(u"MyAction", name='foobar')
+    >>> action.name
+    'foobar'
+
+    >>> action = zope.formlib.form.Action(u"8 Balls", name='foobar')
+    >>> action.name
+    'foobar'
+
+    >>> action = zope.formlib.form.Action(u'\u9001\u4fe1', name='foobar')
+    >>> action.name
+    'foobar'
+
+    >>> action = zope.formlib.form.Action(_(u"MyAction"), name='foobar')
+    >>> action.name
+    'foobar'
+
+    >>> action = zope.formlib.form.Action(_(u"8 Balls"), name='foobar')
+    >>> action.name
+    'foobar'
+
+    >>> action = zope.formlib.form.Action(_(u'\u9001\u4fe1'), name='foobar')
+    >>> action.name
+    'foobar'
+
+With some uppercase name:
+
+    >>> action = zope.formlib.form.Action("MyAction", name='FooBar')
+    >>> action.name
+    'FooBar'
+
+    >>> action = zope.formlib.form.Action("8 Balls", name='FooBar')
+    >>> action.name
+    'FooBar'
+
+    >>> action = zope.formlib.form.Action(u"MyAction", name='FooBar')
+    >>> action.name
+    'FooBar'
+
+    >>> action = zope.formlib.form.Action(u"8 Balls", name='FooBar')
+    >>> action.name
+    'FooBar'
+
+    >>> action = zope.formlib.form.Action(u'\u9001\u4fe1', name='FooBar')
+    >>> action.name
+    'FooBar'
+
+    >>> action = zope.formlib.form.Action(_(u"MyAction"), name='FooBar')
+    >>> action.name
+    'FooBar'
+
+    >>> action = zope.formlib.form.Action(_(u"8 Balls"), name='FooBar')
+    >>> action.name
+    'FooBar'
+
+    >>> action = zope.formlib.form.Action(_(u'\u9001\u4fe1'), name='FooBar')
+    >>> action.name
+    'FooBar'
+
+"""
+
+
 def test_suite():
     import doctest
     checker = zope.testing.renormalizing.RENormalizing([
@@ -559,4 +670,3 @@
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')
-



More information about the Zope3-Checkins mailing list