[Checkins]
SVN: zope.introspector/trunk/src/zope/introspector/utilityinfo.
Remove UtilityInfo.
Uli Fouquet
uli at gnufix.de
Wed Jul 9 18:14:59 EDT 2008
Log message for revision 88149:
Remove UtilityInfo.
Changed:
D zope.introspector/trunk/src/zope/introspector/utilityinfo.py
D zope.introspector/trunk/src/zope/introspector/utilityinfo.txt
-=-
Deleted: zope.introspector/trunk/src/zope/introspector/utilityinfo.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/utilityinfo.py 2008-07-09 22:14:29 UTC (rev 88148)
+++ zope.introspector/trunk/src/zope/introspector/utilityinfo.py 2008-07-09 22:14:58 UTC (rev 88149)
@@ -1,38 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2008 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.
-#
-##############################################################################
-"""Infos about utilities.
-"""
-import zope.component
-from zope.component import globalregistry
-
-class UtilityInfo(object):
-
- def __init__(self, obj=None):
- self.context = obj
-
- def getAllUtilities(self):
- smlist = [zope.component.getSiteManager(self.context)]
- seen = []
- result = []
- while smlist:
- sm = smlist.pop()
- if sm in seen:
- continue
- seen.append(sm)
- smlist += list(sm.__bases__)
- for u in sm.registeredUtilities():
- result.append(
- dict(name = u.name, provided=u.provided,
- registry=u.registry, component=u.component))
- return result
Deleted: zope.introspector/trunk/src/zope/introspector/utilityinfo.txt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/utilityinfo.txt 2008-07-09 22:14:29 UTC (rev 88148)
+++ zope.introspector/trunk/src/zope/introspector/utilityinfo.txt 2008-07-09 22:14:58 UTC (rev 88149)
@@ -1,113 +0,0 @@
-Determining utilites for objects
-********************************
-
-Get informed about all local and global utilities for an object.
-
-:Test-Layer: functional
-
-zope.introspector provides the ``UtilityInfo`` for determining
-utilities, that are available for specific contexts. Contrary to
-adapters, utilities tend to be context-less. We must, however, take
-care, that local utilities are only registered for objects in the same
-site.
-
-Let's start with a simple object::
-
- >>> class Mammoth(object):
- ... pass
-
-We define a utility::
-
- >>> from zope.interface import Interface, implements
- >>> from zope.component import provideUtility
-
- >>> import persistent
- >>> from zope.app.container.contained import Contained
- >>> class ITestUtility(Interface):
- ... pass
-
- >>> #class TestUtility(object):
- >>> class TestUtility(persistent.Persistent, Contained):
- ... implements(ITestUtility)
-
-
-Now we register it globally and unnamed::
-
- >>> provideUtility(TestUtility(), provides=ITestUtility, name='')
-
-Make sure, the utility was really registered::
-
- >>> from zope.component import getUtility
- >>> getUtility(ITestUtility, name='', context=None)
- <TestUtility object at 0x...>
-
-We create an instance of the mammoth::
-
- >>> manfred = Mammoth()
-
-Using ``UtilityInfo`` we can ask for all the utilities for our
-particular mammoth::
-
- >>> from zope.introspector import UtilityInfo
- >>> info = UtilityInfo(manfred)
- >>> from pprint import pprint
- >>> pprint(sorted(info.getAllUtilities()))
- [{'component': <zope.app.publisher.browser.menu.BrowserMenu object at 0x...>,
- ...
- {'component': <TestUtility object at 0x...>,
- 'name': '',
- 'provided': <InterfaceClass __builtin__.ITestUtility>,
- 'registry': <BaseGlobalComponents base>},
- ...
-
-
-Local Utilitites
-================
-
-If an object is stored in a local site, then we should get also the
-locally registered utilities, but only those, that are in one of the
-sites, the object is part of.
-
-We now create a site, where we can register local utilities and store
-objects::
-
- >>> from zope.app.folder import folder
- >>> local_site1 = folder.rootFolder()
- >>> getRootFolder()['local_site'] = local_site1
-
- >>> from zope.app.component import site
- >>> sm = site.LocalSiteManager(local_site1)
- >>> local_site1.setSiteManager(sm)
-
-We register a utility in this site, this time a named one::
-
- >>> local_utility1 = TestUtility()
- >>> sm.registerUtility(local_utility1, ITestUtility, 'local_u1')
-
-The utility is available, if we ask the local site manager directly::
-
- >>> sm.queryUtility(ITestUtility, 'local_u1')
- <TestUtility object at 0x...>
-
-We place another mammoth in that site. To make it also a placefull
-object, we have also to provide a ``__parent__`` attribute::
-
- >>> fred = Mammoth()
- >>> local_site1['fred'] = fred
- >>> fred.__parent__ = local_site1
-
-Using UtilityInfo we can now get also this newly registered utility::
-
- >>> info = UtilityInfo(fred)
- >>> pprint(info.getAllUtilities())
- [{'component': <TestUtility object at 0x...>,
- 'name': 'local_u1',
- 'provided': <InterfaceClass __builtin__.ITestUtility>,
- 'registry': <LocalSiteManager ++etc++site>},
- ...
- {'component': <TestUtility object at 0x...>,
- 'name': '',
- 'provided': <InterfaceClass __builtin__.ITestUtility>,
- 'registry': <BaseGlobalComponents base>},
- ...]
-
More information about the Checkins
mailing list