[Checkins] SVN: Zope/trunk/ Cloned ``ZopeVocabularyRegistry`` from ``zope.app.schema``.
Hanno Schlichting
hanno at hannosch.eu
Fri Sep 18 18:46:19 EDT 2009
Hi.
Wouldn't it make sense to move the VocabularyRegistry class into
zope.schema instead of forking it?
Hanno
On Sat, Sep 19, 2009 at 12:40 AM, Tres Seaver <tseaver at palladion.com> wrote:
> Log message for revision 104366:
> Cloned ``ZopeVocabularyRegistry`` from ``zope.app.schema``.
>
> o Added "sane" registration of it during initialization of Five, instead
> of registering it via import side effects.
>
>
> Changed:
> U Zope/trunk/ZOPE_APP_DEPENDENCIES.rst
> U Zope/trunk/doc/CHANGES.rst
> U Zope/trunk/src/Products/Five/__init__.py
> A Zope/trunk/src/Products/Five/schema.py
> A Zope/trunk/src/Products/Five/tests/test_schema.py
>
> -=-
> Modified: Zope/trunk/ZOPE_APP_DEPENDENCIES.rst
> ===================================================================
> --- Zope/trunk/ZOPE_APP_DEPENDENCIES.rst 2009-09-18 22:27:17 UTC (rev 104365)
> +++ Zope/trunk/ZOPE_APP_DEPENDENCIES.rst 2009-09-18 22:40:23 UTC (rev 104366)
> @@ -39,13 +39,13 @@
> * Products.Five.form.metaconfigure (for ``menuItemDirective``)
> * Products.Five.fivedirectives (for ``IBasicResourceInformation``)
>
> -- [_] zope.app.schema
> - o Products.Five (imports ``zope.app.schema.vocabulary`` for
> +- [X] zope.app.schema
> + * Products.Five (imports ``zope.app.schema.vocabulary`` for
> side-effects ?!).
>
> -- [_] zope.app.twisted
> - o Zope2.Startup.datatypes (conditionally imports ``ServerFactory``)
> - o Zope2.Startup.handlers (conditionally imports ``ServerType``,
> +- [X] zope.app.twisted
> + * Zope2.Startup.datatypes (conditionally imports ``ServerFactory``)
> + * Zope2.Startup.handlers (conditionally imports ``ServerType``,
> ``SSLServerType``, ``IServerType``; worse, conditionally imports
> ``zope.app.twisted.main`` for side effects, which includes pulling
> back ``zope.app.appsetup`` as well as adding ``zope.app.wsgi``?!)
>
> Modified: Zope/trunk/doc/CHANGES.rst
> ===================================================================
> --- Zope/trunk/doc/CHANGES.rst 2009-09-18 22:27:17 UTC (rev 104365)
> +++ Zope/trunk/doc/CHANGES.rst 2009-09-18 22:40:23 UTC (rev 104366)
> @@ -11,6 +11,9 @@
> Restructuring
> +++++++++++++
>
> +- Cloned ``ZopeVocabularyRegistry`` from ``zope.app.schema``, and added
> + sane registration of it during initialization of Five.
> +
> - Removed experimental support for configuring the Twisted HTTP server
> as an alternative to ``ZServer``.
>
>
> Modified: Zope/trunk/src/Products/Five/__init__.py
> ===================================================================
> --- Zope/trunk/src/Products/Five/__init__.py 2009-09-18 22:27:17 UTC (rev 104365)
> +++ Zope/trunk/src/Products/Five/__init__.py 2009-09-18 22:40:23 UTC (rev 104366)
> @@ -22,13 +22,14 @@
> from Products.Five.browser import BrowserView
> from Products.Five.skin.standardmacros import StandardMacros
>
> -# hook up ZopeVocabularyRegistry
> -import zope.app.schema.vocabulary
> -
> # load the site's ZCML tree (usually site.zcml) upon product
> # initialization
> def initialize(context):
> + from zope.schema.vocabulary import setVocabularyRegistry
> + from Products.Five.schema import Zope2VocabularyRegistry
> +
> zcml.load_site()
> + setVocabularyRegistry(Zope2VocabularyRegistry())
>
> # some convenience methods/decorators
>
>
> Added: Zope/trunk/src/Products/Five/schema.py
> ===================================================================
> --- Zope/trunk/src/Products/Five/schema.py (rev 0)
> +++ Zope/trunk/src/Products/Five/schema.py 2009-09-18 22:40:23 UTC (rev 104366)
> @@ -0,0 +1,36 @@
> +##############################################################################
> +#
> +# Copyright (c) 2004, 2005 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.
> +#
> +##############################################################################
> +"""Five-specific schema support
> +
> +$Id$
> +"""
> +from zope.component import getUtility
> +from zope.interface import implements
> +from zope.schema.interfaces import IVocabularyRegistry
> +from zope.schema.interfaces import IVocabularyFactory
> +
> +class Zope2VocabularyRegistry(object):
> + """IVocabularyRegistry that supports global and local utilities.
> +
> + Cloned from the version in zope.app.schema.vocabulary: it was the
> + only feature in that package!
> + """
> + implements(IVocabularyRegistry)
> + __slots__ = ()
> +
> + def get(self, context, name):
> + """See zope.schema.interfaces.IVocabularyRegistry.
> + """
> + factory = getUtility(IVocabularyFactory, name)
> + return factory(context)
>
> Added: Zope/trunk/src/Products/Five/tests/test_schema.py
> ===================================================================
> --- Zope/trunk/src/Products/Five/tests/test_schema.py (rev 0)
> +++ Zope/trunk/src/Products/Five/tests/test_schema.py 2009-09-18 22:40:23 UTC (rev 104366)
> @@ -0,0 +1,54 @@
> +##############################################################################
> +#
> +# Copyright (c) 2006 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.
> +#
> +##############################################################################
> +""" Unit tests for Products.Five.schema module.
> +
> +$Id: tests.py 71093 2006-11-07 13:54:29Z yuppie $
> +"""
> +import unittest
> +from zope.testing.cleanup import CleanUp
> +
> +class Zope2VocabularyRegistryTests(unittest.TestCase, CleanUp):
> +
> + def _getTargetClass(self):
> + from Products.Five.schema import Zope2VocabularyRegistry
> + return Zope2VocabularyRegistry
> +
> + def _makeOne(self):
> + return self._getTargetClass()()
> +
> + def test_class_conforms_to_IVocabularyRegistry(self):
> + from zope.interface.verify import verifyClass
> + from zope.schema.interfaces import IVocabularyRegistry
> + verifyClass(IVocabularyRegistry, self._getTargetClass())
> +
> + def test_instance_conforms_to_IVocabularyRegistry(self):
> + from zope.interface.verify import verifyObject
> + from zope.schema.interfaces import IVocabularyRegistry
> + verifyObject(IVocabularyRegistry, self._makeOne())
> +
> + def test_get_miss_raises_LookupError(self):
> + registry = self._makeOne()
> + context = object()
> + self.assertRaises(LookupError, registry.get, context, 'nonesuch')
> +
> + def test_get_hit_finds_registered_IVocabularyFactory(self):
> + from zope.component import provideUtility
> + from zope.schema.interfaces import IVocabularyFactory
> + _marker = object()
> + def _factory(context):
> + return _marker
> + provideUtility(_factory, IVocabularyFactory, 'foundit')
> + registry = self._makeOne()
> + context = object()
> + found = registry.get(context, 'foundit')
> + self.failUnless(found is _marker)
>
> _______________________________________________
> checkins mailing list
> checkins at zope.org
> https://mail.zope.org/mailman/listinfo/checkins
>
More information about the checkins
mailing list