~menesis/ubuntu/natty/zope.app.schema/natty

« back to all changes in this revision

Viewing changes to src/zope/app/schema/metaconfigure.py

  • Committer: Gediminas Paulauskas
  • Author(s): Brian Sutherland
  • Date: 2007-11-08 17:27:48 UTC
  • Revision ID: menesis@pov.lt-20071108172748-2yg2z58jbj9u8tmf
Tags: upstream-3.4.0
ImportĀ upstreamĀ versionĀ 3.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2003 Zope Corporation and Contributors.
 
4
# All Rights Reserved.
 
5
#
 
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.
 
12
#
 
13
##############################################################################
 
14
"""ZCML special vocabulary directive handlers
 
15
 
 
16
$Id: metaconfigure.py 67630 2006-04-27 00:54:03Z jim $
 
17
"""
 
18
import warnings
 
19
from zope.interface import directlyProvides
 
20
from zope.schema.interfaces import IVocabularyFactory
 
21
from zope.component.zcml import utility
 
22
 
 
23
class FactoryKeywordPasser(object):
 
24
    """Helper that passes additional keywords to the actual factory."""
 
25
 
 
26
    def __init__(self, factory, kwargs):
 
27
        self.factory = factory
 
28
        self.kwargs = kwargs
 
29
 
 
30
    def __call__(self, object):
 
31
        return self.factory(object, **self.kwargs)
 
32
 
 
33
 
 
34
# BBB 2006/02/24, to be removed after 12 months
 
35
def vocabulary(_context, name, factory, **kw):
 
36
    try:
 
37
        dottedname = factory.__module__ + "." + factory.__name__
 
38
    except AttributeError:
 
39
        dottedname = '...'
 
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"
 
44
        '  <utility\n'
 
45
        '      provides="zope.schema.interfaces.IVocabularyFactory"\n'
 
46
        '      component="%s"\n'
 
47
        '      name="%s"\n'
 
48
        '      />' % (dottedname, name),
 
49
        DeprecationWarning, _context.info.file, _context.info.line)
 
50
    if kw:
 
51
        factory = FactoryKeywordPasser(factory, kw)
 
52
    directlyProvides(factory, IVocabularyFactory)
 
53
    utility(_context, IVocabularyFactory, factory, name=name)