[Zope3-checkins] SVN: Zope3/branches/3.2/ - backported fixes for #99408 and #99402

Christian Theune ct at gocept.com
Sat Apr 21 05:48:55 EDT 2007


Log message for revision 74313:
   - backported fixes for #99408 and #99402
  

Changed:
  U   Zope3/branches/3.2/doc/CHANGES.txt
  A   Zope3/branches/3.2/src/zope/app/component/tests/test_vocabulary.py
  U   Zope3/branches/3.2/src/zope/app/component/vocabulary.py

-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt	2007-04-21 09:41:34 UTC (rev 74312)
+++ Zope3/branches/3.2/doc/CHANGES.txt	2007-04-21 09:48:55 UTC (rev 74313)
@@ -10,6 +10,12 @@
 
     Bug fixes
 
+      - #99408: zope.app.component.vocabulary.UtilityNames.getTermByToken was
+        broken
+
+      - #99402: zope.app.component.vocabulary.UtilityNameTerm was implement
+        the wrong interface incorrectly
+
       - zope.app.form.browser.textwidgets: The TextAreaWidget was not escaping
         its content when the validation failed. This way <, > and & were put
         out unquoted.

Added: Zope3/branches/3.2/src/zope/app/component/tests/test_vocabulary.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/component/tests/test_vocabulary.py	2007-04-21 09:41:34 UTC (rev 74312)
+++ Zope3/branches/3.2/src/zope/app/component/tests/test_vocabulary.py	2007-04-21 09:48:55 UTC (rev 74313)
@@ -0,0 +1,23 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Vocabulary tests
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import doctest
+
+
+def test_suite():
+    return doctest.DocTestSuite('zope.app.component.vocabulary')


Property changes on: Zope3/branches/3.2/src/zope/app/component/tests/test_vocabulary.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope3/branches/3.2/src/zope/app/component/vocabulary.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/component/vocabulary.py	2007-04-21 09:41:34 UTC (rev 74312)
+++ Zope3/branches/3.2/src/zope/app/component/vocabulary.py	2007-04-21 09:48:55 UTC (rev 74313)
@@ -23,7 +23,7 @@
 from zope.interface.interfaces import IInterface
 from zope.interface.verify import verifyObject
 from zope.schema.interfaces import IVocabulary, IVocabularyTokenized
-from zope.schema.interfaces import ITokenizedTerm
+from zope.schema.interfaces import ITokenizedTerm, ITitledTokenizedTerm
 
 from zope.app import zapi
 from zope.app.i18n import ZopeMessageFactory as _
@@ -236,35 +236,37 @@
     u'abc'
     >>> t2.value
     u'\xc0\xdf\xc7'
-    >>> t1.title()
+    >>> t1.title
     u'abc'
-    >>> repr(t2.title())
+    >>> repr(t2.title)
     "u'\\xc0\\xdf\\xc7'"
+    >>> ITitledTokenizedTerm.providedBy(t1)
+    True
 
     The tokens used for form values are Base-64 encodings of the
     names, with the letter 't' prepended to ensure the unnamed utility
     is supported:
 
-    >>> t1.token()
+    >>> t1.token
     'tYWJj'
-    >>> t2.token()
+    >>> t2.token
     'tw4DDn8OH'
 
-
     The unnamed utility is given an artificial title for use in user
     interfaces:
 
     >>> t3 = UtilityNameTerm(u'')
-    >>> t3.title()
+    >>> t3.title
     u'(unnamed utility)'
 
     """
 
-    implements(ITokenizedTerm)
+    implements(ITitledTokenizedTerm)
 
     def __init__(self, value):
         self.value = unicode(value)
 
+    @property
     def token(self):
         # Return our value as a token.  This is required to be 7-bit
         # printable ascii. We'll use base64 generated from the UTF-8
@@ -272,6 +274,7 @@
         # allowed to apply.)
         return "t" + self.value.encode('utf-8').encode('base64')[:-1]
 
+    @property
     def title(self):
         return self.value or _("(unnamed utility)")
 
@@ -287,6 +290,7 @@
 
     >>> vocab = UtilityNames(IMyUtility)
 
+    >>> from zope.schema.interfaces import IVocabulary
     >>> IVocabulary.providedBy(vocab)
     True
     >>> IVocabularyTokenized.providedBy(vocab)
@@ -319,9 +323,15 @@
     >>> u'' in vocab
     True
     >>> term1 = vocab.getTerm(u'')
-    >>> term2 = vocab.getTermByToken(term1.token())
+    >>> term2 = vocab.getTermByToken(term1.token)
     >>> term2.value
     u''
+    >>> term3 = vocab.getTerm(u'one')
+    >>> term3.token
+    'tb25l'
+    >>> term3a = vocab.getTermByToken('tb25l')
+    >>> term3.value
+    u'one'
 
     >>> placelesssetup.tearDown()
     """
@@ -345,7 +355,7 @@
             if token == "t":
                 if not name:
                     break
-            elif name.encode('utf-8').encode('base64')[:-1] == token:
+            elif UtilityNameTerm(name).token == token:
                 break
         else:
             raise LookupError("no matching token: %r" % token)



More information about the Zope3-Checkins mailing list