1
##############################################################################
3
# Copyright (c) 2003 Zope Corporation and Contributors.
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
13
##############################################################################
14
"""ZCML special vocabulary directive handlers
16
$Id: metaconfigure.py 67630 2006-04-27 00:54:03Z jim $
19
from zope.interface import directlyProvides
20
from zope.schema.interfaces import IVocabularyFactory
21
from zope.component.zcml import utility
23
class FactoryKeywordPasser(object):
24
"""Helper that passes additional keywords to the actual factory."""
26
def __init__(self, factory, kwargs):
27
self.factory = factory
30
def __call__(self, object):
31
return self.factory(object, **self.kwargs)
34
# BBB 2006/02/24, to be removed after 12 months
35
def vocabulary(_context, name, factory, **kw):
37
dottedname = factory.__module__ + "." + factory.__name__
38
except AttributeError:
40
warnings.warn_explicit(
41
"The 'vocabulary' directive has been deprecated and will be "
42
"removed in Zope 3.5. Use the 'utility' directive instead to "
43
"register the class as a named utility:\n"
45
' provides="zope.schema.interfaces.IVocabularyFactory"\n'
48
' />' % (dottedname, name),
49
DeprecationWarning, _context.info.file, _context.info.line)
51
factory = FactoryKeywordPasser(factory, kw)
52
directlyProvides(factory, IVocabularyFactory)
53
utility(_context, IVocabularyFactory, factory, name=name)