[Zope3-checkins] SVN: Zope3/trunk/ Remove the aliasing of
`zope.component` to `capi` as dicussed in
Philipp von Weitershausen
philikon at philikon.de
Sun Mar 6 10:12:39 EST 2005
Log message for revision 29403:
Remove the aliasing of `zope.component` to `capi` as dicussed in
http://mail.zope.org/pipermail/zope3-dev/2005-March/013668.html
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/principalannotation/tests.py
U Zope3/trunk/src/zope/app/traversing/browser/absoluteurl.py
U Zope3/trunk/src/zope/app/traversing/namespace.py
U Zope3/trunk/src/zope/component/factory.txt
U Zope3/trunk/src/zope/component/socketexample.txt
U Zope3/trunk/src/zope/component/tests.py
U Zope3/trunk/src/zope/i18n/tests/test_itranslationdomain.py
U Zope3/trunk/src/zope/i18n/tests/test_translationdomain.py
U Zope3/trunk/src/zope/server/http/tests/test_publisherserver.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/doc/CHANGES.txt 2005-03-06 15:12:39 UTC (rev 29403)
@@ -378,8 +378,8 @@
+ Updated `zope.app.pluggableauth`, so that it will work as an
authentication utility.
- + Restructured `zope.app.persentation` (a.k.a page folders) to the new
- component API.
+ + Restructured `zope.app.presentation` (a.k.a page folders) to
+ the new component API.
- Simplified the registration framework by only supporting two states:
active and inactive. This allowed us to get rid of the registration
@@ -493,12 +493,6 @@
Instead of `rename(container, oldName, newName)`, one should use
`IContainerItemRenamer(container).renameItem(oldName, newName)`.
- - Added capi in zope.component, a short form of zope.component, that can
- be in instead of zapi when zapi cannot be used. This would be the case
- for packages that don't want to create a dependency on zope.app or
- cannot access zope.app.zapi directly (e.g. zope.app.traversing). If
- your use case doesn't apply to this, continue using zope.app.zapi.
-
Bug Fixes
- Fixed issue #345: Using response.write should not involve unicode
Modified: Zope3/trunk/src/zope/app/principalannotation/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/principalannotation/tests.py 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/src/zope/app/principalannotation/tests.py 2005-03-06 15:12:39 UTC (rev 29403)
@@ -17,7 +17,7 @@
"""
from unittest import TestCase, TestLoader, TextTestRunner
-from zope import component as capi
+import zope.component
from zope.interface import implements
from zope.app import zapi
from zope.app.annotation.interfaces import IAnnotations
@@ -43,7 +43,7 @@
sm = self.buildFolders(site='/')
self.util = PrincipalAnnotationUtility()
- capi.provideUtility(self.util, IPrincipalAnnotationUtility)
+ zope.component.provideUtility(self.util, IPrincipalAnnotationUtility)
def testGetSimple(self):
prince = Principal('somebody')
Modified: Zope3/trunk/src/zope/app/traversing/browser/absoluteurl.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/browser/absoluteurl.py 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/src/zope/app/traversing/browser/absoluteurl.py 2005-03-06 15:12:39 UTC (rev 29403)
@@ -20,7 +20,7 @@
from zope.proxy import sameProxiedObjects
from zope.publisher.browser import IBrowserRequest
-import zope.component as capi
+import zope.component
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.publisher.browser import BrowserView
from zope.app.traversing.browser.interfaces import IAbsoluteURL
@@ -32,7 +32,7 @@
_safe = '@+' # Characters that we don't want to have quoted
def absoluteURL(ob, request):
- return capi.getMultiAdapter((ob, request), IAbsoluteURL)()
+ return zope.component.getMultiAdapter((ob, request), IAbsoluteURL)()
class AbsoluteURL(BrowserView):
implements(IAbsoluteURL)
@@ -54,8 +54,8 @@
if container is None:
raise TypeError, _insufficientContext
- url = str(capi.getMultiAdapter((container, request),
- name='absolute_url'))
+ url = str(zope.component.getMultiAdapter((container, request),
+ name='absolute_url'))
name = self._getContextName(context)
if name is None:
raise TypeError, _insufficientContext
@@ -83,8 +83,8 @@
isinstance(context, Exception):
return ({'name':'', 'url': self.request.getApplicationURL()}, )
- base = tuple(capi.getMultiAdapter((container, request),
- name='absolute_url').breadcrumbs())
+ base = tuple(zope.component.getMultiAdapter(
+ (container, request), name='absolute_url').breadcrumbs())
name = getattr(context, '__name__', None)
if name is None:
Modified: Zope3/trunk/src/zope/app/traversing/namespace.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/namespace.py 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/src/zope/app/traversing/namespace.py 2005-03-06 15:12:39 UTC (rev 29403)
@@ -17,7 +17,7 @@
"""
import re
-import zope.component as capi
+import zope.component
import zope.interface
from zope.component.exceptions import ComponentLookupError
from zope.interface import providedBy, directlyProvides, directlyProvidedBy
@@ -104,10 +104,10 @@
"""
if request is not None:
- traverser = capi.queryMultiAdapter((object, request),
- ITraversable, ns)
+ traverser = zope.component.queryMultiAdapter((object, request),
+ ITraversable, ns)
else:
- traverser = capi.queryAdapter(object, ITraversable, ns)
+ traverser = zope.component.queryAdapter(object, ITraversable, ns)
if traverser is None:
raise TraversalError("++%s++%s" % (ns, name))
@@ -167,7 +167,7 @@
return resource
def queryResource(site, name, request, default=None):
- resource = capi.queryAdapter(request, name=name)
+ resource = zope.component.queryAdapter(request, name=name)
if resource is None:
return default
@@ -353,8 +353,8 @@
self.request = request
def traverse(self, name, ignored):
- view = capi.queryMultiAdapter((self.context, self.request),
- name=name)
+ view = zope.component.queryMultiAdapter((self.context, self.request),
+ name=name)
if view is None:
raise TraversalError(self.context, name)
@@ -371,7 +371,7 @@
def traverse(self, name, ignored):
self.request.shiftNameToApplication()
- skin = capi.getUtility(ISkin, name)
+ skin = zope.component.getUtility(ISkin, name)
applySkin(self.request, skin)
return self.context
@@ -448,7 +448,7 @@
>>> tearDown()
"""
try:
- return capi.getAdapter(self.context, IPathAdapter, name)
+ return zope.component.getAdapter(self.context, IPathAdapter, name)
except ComponentLookupError:
raise TraversalError(self.context, name)
@@ -528,7 +528,7 @@
# TODO: I am not sure this is the best solution. What
# if we want to enable tracebacks when also trying to
# debug a different skin?
- skin = capi.getUtility(ISkin, 'Debug')
+ skin = zope.component.getUtility(ISkin, 'Debug')
directlyProvides(request, providedBy(request)+skin)
else:
raise ValueError("Unknown debug flag: %s" % flag)
Modified: Zope3/trunk/src/zope/component/factory.txt
===================================================================
--- Zope3/trunk/src/zope/component/factory.txt 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/src/zope/component/factory.txt 2005-03-06 15:12:39 UTC (rev 29403)
@@ -96,9 +96,9 @@
The Componant Architecture Factory API
--------------------------------------
- >>> from zope import component as capi
+ >>> import zope.component
>>> factory = Factory(Klass, 'Klass', 'Klassier')
- >>> gsm = capi.getGlobalSiteManager()
+ >>> gsm = zope.component.getGlobalSiteManager()
>>> from zope.component.interfaces import IFactory
>>> gsm.provideUtility(IFactory, factory, 'klass')
@@ -106,7 +106,7 @@
Creating an Object
++++++++++++++++++
- >>> kl = capi.createObject('klass', 1, 2, foo=3, bar=4)
+ >>> kl = zope.component.createObject('klass', 1, 2, foo=3, bar=4)
>>> isinstance(kl, Klass)
True
>>> kl.args
@@ -117,7 +117,7 @@
Accessing Provided Interfaces
+++++++++++++++++++++++++++++
- >>> implemented = capi.getFactoryInterfaces('klass')
+ >>> implemented = zope.component.getFactoryInterfaces('klass')
>>> implemented.isOrExtends(IKlass)
True
>>> [iface for iface in implemented]
@@ -126,6 +126,7 @@
List of All Factories
+++++++++++++++++++++
- >>> [(name, fac.__class__) for name, fac in capi.getFactoriesFor(IKlass)]
+ >>> [(name, fac.__class__) for name, fac in
+ ... zope.component.getFactoriesFor(IKlass)]
[(u'klass', <class 'zope.component.factory.Factory'>)]
Modified: Zope3/trunk/src/zope/component/socketexample.txt
===================================================================
--- Zope3/trunk/src/zope/component/socketexample.txt 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/src/zope/component/socketexample.txt 2005-03-06 15:12:39 UTC (rev 29403)
@@ -81,15 +81,15 @@
inventory. In the component architecture we do this by registering the adapter
with the framework, more specifically with the global site manager:
- >>> from zope import component as capi
- >>> gsm = capi.getGlobalSiteManager()
+ >>> import zope.component
+ >>> gsm = zope.component.getGlobalSiteManager()
>>> gsm.provideAdapter((IGermanSocket,), IUSSocket, '',
... GermanToUSSocketAdapter)
-`capi` is the component architecture API that is being presented by this
-file. You registered an adapter from `IGermanSocket` to `IUSSocket` having no
-name (thus the empty string).
+`zope.component` is the component architecture API that is being
+presented by this file. You registered an adapter from `IGermanSocket`
+to `IUSSocket` having no name (thus the empty string).
Anyways, you finally get back to your hotel room and shave, since you have not
been able to shave in the plane. In the bathroom you discover a socket:
@@ -100,7 +100,7 @@
You now insert the adapter in the German socket
- >>> bathroomUS = capi.getAdapter(bathroomDE, IUSSocket, '')
+ >>> bathroomUS = zope.component.getAdapter(bathroomDE, IUSSocket, '')
so that the socket now provides the US version:
@@ -123,7 +123,8 @@
You try to find an adapter for your shaver in your bag, but you fail, since
you do not have one:
- >>> capi.getAdapter(czech, IUSSocket, '') #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getAdapter(czech, IUSSocket, '') \
+ ... #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError: (<instance of CzechSocket>,
@@ -133,7 +134,7 @@
or the more graceful way:
>>> marker = object()
- >>> socket = capi.queryAdapter(czech, IUSSocket, '', marker)
+ >>> socket = zope.component.queryAdapter(czech, IUSSocket, '', marker)
>>> socket is marker
True
@@ -168,31 +169,30 @@
Now we simply look up the adapters using their labels (called *name*):
- >>> socket = capi.getAdapter(bathroomDE, IUSSocket, 'shaver')
+ >>> socket = zope.component.getAdapter(bathroomDE, IUSSocket, 'shaver')
>>> socket.__class__ is GermanToUSSocketAdapter
True
- >>> socket = capi.getAdapter(bathroomDE, IUSSocket, 'dvd')
+ >>> socket = zope.component.getAdapter(bathroomDE, IUSSocket, 'dvd')
>>> socket.__class__ is GermanToUSSocketAdapterAndTransformer
True
Clearly, we do not have an adapter for the MP3 player
- >>> capi.getAdapter(bathroomDE, IUSSocket,
- ... 'mp3') #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getAdapter(bathroomDE, IUSSocket, 'mp3') \
+ ... #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError: (<instance of GermanSocket>,
<InterfaceClass __builtin__.IUSSocket>,
'mp3')
-
but you could use the 'dvd' adapter in this case of course. ;)
Sometimes you want to know all adapters that are available. Let's say you want
to know about all the adapters that convert a German to a US socket type:
- >>> sockets = capi.getAdapters((bathroomDE,), IUSSocket)
+ >>> sockets = zope.component.getAdapters((bathroomDE,), IUSSocket)
>>> len(sockets)
3
>>> names = [name for name, socket in sockets]
@@ -200,8 +200,9 @@
>>> names
[u'', u'dvd', u'shaver']
-`capi.getAdapters()` returns a list of tuples. The first entry of the tuple is
-the name of the adapter and the second is the adapter itself.
+`zope.component.getAdapters()` returns a list of tuples. The first
+entry of the tuple is the name of the adapter and the second is the
+adapter itself.
Multi-Adapters
@@ -251,8 +252,8 @@
we can now get a gounded US socket:
- >>> socket = capi.getMultiAdapter((livingroom, grounder),
- ... IUSGroundedSocket, 'mp3')
+ >>> socket = zope.component.getMultiAdapter((livingroom, grounder),
+ ... IUSGroundedSocket, 'mp3')
>>> socket.__class__ is GroundedGermanToUSSocketAdapter
True
@@ -263,8 +264,9 @@
Of course, you do not have a 'dvd' grounded US socket available:
- >>> capi.getMultiAdapter((livingroom, grounder), IUSGroundedSocket,
- ... 'dvd') #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getMultiAdapter((livingroom, grounder),
+ ... IUSGroundedSocket, 'dvd') \
+ ... #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError: ((<instance of GermanSocket>,
@@ -273,8 +275,8 @@
'dvd')
- >>> socket = capi.queryMultiAdapter((livingroom, grounder),
- ... IUSGroundedSocket, 'dvd', marker)
+ >>> socket = zope.component.queryMultiAdapter(
+ ... (livingroom, grounder), IUSGroundedSocket, 'dvd', marker)
>>> socket is marker
True
@@ -328,7 +330,7 @@
Now let use all these things to put out the fire:
- >>> extinguishers = capi.subscribers((fire,), IFireExtinguisher)
+ >>> extinguishers = zope.component.subscribers((fire,), IFireExtinguisher)
>>> extinguishers.sort()
>>> for extinguisher in extinguishers:
... extinguisher.extinguish()
@@ -339,7 +341,7 @@
If no subscribers are found for a particular object, then an empty list is
returned:
- >>> capi.subscribers((object(),), IFireExtinguisher)
+ >>> zope.component.subscribers((object(),), IFireExtinguisher)
[]
@@ -380,7 +382,7 @@
We can now get the utility using
- >>> utility = capi.getUtility(IUSSocket)
+ >>> utility = zope.component.getUtility(IUSSocket)
>>> utility is generator
True
@@ -388,7 +390,7 @@
utility does not exsist for a particular interface, such as the German socket,
then the lookup fails
- >>> capi.getUtility(IGermanSocket)
+ >>> zope.component.getUtility(IGermanSocket)
Traceback (most recent call last):
...
ComponentLookupError: (<InterfaceClass __builtin__.IGermanSocket>, '')
@@ -396,7 +398,7 @@
or more gracefully when specifying a default value:
>>> default = object()
- >>> utility = capi.queryUtility(IGermanSocket, default=default)
+ >>> utility = zope.component.queryUtility(IGermanSocket, default=default)
>>> utility is default
True
@@ -432,13 +434,13 @@
You can now access the solar panel using
- >>> utility = capi.getUtility(IUSSocket, 'Solar Panel')
+ >>> utility = zope.component.getUtility(IUSSocket, 'Solar Panel')
>>> utility is panel
True
Of course, if a utility is not available, then the lookup will simply fail
- >>> capi.getUtility(IUSSocket, 'Wind Mill')
+ >>> zope.component.getUtility(IUSSocket, 'Wind Mill')
Traceback (most recent call last):
...
ComponentLookupError: (<InterfaceClass __builtin__.IUSSocket>, 'Wind Mill')
@@ -446,14 +448,15 @@
or more gracefully when specifying a default value:
>>> default = object()
- >>> utility = capi.queryUtility(IUSSocket, 'Wind Mill', default=default)
+ >>> utility = zope.component.queryUtility(IUSSocket, 'Wind Mill',
+ ... default=default)
>>> utility is default
True
Now you want to look at all the utilities you have for a particular kind. The
following API function will return a list of name/utility pairs:
- >>> utils = list(capi.getUtilitiesFor(IUSSocket))
+ >>> utils = list(zope.component.getUtilitiesFor(IUSSocket))
>>> utils.sort()
>>> utils #doctest: +NORMALIZE_WHITESPACE
[(u'', <instance of Generator>),
@@ -465,7 +468,7 @@
utilities. If you are not using multiple site managers, you will not actually
need this method.
- >>> utils = list(capi.getAllUtilitiesRegisteredFor(IUSSocket))
+ >>> utils = list(zope.component.getAllUtilitiesRegisteredFor(IUSSocket))
>>> utils.sort()
>>> utils
[<instance of Generator>, <instance of Solar Panel>]
@@ -502,7 +505,7 @@
We can now get a list of interfaces the produced object will provide:
- >>> ifaces = capi.getFactoryInterfaces('SolarPanel')
+ >>> ifaces = zope.component.getFactoryInterfaces('SolarPanel')
>>> IUSSocket in ifaces
True
@@ -514,7 +517,7 @@
Of course you can also just create an object:
- >>> panel = capi.createObject('SolarPanel')
+ >>> panel = zope.component.createObject('SolarPanel')
>>> panel.__class__ is SolarPanel
True
@@ -530,7 +533,7 @@
you can also determine, which available factories will create objects
providing a certian interface:
- >>> factories = capi.getFactoriesFor(IUSSocket)
+ >>> factories = zope.component.getFactoriesFor(IUSSocket)
>>> factories = [(name, factory.__class__) for name, factory in factories]
>>> factories.sort()
>>> factories #doctest: +NORMALIZE_WHITESPACE
@@ -550,7 +553,7 @@
commonly known as *global site manager*, since it is always available. You can
always get the global site manager using the API:
- >>> gsm = capi.getGlobalSiteManager()
+ >>> gsm = zope.component.getGlobalSiteManager()
>>> from zope.component.site import globalSiteManager
>>> gsm is globalSiteManager
@@ -587,7 +590,7 @@
We can now ask for the site manager of this context:
- >>> lsm = capi.getSiteManager(context)
+ >>> lsm = zope.component.getSiteManager(context)
>>> lsm is sm
True
Modified: Zope3/trunk/src/zope/component/tests.py
===================================================================
--- Zope3/trunk/src/zope/component/tests.py 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/src/zope/component/tests.py 2005-03-06 15:12:39 UTC (rev 29403)
@@ -21,7 +21,7 @@
from zope.interface.verify import verifyObject
from zope.testing import doctest
-from zope import component as capi
+import zope.component
from zope.component.interfaces import ComponentLookupError
from zope.component.interfaces import IComponentArchitecture
from zope.component.interfaces import ISiteManager
@@ -89,7 +89,7 @@
Get the global site manager via the CA API function:
- >>> gsm = capi.getGlobalSiteManager()
+ >>> gsm = zope.component.getGlobalSiteManager()
Make sure that the global site manager implements the correct interface
and is the global site manager instance we expect to get.
@@ -102,7 +102,7 @@
Finally, ensure that we always get the same global site manager, otherwise
our component registry will always be reset.
- >>> capi.getGlobalSiteManager() is gsm
+ >>> zope.component.getGlobalSiteManager() is gsm
True
"""
@@ -113,13 +113,13 @@
We don't know anything about the default service manager, except that it
is an `ISiteManager`.
- >>> ISiteManager.providedBy(capi.getSiteManager())
+ >>> ISiteManager.providedBy(zope.component.getSiteManager())
True
Calling `getSiteManager()` with no args is equivalent to calling it with a
context of `None`.
- >>> capi.getSiteManager() is capi.getSiteManager(None)
+ >>> zope.component.getSiteManager() is zope.component.getSiteManager(None)
True
If the context passed to `getSiteManager()` is not `None`, it is adapted
@@ -138,12 +138,12 @@
Now make sure that the `getSiteManager()` API call returns the correct
site manager.
- >>> capi.getSiteManager(context) is sitemanager
+ >>> zope.component.getSiteManager(context) is sitemanager
True
Using a context that is not adaptable to `ISiteManager` should fail.
- >>> capi.getSiteManager(ob) #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getSiteManager(ob) #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError: ('Could not adapt', <instance Ob>,
@@ -190,17 +190,17 @@
If an object implements the interface you want to adapt to,
`getAdapterInContext()` should simply return the object.
- >>> capi.getAdapterInContext(ob, I1, context)
+ >>> zope.component.getAdapterInContext(ob, I1, context)
<Component implementing 'I1'>
- >>> capi.queryAdapterInContext(ob, I1, context)
+ >>> zope.component.queryAdapterInContext(ob, I1, context)
<Component implementing 'I1'>
If an object conforms to the interface you want to adapt to,
`getAdapterInContext()` should simply return the conformed object.
- >>> capi.getAdapterInContext(ob, I2, context)
+ >>> zope.component.getAdapterInContext(ob, I2, context)
42
- >>> capi.queryAdapterInContext(ob, I2, context)
+ >>> zope.component.queryAdapterInContext(ob, I2, context)
42
If an adapter isn't registered for the given object and interface, and you
@@ -209,8 +209,8 @@
>>> class I4(Interface):
... pass
- >>> capi.getAdapterInContext(ob, I4,
- ... context) #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getAdapterInContext(ob, I4, context) \\
+ ... #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError: (<Component implementing 'I1'>,
@@ -218,15 +218,15 @@
...otherwise, you get the default:
- >>> capi.queryAdapterInContext(ob, I4, context, 44)
+ >>> zope.component.queryAdapterInContext(ob, I4, context, 44)
44
If you ask for an adapter for which something's registered you get the
registered adapter
- >>> capi.getAdapterInContext(ob, I3, context)
+ >>> zope.component.getAdapterInContext(ob, I3, context)
43
- >>> capi.queryAdapterInContext(ob, I3, context)
+ >>> zope.component.queryAdapterInContext(ob, I3, context)
43
"""
@@ -239,7 +239,7 @@
If an adapter isn't registered for the given object and interface, and you
provide no default, raise `ComponentLookupError`...
- >>> capi.getAdapter(ob, I2, '') #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getAdapter(ob, I2, '') #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError: (<instance Ob>,
@@ -248,18 +248,19 @@
...otherwise, you get the default
- >>> capi.queryAdapter(ob, I2, '', '<default>')
+ >>> zope.component.queryAdapter(ob, I2, '', '<default>')
'<default>'
Now get the global site manager and register an adapter from `I1` to `I2`
without a name:
- >>> capi.getGlobalSiteManager().provideAdapter((I1,), I2, '', Comp)
+ >>> zope.component.getGlobalSiteManager().provideAdapter(
+ ... (I1,), I2, '', Comp)
You can now simply access the adapter using the `getAdapter()` API
function:
- >>> adapter = capi.getAdapter(ob, I2, '')
+ >>> adapter = zope.component.getAdapter(ob, I2, '')
>>> adapter.__class__ is Comp
True
>>> adapter.context is ob
@@ -273,7 +274,8 @@
First, we need to register an adapter:
- >>> capi.getGlobalSiteManager().provideAdapter([I1], I2, '', Comp)
+ >>> zope.component.getGlobalSiteManager().provideAdapter(
+ ... [I1], I2, '', Comp)
Then we try to adapt `ob` to provide an `I2` interface by calling the `I2`
interface with the obejct as first argument:
@@ -305,13 +307,14 @@
First we register some named adapter:
- >>> capi.getGlobalSiteManager().provideAdapter([I1], I2, 'foo',
- ... lambda x: 0)
+ >>> zope.component.getGlobalSiteManager().provideAdapter(
+ ... [I1], I2, 'foo', lambda x: 0)
If an adapter isn't registered for the given object and interface,
and you provide no default, raise `ComponentLookupError`...
- >>> capi.getAdapter(ob, I2, 'bar') #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getAdapter(ob, I2, 'bar') \\
+ ... #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError:
@@ -319,16 +322,17 @@
...otherwise, you get the default
- >>> capi.queryAdapter(ob, I2, 'bar', '<default>')
+ >>> zope.component.queryAdapter(ob, I2, 'bar', '<default>')
'<default>'
But now we register an adapter for the object having the correct name
- >>> capi.getGlobalSiteManager().provideAdapter([I1], I2, 'bar', Comp)
+ >>> zope.component.getGlobalSiteManager().provideAdapter(
+ ... [I1], I2, 'bar', Comp)
so that the lookup succeeds:
- >>> adapter = capi.getAdapter(ob, I2, 'bar')
+ >>> adapter = zope.component.getAdapter(ob, I2, 'bar')
>>> adapter.__class__ is Comp
True
>>> adapter.context is ob
@@ -348,7 +352,8 @@
objects and interface, and you provide no default, raise
`ComponentLookupError`...
- >>> capi.getMultiAdapter((ob, ob2), I3) #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getMultiAdapter((ob, ob2), I3) \\
+ ... #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError:
@@ -358,7 +363,7 @@
...otherwise, you get the default
- >>> capi.queryMultiAdapter((ob, ob2), I3, default='<default>')
+ >>> zope.component.queryMultiAdapter((ob, ob2), I3, default='<default>')
'<default>'
Note that the name is not a required attribute here.
@@ -374,13 +379,13 @@
Now we can register the multi-adapter using
- >>> capi.getGlobalSiteManager().provideAdapter((I1, I2), I3, '',
- ... DoubleAdapter)
+ >>> zope.component.getGlobalSiteManager().provideAdapter(
+ ... (I1, I2), I3, '', DoubleAdapter)
Notice how the required interfaces are simply provided by a tuple. Now we
can get the adapter:
- >>> adapter = capi.getMultiAdapter((ob, ob2), I3)
+ >>> adapter = zope.component.getMultiAdapter((ob, ob2), I3)
>>> adapter.__class__ is DoubleAdapter
True
>>> adapter.first is ob
@@ -393,7 +398,8 @@
"""Providing an adapter for None says that your adapter can adapt anything
to `I2`.
- >>> capi.getGlobalSiteManager().provideAdapter((None,), I2, '', Comp)
+ >>> zope.component.getGlobalSiteManager().provideAdapter(
+ ... (None,), I2, '', Comp)
>>> adapter = I2(ob)
>>> adapter.__class__ is Comp
@@ -418,13 +424,15 @@
Let's register some adapters first:
- >>> capi.getGlobalSiteManager().provideAdapter([I1], I2, '', Comp)
- >>> capi.getGlobalSiteManager().provideAdapter([None], I2, 'foo', Comp)
+ >>> zope.component.getGlobalSiteManager().provideAdapter(
+ ... [I1], I2, '', Comp)
+ >>> zope.component.getGlobalSiteManager().provideAdapter(
+ ... [None], I2, 'foo', Comp)
Now we get all the adapters that are registered for `ob` that provide
`I2`:
- >>> adapters = capi.getAdapters((ob,), I2)
+ >>> adapters = zope.component.getAdapters((ob,), I2)
>>> adapters.sort()
>>> [(name, adapter.__class__.__name__) for name, adapter in adapters]
[(u'', 'Comp'), (u'foo', 'Comp')]
@@ -439,7 +447,7 @@
course. The pure instatiation of an object does not make it a utility. If
you do not specify a default, you get a `ComponentLookupError`...
- >>> capi.getUtility(I1) #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getUtility(I1) #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError: \
@@ -447,18 +455,18 @@
...otherwise, you get the default
- >>> capi.queryUtility(I1, default='<default>')
+ >>> zope.component.queryUtility(I1, default='<default>')
'<default>'
- >>> capi.queryUtility(I2, default='<default>')
+ >>> zope.component.queryUtility(I2, default='<default>')
'<default>'
Now we declare `ob` to be the utility providing `I1`
- >>> capi.getGlobalSiteManager().provideUtility(I1, ob)
+ >>> zope.component.getGlobalSiteManager().provideUtility(I1, ob)
so that the component is now available:
- >>> capi.getUtility(I1) is ob
+ >>> zope.component.getUtility(I1) is ob
True
"""
@@ -467,11 +475,12 @@
Just because you register an utility having no name
- >>> capi.getGlobalSiteManager().provideUtility(I1, ob)
+ >>> zope.component.getGlobalSiteManager().provideUtility(I1, ob)
does not mean that they are available when you specify a name:
- >>> capi.getUtility(I1, name='foo') #doctest: +NORMALIZE_WHITESPACE
+ >>> zope.component.getUtility(I1, name='foo') \\
+ ... #doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ComponentLookupError:
@@ -480,16 +489,17 @@
...otherwise, you get the default
- >>> capi.queryUtility(I1, name='foo', default='<default>')
+ >>> zope.component.queryUtility(I1, name='foo', default='<default>')
'<default>'
Registering the utility under the correct name
- >>> capi.getGlobalSiteManager().provideUtility(I1, ob, name='foo')
+ >>> zope.component.getGlobalSiteManager().provideUtility(
+ ... I1, ob, name='foo')
really helps:
- >>> capi.getUtility(I1, 'foo') is ob
+ >>> zope.component.getUtility(I1, 'foo') is ob
True
"""
@@ -511,7 +521,7 @@
Now we register the new utilities:
- >>> gsm = capi.getGlobalSiteManager()
+ >>> gsm = zope.component.getGlobalSiteManager()
>>> gsm.provideUtility(I1, ob)
>>> gsm.provideUtility(I11, ob11)
>>> gsm.provideUtility(I1, ob_bob, name='bob')
@@ -519,7 +529,7 @@
We can now get all the utilities that provide interface `I1`:
- >>> uts = list(capi.getAllUtilitiesRegisteredFor(I1))
+ >>> uts = list(zope.component.getAllUtilitiesRegisteredFor(I1))
>>> uts = [util.__class__.__name__ for util in uts]
>>> uts.sort()
>>> uts
Modified: Zope3/trunk/src/zope/i18n/tests/test_itranslationdomain.py
===================================================================
--- Zope3/trunk/src/zope/i18n/tests/test_itranslationdomain.py 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/src/zope/i18n/tests/test_itranslationdomain.py 2005-03-06 15:12:39 UTC (rev 29403)
@@ -19,7 +19,7 @@
from zope.interface.verify import verifyObject
from zope.interface import implements
-import zope.component as capi
+import zope.component
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.i18n.negotiator import negotiator
@@ -47,7 +47,7 @@
self._domain = self._getTranslationDomain()
# Setup the negotiator utility
- capi.provideUtility(negotiator, INegotiator)
+ zope.component.provideUtility(negotiator, INegotiator)
def testInterface(self):
verifyObject(ITranslationDomain, self._domain)
Modified: Zope3/trunk/src/zope/i18n/tests/test_translationdomain.py
===================================================================
--- Zope3/trunk/src/zope/i18n/tests/test_translationdomain.py 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/src/zope/i18n/tests/test_translationdomain.py 2005-03-06 15:12:39 UTC (rev 29403)
@@ -22,7 +22,7 @@
TestITranslationDomain, Environment
from zope.i18n import MessageIDFactory
from zope.i18n.interfaces import ITranslationDomain
-import zope.component as capi
+import zope.component
def testdir():
from zope.i18n import tests
@@ -102,7 +102,7 @@
os.path.join(path, 'en-default.mo'))
domain.addCatalog(en_catalog)
- capi.provideUtility(domain, ITranslationDomain, 'other')
+ zope.component.provideUtility(domain, ITranslationDomain, 'other')
factory = MessageIDFactory('other')
msgid = factory(u'short_greeting', 'default')
Modified: Zope3/trunk/src/zope/server/http/tests/test_publisherserver.py
===================================================================
--- Zope3/trunk/src/zope/server/http/tests/test_publisherserver.py 2005-03-05 15:21:05 UTC (rev 29402)
+++ Zope3/trunk/src/zope/server/http/tests/test_publisherserver.py 2005-03-06 15:12:39 UTC (rev 29403)
@@ -21,7 +21,7 @@
from zope.server.http.publisherhttpserver import PublisherHTTPServer
from zope.component.testing import PlacelessSetup
-import zope.component as capi
+import zope.component
from zope.i18n.interfaces import IUserPreferredCharsets
@@ -90,8 +90,8 @@
def setUp(self):
super(Tests, self).setUp()
- capi.provideAdapter(HTTPCharsets,
- [IHTTPRequest], IUserPreferredCharsets, '')
+ zope.component.provideAdapter(HTTPCharsets, [IHTTPRequest],
+ IUserPreferredCharsets, '')
obj = tested_object()
obj.folder = tested_object()
obj.folder.item = tested_object()
More information about the Zope3-Checkins
mailing list