[Checkins] SVN: zope.site/trunk/ The get/queryNextUtility functions is now in zope.component. Provide BBB imports. The README.txt became useless, as it only contained tests for those functions, rip it.

Dan Korostelev nadako at gmail.com
Wed Mar 11 20:07:29 EDT 2009


Log message for revision 97940:
  The get/queryNextUtility functions is now in zope.component. Provide BBB imports. The README.txt became useless, as it only contained tests for those functions, rip it.

Changed:
  U   zope.site/trunk/CHANGES.txt
  U   zope.site/trunk/README.txt
  U   zope.site/trunk/buildout.cfg
  U   zope.site/trunk/setup.py
  D   zope.site/trunk/src/zope/site/README.txt
  U   zope.site/trunk/src/zope/site/__init__.py
  U   zope.site/trunk/src/zope/site/next.py
  D   zope.site/trunk/src/zope/site/tests/test_api.py

-=-
Modified: zope.site/trunk/CHANGES.txt
===================================================================
--- zope.site/trunk/CHANGES.txt	2009-03-12 00:01:36 UTC (rev 97939)
+++ zope.site/trunk/CHANGES.txt	2009-03-12 00:07:28 UTC (rev 97940)
@@ -7,6 +7,10 @@
 
 - Fix NameError when calling ``zope.site.testing.siteSetUp(site=True)``.
 
+- The getNextUtility and queryNextUtility functions was moved to zope.component.
+  While backward-compatibility imports are provided, it's strongly recommended
+  to update your imports.
+
 3.6.1 (2009-02-28)
 ------------------
 

Modified: zope.site/trunk/README.txt
===================================================================
--- zope.site/trunk/README.txt	2009-03-12 00:01:36 UTC (rev 97939)
+++ zope.site/trunk/README.txt	2009-03-12 00:07:28 UTC (rev 97940)
@@ -1,2 +1,9 @@
-This package adds support for persistent local component registries for
-the zope component architecture.
+=====================================
+Zope 3's Local Component Architecture
+=====================================
+
+This package provides a local and persistent site manager
+implementation, so that one can register local utilities and
+adapters. It uses local adapter registries for its adapter and utility
+registry. The module also provides some facilities to organize the
+local software and ensures the correct behavior inside the ZODB.

Modified: zope.site/trunk/buildout.cfg
===================================================================
--- zope.site/trunk/buildout.cfg	2009-03-12 00:01:36 UTC (rev 97939)
+++ zope.site/trunk/buildout.cfg	2009-03-12 00:07:28 UTC (rev 97940)
@@ -1,5 +1,5 @@
 [buildout]
-develop = .
+develop = . ../zope.component
 parts = test coverage-test coverage-report
 
 [test]

Modified: zope.site/trunk/setup.py
===================================================================
--- zope.site/trunk/setup.py	2009-03-12 00:01:36 UTC (rev 97939)
+++ zope.site/trunk/setup.py	2009-03-12 00:07:28 UTC (rev 97940)
@@ -32,8 +32,6 @@
           'Detailed Documentation\n'
           '**********************\n'
           + '\n\n' +
-          read('src', 'zope', 'site', 'README.txt')
-          + '\n\n' +
           read('src', 'zope', 'site', 'site.txt')
           + '\n\n' +
           read('CHANGES.txt')

Deleted: zope.site/trunk/src/zope/site/README.txt
===================================================================
--- zope.site/trunk/src/zope/site/README.txt	2009-03-12 00:01:36 UTC (rev 97939)
+++ zope.site/trunk/src/zope/site/README.txt	2009-03-12 00:07:28 UTC (rev 97940)
@@ -1,106 +0,0 @@
-=====================================
-Zope 3's Local Component Architecture
-=====================================
-
-This package provides a local and persistent site manager
-implementation, so that one can register local utilities and
-adapters. It uses local adapter registries for its adapter and utility
-registry. The module also provides some facilities to organize the
-local software and ensures the correct behavior inside the ZODB.
-
-Local Component Architecture API
---------------------------------
-
-While the component architecture API provided by ``zope.component`` is
-sufficient most of the time, there are a couple of functions that are
-useful in the context of multiple sites and base component registries.
-
-It is common for a utility to delegate its answer to a utility
-providing the same interface in one of the component registry's
-bases. Let's first create a global utility::
-
-  >>> import zope.interface
-  >>> class IMyUtility(zope.interface.Interface):
-  ...     pass
-
-  >>> class MyUtility(object):
-  ...     zope.interface.implements(IMyUtility)
-  ...     def __init__(self, id):
-  ...         self.id = id
-  ...     def __repr__(self):
-  ...         return "%s('%s')" % (self.__class__.__name__, self.id)
-
-  >>> gutil = MyUtility('global')
-  >>> from zope.component import getGlobalSiteManager
-  >>> gsm = getGlobalSiteManager()
-  >>> gsm.registerUtility(gutil, IMyUtility, 'myutil')
-
-We create a simple folder hierarchy we can place our utilities in:
-
-  >>> from zope.site.folder import Folder, rootFolder
-  >>> root = rootFolder()
-  >>> root[u'folder1'] = Folder()
-  >>> root[u'folder1'][u'folder1_1'] = Folder()
-
-We set up site managers in the folders::
-
-  >>> from zope.site import testing
-  >>> root_sm = testing.createSiteManager(root)
-  >>> folder1_sm = testing.createSiteManager(root['folder1'])
-  >>> folder1_1_sm = testing.createSiteManager(root['folder1']['folder1_1'])
-
-Now we create two utilities and insert them in our folder hierarchy:
-
-  >>> util1 = testing.addUtility(folder1_sm, 'myutil', IMyUtility,
-  ...                            MyUtility('one'))
-  >>> util1_1 = testing.addUtility(folder1_1_sm, 'myutil', IMyUtility,
-  ...                              MyUtility('one-one'))
-
-Now, if we ask `util1_1` for its next available utility we get the
-``one`` utility::
-
-  >>> from zope import site
-  >>> site.getNextUtility(util1_1, IMyUtility, 'myutil')
-  MyUtility('one')
-
-Next we ask `util1` for its next utility and we should get the global version:
-
-  >>> site.getNextUtility(util1, IMyUtility, 'myutil')
-  MyUtility('global')
-
-However, if we ask the global utility for the next one, an error is raised
-
-  >>> site.getNextUtility(gutil, IMyUtility,
-  ...                     'myutil') #doctest: +NORMALIZE_WHITESPACE
-  Traceback (most recent call last):
-  ...
-  ComponentLookupError:
-  No more utilities for <InterfaceClass __builtin__.IMyUtility>,
-  'myutil' have been found.
-
-You can also use `queryNextUtility` and specify a default:
-
-  >>> site.queryNextUtility(gutil, IMyUtility, 'myutil', 'default')
-  'default'
-
-Let's now ensure that the function also works with multiple registries. First
-we create another base registry:
-
-  >>> from zope.component import registry
-  >>> myregistry = registry.Components()
-
-We now set up another utility into that registry:
-
-  >>> custom_util = MyUtility('my_custom_util')
-  >>> myregistry.registerUtility(custom_util, IMyUtility, 'my_custom_util')
-
-We add it as a base to the local site manager:
-
-  >>> folder1_sm.__bases__ = (myregistry,) + folder1_sm.__bases__
-
-Both the ``myregistry`` and global utilities should be available:
-
-  >>> site.queryNextUtility(folder1_sm, IMyUtility, 'my_custom_util')
-  MyUtility('my_custom_util')
-  >>> site.queryNextUtility(folder1_sm, IMyUtility, 'myutil')
-  MyUtility('global')

Modified: zope.site/trunk/src/zope/site/__init__.py
===================================================================
--- zope.site/trunk/src/zope/site/__init__.py	2009-03-12 00:01:36 UTC (rev 97939)
+++ zope.site/trunk/src/zope/site/__init__.py	2009-03-12 00:07:28 UTC (rev 97940)
@@ -21,5 +21,6 @@
 from zope.site.site import LocalSiteManager, changeSiteConfigurationAfterMove
 from zope.site.site import threadSiteSubscriber
 from zope.site.site import clearThreadSiteSubscriber
-from zope.site.next import getNextUtility, queryNextUtility
 
+# BBB
+from zope.component import getNextUtility, queryNextUtility

Modified: zope.site/trunk/src/zope/site/next.py
===================================================================
--- zope.site/trunk/src/zope/site/next.py	2009-03-12 00:01:36 UTC (rev 97939)
+++ zope.site/trunk/src/zope/site/next.py	2009-03-12 00:07:28 UTC (rev 97940)
@@ -1,33 +1,2 @@
-import zope.component
-
-__docformat__ = "reStructuredText"
-
-_marker = object()
-
-def getNextUtility(context, interface, name=''):
-    """Get the next available utility.
-
-    If no utility was found, a `ComponentLookupError` is raised.
-    """
-    util = queryNextUtility(context, interface, name, _marker)
-    if util is _marker:
-        raise zope.component.interfaces.ComponentLookupError(
-              "No more utilities for %s, '%s' have been found." % (
-                  interface, name))
-    return util
-
-
-def queryNextUtility(context, interface, name='', default=None):
-    """Query for the next available utility.
-
-    Find the next available utility providing `interface` and having the
-    specified name. If no utility was found, return the specified `default`
-    value."""
-    sm = zope.component.getSiteManager(context)
-    bases = sm.__bases__
-    for base in bases:
-        util = base.queryUtility(interface, name, _marker)
-        if util is not _marker:
-            return util
-    return default
-
+# BBB
+from zope.component import getNextUtility, queryNextUtility

Deleted: zope.site/trunk/src/zope/site/tests/test_api.py
===================================================================
--- zope.site/trunk/src/zope/site/tests/test_api.py	2009-03-12 00:01:36 UTC (rev 97939)
+++ zope.site/trunk/src/zope/site/tests/test_api.py	2009-03-12 00:07:28 UTC (rev 97940)
@@ -1,34 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 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.
-#
-##############################################################################
-"""Registration Tests
-
-$Id$
-"""
-__docformat__ = "reStructuredText"
-import unittest
-
-from zope.testing import doctest
-from zope.site import testing
-
-def setUp(test):
-    testing.siteSetUp()
-
-def tearDown(test):
-    testing.siteTearDown()
-
-def test_suite():
-    return unittest.TestSuite((
-        doctest.DocFileSuite('../README.txt',
-                             setUp=setUp, tearDown=tearDown),
-        ))



More information about the Checkins mailing list