summaryrefslogtreecommitdiff
path: root/src/zope/interface/declarations.py
diff options
context:
space:
mode:
authorStephan Richter <stephan.richter@gmail.com>2014-02-04 23:21:42 -0500
committerStephan Richter <stephan.richter@gmail.com>2014-02-04 23:21:42 -0500
commit79a266200384fa53fb3810ed316a94394166f4e3 (patch)
treefbbe989594e10ea3a34752a1b6023b03c2dfd92c /src/zope/interface/declarations.py
parentffcf2887646c268c104ee2aa7bb3c087d691149b (diff)
downloadzope-interface-79a266200384fa53fb3810ed316a94394166f4e3.tar.gz
Added ``@named(name)`` declaration.
The decorator specifies the component name, so it does not have to be passed in during registration. This in turn allows developers to define component names once globally and use it everywhere, especially when using ZCML where the name had to be specified a second time.
Diffstat (limited to 'src/zope/interface/declarations.py')
-rw-r--r--src/zope/interface/declarations.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/zope/interface/declarations.py b/src/zope/interface/declarations.py
index 0992adc..06b1688 100644
--- a/src/zope/interface/declarations.py
+++ b/src/zope/interface/declarations.py
@@ -49,6 +49,15 @@ _ADVICE_ERROR = ('Class advice impossible in Python3. '
_ADVICE_WARNING = ('The %s API is deprecated, and will not work in Python3 '
'Use the @%s class decorator instead.')
+class named(object):
+
+ def __init__(self, name):
+ self.name = name
+
+ def __call__(self, ob):
+ ob.__component_name__ = self.name
+ return ob
+
class Declaration(Specification):
"""Interface declarations"""