-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate the <vocabulary /> directive.
Put IVocabularyFactory into a more public place (zope.app.schema.interfaces).
- Loading branch information
0 parents
commit e44e6b8
Showing
4 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2003 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""TTW Schema Interfaces | ||
$Id$ | ||
""" | ||
from zope.interface import Interface | ||
from zope.interface.interfaces import IInterface | ||
from zope.app.container.interfaces import IAdding | ||
|
||
class IVocabularyFactory(Interface): | ||
"""Can create vocabularies.""" | ||
|
||
def __call__(self, context): | ||
"""The context provides a location that the vocabulary can make use | ||
of.""" | ||
|
||
class ISchemaUtility(Interface): | ||
pass | ||
|
||
class ISchemaAdding(IAdding): | ||
pass | ||
|
||
class IReadMutableSchema(IInterface): | ||
"""This object represents an interface/schema that can be edited by | ||
managing the fields it contains.""" | ||
|
||
def getName(name): | ||
"""Get the name of the schema.""" | ||
|
||
class IWriteMutableSchema(Interface): | ||
"""This object represents an interface/schema that can be edited by | ||
managing the fields it contains.""" | ||
|
||
def setName(name): | ||
"""Set the name of the schema.""" | ||
|
||
def addField(name, field): | ||
"""Add a field to schema.""" | ||
|
||
def removeField(name): | ||
"""Remove field by name from the schema. | ||
If the field does not exist, raise an error. | ||
""" | ||
|
||
def renameField(orig_name, target_name): | ||
"""Rename a field. | ||
If the target_name is already taken, raise an error. | ||
""" | ||
|
||
def insertField(name, field, position): | ||
"""Insert a field with a given name at the specified position. | ||
If the position does not make sense, i.e. a negative number of a | ||
number larger than len(self), then an error is raised. | ||
""" | ||
|
||
def moveField(name, position): | ||
"""Move a field (given by its name) to a particular position. | ||
If the position does not make sense, i.e. a negative number of a | ||
number larger than len(self), then an error is raised. | ||
""" | ||
|
||
def moveField(name, position): | ||
"""Move a field (given by its name) to a particular position. | ||
If the position does not make sense, i.e. a negative number of a | ||
number larger than len(self), then an error is raised. | ||
""" | ||
|
||
def __setitem__(name, object): | ||
"""Add the given object to the container under the given name. | ||
""" | ||
|
||
def __delitem__(name): | ||
"""Delete the named object from the container. | ||
Raises a KeyError if the object is not found. | ||
""" | ||
|
||
class IMutableSchema(IReadMutableSchema, IWriteMutableSchema): | ||
"""This object represents an interface/schema that can be edited by | ||
managing the fields it contains.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2003 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""ZCML special vocabulary directive handlers | ||
$Id$ | ||
""" | ||
import warnings | ||
from zope.interface import directlyProvides | ||
from zope.app.schema.interfaces import IVocabularyFactory | ||
from zope.app.component.metaconfigure import utility | ||
|
||
class FactoryKeywordPasser(object): | ||
"""Helper that passes additional keywords to the actual factory.""" | ||
|
||
def __init__(self, factory, kwargs): | ||
self.factory = factory | ||
self.kwargs = kwargs | ||
|
||
def __call__(self, object): | ||
return self.factory(object, **self.kwargs) | ||
|
||
|
||
# BBB 2006/02/24, to be removed after 12 months | ||
def vocabulary(_context, name, factory, **kw): | ||
try: | ||
dottedname = factory.__module__ + "." + factory.__name__ | ||
except AttributeError: | ||
dottedname = '...' | ||
warnings.warn_explicit( | ||
"The 'vocabulary' directive has been deprecated and will be " | ||
"removed in Zope 3.5. Use the 'utility' directive instead to " | ||
"register the class as a named utility:\n" | ||
' <utility\n' | ||
' provides="zope.app.schema.interfaces.IVocabularyFactory"\n' | ||
' component="%s"\n' | ||
' name="%s"\n' | ||
' />' % (dottedname, name), | ||
DeprecationWarning, _context.info.file, _context.info.line) | ||
if kw: | ||
factory = FactoryKeywordPasser(factory, kw) | ||
directlyProvides(factory, IVocabularyFactory) | ||
utility(_context, IVocabularyFactory, factory, name=name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Renderer configuration code | ||
$Id$ | ||
""" | ||
from zope.configuration.fields import GlobalObject | ||
from zope.interface import Interface | ||
from zope.schema import TextLine | ||
|
||
# BBB 2006/02/24, to be removed after 12 months | ||
class IVocabularyDirective(Interface): | ||
'''Define a named vocabulary. | ||
This associates a vocabulary name in the global vocabulary registry with a | ||
factory. Each name may only be defined once. | ||
Additional keyword arguments may be passed to the factory by adding | ||
additional attributes beyond those listed here. This can be useful when | ||
using vocabularies which implement various kinds of filtering. | ||
Example:: | ||
<vocabulary | ||
name="garys-favorite-path-references" | ||
factory="zope.app.gary.paths.Favorites" /> | ||
''' | ||
|
||
name = TextLine( | ||
title=u"Name", | ||
description=u'Provides a title for the source type. The name of the ' \ | ||
u'vocabulary; this can be used as the value for the ' \ | ||
u'"vocabulary" argument to the Choice field ' \ | ||
u'constructor to cause this vocabulary to be used.', | ||
required=True) | ||
|
||
factory = GlobalObject( | ||
title=u"Factory", | ||
description=u"Factory that returns an instance of the named " \ | ||
u"vocabulary when called with the context object as " \ | ||
u"the only argument. This should be a dotted-name " \ | ||
u"that refers to a Python object.", | ||
required=True) | ||
|
||
|
||
# Arbitrary keys and values are allowed to be passed to the vocabulary source. | ||
IVocabularyDirective.setTaggedValue('keyword_arguments', True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2003 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Implementation of ZCML action to register vocabulary factories. | ||
$Id$ | ||
""" | ||
from zope.app import zapi | ||
from zope.interface import Interface, implements | ||
from zope.schema.interfaces import IVocabularyRegistry | ||
from zope.schema import vocabulary | ||
from zope.testing import cleanup | ||
from zope.app.schema.interfaces import IVocabularyFactory | ||
|
||
class ZopeVocabularyRegistry(object): | ||
"""IVocabularyRegistry that supports global and local utilities.""" | ||
|
||
implements(IVocabularyRegistry) | ||
__slots__ = () | ||
|
||
def get(self, context, name): | ||
"""See zope.schema.interfaces.IVocabularyRegistry""" | ||
factory = zapi.getUtility(IVocabularyFactory, name) | ||
return factory(context) | ||
|
||
def _clear(): | ||
"""Re-initialize the vocabulary registry.""" | ||
# This should normally only be needed by the testing framework, | ||
# but is also used for module initialization. | ||
global vocabularyRegistry | ||
vocabulary._clear() | ||
vocabularyRegistry = vocabulary.getVocabularyRegistry() | ||
vocabulary._clear() | ||
vocabulary.setVocabularyRegistry(ZopeVocabularyRegistry()) | ||
|
||
|
||
_clear() | ||
cleanup.addCleanUp(_clear) |