[Zope3-checkins] SVN: Zope3/trunk/ Fixes for #99402 and #99408.
Christian Theune
ct at gocept.com
Sat Apr 21 05:32:39 EDT 2007
Log message for revision 74311:
Fixes for #99402 and #99408.
Changed:
U Zope3/trunk/doc/CHANGES.txt
A Zope3/trunk/src/zope/app/component/tests/test_vocabulary.py
U Zope3/trunk/src/zope/app/component/vocabulary.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2007-04-21 09:24:01 UTC (rev 74310)
+++ Zope3/trunk/doc/CHANGES.txt 2007-04-21 09:32:39 UTC (rev 74311)
@@ -10,6 +10,12 @@
Bugs fixed
+ - #99408: zope.app.component.vocabulary.UtilityNames.getTermByToken was
+ broken
+
+ - #99402: zope.app.component.vocabulary.UtilityNameTerm was implement
+ the wrong interface incorrectly
+
------------------------------------------------------------------
Zope 3.4.0a1 (2007/04/19)
Added: Zope3/trunk/src/zope/app/component/tests/test_vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/app/component/tests/test_vocabulary.py 2007-04-21 09:24:01 UTC (rev 74310)
+++ Zope3/trunk/src/zope/app/component/tests/test_vocabulary.py 2007-04-21 09:32:39 UTC (rev 74311)
@@ -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/trunk/src/zope/app/component/tests/test_vocabulary.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/app/component/vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/app/component/vocabulary.py 2007-04-21 09:24:01 UTC (rev 74310)
+++ Zope3/trunk/src/zope/app/component/vocabulary.py 2007-04-21 09:32:39 UTC (rev 74311)
@@ -23,7 +23,8 @@
from zope.interface import implements, classProvides, Interface
from zope.interface.interfaces import IInterface
from zope.schema.interfaces import IVocabularyTokenized
-from zope.schema.interfaces import ITokenizedTerm, IVocabularyFactory
+from zope.schema.interfaces import ITokenizedTerm, ITitledTokenizedTerm
+from zope.schema.interfaces import IVocabularyFactory
from zope.app.component.i18n import ZopeMessageFactory as _
from zope.app.interface.vocabulary import ObjectInterfacesVocabulary
@@ -252,35 +253,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
@@ -288,6 +291,7 @@
# allowed to apply.)
return "t" + self.value.encode('utf-8').encode('base64')[:-1]
+ @property
def title(self):
return self.value or _("(unnamed utility)")
@@ -303,6 +307,7 @@
>>> vocab = UtilityNames(IMyUtility)
+ >>> from zope.schema.interfaces import IVocabulary
>>> IVocabulary.providedBy(vocab)
True
>>> IVocabularyTokenized.providedBy(vocab)
@@ -335,9 +340,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()
"""
@@ -361,7 +372,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