From 79a266200384fa53fb3810ed316a94394166f4e3 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Tue, 4 Feb 2014 23:21:42 -0500 Subject: 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. --- src/zope/interface/declarations.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/zope/interface/declarations.py') 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""" -- cgit v1.2.1