[Zope3-checkins] SVN: Zope3/trunk/ - Added a new interface
decorator to zope.interface that allows the
Christian Theune
ct at gocept.com
Fri Sep 8 18:09:28 EDT 2006
Log message for revision 70082:
- Added a new interface decorator to zope.interface that allows the
setting tagged values on an interface at definition time (see
zope.interface.taggedValue).
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/interface/README.txt
U Zope3/trunk/src/zope/interface/__init__.py
U Zope3/trunk/src/zope/interface/interface.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2006-09-08 22:06:06 UTC (rev 70081)
+++ Zope3/trunk/doc/CHANGES.txt 2006-09-08 22:09:27 UTC (rev 70082)
@@ -10,6 +10,10 @@
New features
+ - Added a new interface decorator to zope.interface that allows the
+ setting tagged values on an interface at definition time (see
+ zope.interface.taggedValue).
+
- Added new Decimal field type to zope.schema (and DecimalWidget in
zope.app.form)
Modified: Zope3/trunk/src/zope/interface/README.txt
===================================================================
--- Zope3/trunk/src/zope/interface/README.txt 2006-09-08 22:06:06 UTC (rev 70081)
+++ Zope3/trunk/src/zope/interface/README.txt 2006-09-08 22:09:27 UTC (rev 70082)
@@ -606,7 +606,13 @@
>>> IBazFactory['__call__'].getTaggedValue('return_type')
<InterfaceClass __main__.IBaz>
+Tagged values can also be defined from within an interface definition:
+ >>> class IWithTaggedValues(zope.interface.Interface):
+ ... zope.interface.taggedValue('squish', 'squash')
+ >>> IWithTaggedValues.getTaggedValue('squish')
+ 'squash'
+
Invariants
==========
Modified: Zope3/trunk/src/zope/interface/__init__.py
===================================================================
--- Zope3/trunk/src/zope/interface/__init__.py 2006-09-08 22:06:06 UTC (rev 70081)
+++ Zope3/trunk/src/zope/interface/__init__.py 2006-09-08 22:09:27 UTC (rev 70082)
@@ -58,7 +58,7 @@
_wire()
del _wire
-from zope.interface.interface import Attribute, invariant
+from zope.interface.interface import Attribute, invariant, taggedValue
from zope.interface.declarations import providedBy, implementedBy
from zope.interface.declarations import classImplements, classImplementsOnly
Modified: Zope3/trunk/src/zope/interface/interface.py
===================================================================
--- Zope3/trunk/src/zope/interface/interface.py 2006-09-08 22:06:06 UTC (rev 70081)
+++ Zope3/trunk/src/zope/interface/interface.py 2006-09-08 22:09:27 UTC (rev 70082)
@@ -25,6 +25,7 @@
from ro import ro
from zope.interface.exceptions import Invalid
+
CO_VARARGS = 4
CO_VARKEYWORDS = 8
TAGGED_DATA = '__interface_tagged_values__'
@@ -38,6 +39,15 @@
invariants.append(call)
return _decorator_non_return
+
+def taggedValue(key, value):
+ """Attaches a tagged value to an interface at definition time."""
+ f_locals = sys._getframe(1).f_locals
+ tagged_values = f_locals.setdefault(TAGGED_DATA, {})
+ tagged_values[key] = value
+ return _decorator_non_return
+
+
class Element(object):
# We can't say this yet because we don't have enough
More information about the Zope3-Checkins
mailing list