[Zope3-checkins] SVN: Zope3/trunk/src/zope/component/ The
presentation service is gone.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Sep 17 12:16:44 EDT 2004
Log message for revision 27600:
The presentation service is gone.
Adjust presentation API to use the adpater service instead.
Changed:
U Zope3/trunk/src/zope/component/__init__.py
U Zope3/trunk/src/zope/component/tests/test_api.py
-=-
Modified: Zope3/trunk/src/zope/component/__init__.py
===================================================================
--- Zope3/trunk/src/zope/component/__init__.py 2004-09-17 16:16:42 UTC (rev 27599)
+++ Zope3/trunk/src/zope/component/__init__.py 2004-09-17 16:16:44 UTC (rev 27600)
@@ -17,13 +17,14 @@
"""
import sys
import warnings
-from zope.interface import moduleProvides, Interface
+from zope.interface import moduleProvides, Interface, providedBy
from zope.interface.interfaces import IInterface
from zope.component.interfaces import IComponentArchitecture, IFactory
from zope.component.interfaces import IServiceService
+from zope.component.interfaces import IDefaultViewName
from zope.component.exceptions import ComponentLookupError
from zope.component.service import serviceManager
-from zope.component.servicenames import Adapters, Presentation, Utilities
+from zope.component.servicenames import Adapters, Utilities
# Try to be hookable. Do so in a try/except to avoid a hard dependency.
try:
@@ -200,7 +201,7 @@
break
-# Presentation service
+# Presentation API
def getView(object, name, request, providing=Interface, context=None):
view = queryView(object, name, request, context=context,
@@ -213,9 +214,8 @@
def queryView(object, name, request,
default=None, providing=Interface, context=None):
- s = getService(Presentation, context=context)
- return s.queryView(object, name, request,
- default=default, providing=providing)
+ return queryMultiAdapter((object, request), providing, name,
+ default, context)
queryView = hookable(queryView)
@@ -229,8 +229,8 @@
def queryMultiView(objects, request, providing=Interface, name='',
default=None, context=None):
- s = getService(Presentation, context)
- return s.queryMultiView(objects, request, providing, name, default)
+ return queryMultiAdapter(objects+(request,), providing, name,
+ default, context)
def getViewProviding(object, providing, request, context=None):
return getView(object, '', request, providing, context)
@@ -248,9 +248,17 @@
context, request)
def queryDefaultViewName(object, request, default=None, context=None):
- s = getService(Presentation, context)
- return s.queryDefaultViewName(object, request, default)
+ try:
+ adapters = getService(Adapters, context)
+ except ComponentLookupError:
+ # Oh blast, no adapter service. We're probably just running from a test
+ return default
+ name = adapters.lookup(map(providedBy, (object, request)), IDefaultViewName)
+ if name is not None:
+ return name
+ return default
+
def getResource(name, request, providing=Interface, context=None):
view = queryResource(name, request, providing=providing, context=context)
if view is not None:
@@ -260,5 +268,4 @@
def queryResource(name, request, default=None, providing=Interface,
context=None):
- s = getService(Presentation, context)
- return s.queryResource(name, request, default=default, providing=providing)
+ return queryAdapter(request, providing, name, default, context)
Modified: Zope3/trunk/src/zope/component/tests/test_api.py
===================================================================
--- Zope3/trunk/src/zope/component/tests/test_api.py 2004-09-17 16:16:42 UTC (rev 27599)
+++ Zope3/trunk/src/zope/component/tests/test_api.py 2004-09-17 16:16:44 UTC (rev 27600)
@@ -31,6 +31,7 @@
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.component.tests.request import Request
from zope.component.interfaces import IComponentArchitecture, IServiceService
+from zope.component.interfaces import IDefaultViewName
from zope.interface import Interface, implements
from zope.interface.verify import verifyObject
@@ -326,8 +327,7 @@
getView, ob, 'foo', Request(I2))
self.assertEquals(queryView(ob, 'foo', Request(I2), Test), Test)
- getService(servicenames.Presentation).provideView(
- I1, 'foo', I2, Comp)
+ getService(Adapters).register([I1, I2], Interface, 'foo', Comp)
c = getView(ob, 'foo', Request(I2))
self.assertEquals(c.__class__, Comp)
self.assertEquals(c.context, ob)
@@ -352,8 +352,7 @@
queryView(ob, 'foo', Request(I2), Test, providing=I3),
Test)
- getService(servicenames.Presentation).provideView(
- I1, 'foo', I2, Comp)
+ getService(Adapters).register([I1, I2], Interface, 'foo', Comp)
self.assertRaises(ComponentLookupError,
getView, ob, 'foo', Request(I1), providing=I3)
@@ -363,10 +362,8 @@
queryView(ob, 'foo', Request(I2), Test, providing=I3),
Test)
+ getService(Adapters).register([I1, I2], I3, 'foo', Comp)
- getService(servicenames.Presentation).provideView(
- I1, 'foo', I2, Comp, providing=I3)
-
c = getView(ob, 'foo', Request(I2), providing=I3)
self.assertEquals(c.__class__, Comp)
self.assertEquals(c.context, ob)
@@ -393,8 +390,7 @@
self.assertEquals(
queryMultiView((ob, ob2), request, I3, 'foo', 42), 42)
- getService(servicenames.Presentation).provideAdapter(
- IRequest, MV, 'foo', (I1, I2), I3)
+ getService(Adapters).register((I1, I2, IRequest), I3, 'foo', MV)
view = queryMultiView((ob, ob2), request, I3, 'foo')
self.assertEquals(view.__class__, MV)
@@ -427,7 +423,7 @@
savedQueryView = zope.component.queryView
zope.component.queryView = queryView
- # confirm pass through of args to queryView by way of queryViewProviding
+ # confirm pass through of args to queryView by way of queryViewProviding
zope.component.queryViewProviding(
object='object', providing='providing', request='request',
default='default', context='context')
@@ -449,8 +445,7 @@
self.assertRaises(ComponentLookupError, getResource, 'foo', r2)
self.assertEquals(queryResource('foo', r2, Test), Test)
- getService(servicenames.Presentation).provideResource(
- 'foo', I2, Comp)
+ getService(Adapters).register((I2,), Interface, 'foo', Comp)
c = getResource('foo', r2)
self.assertEquals(c.__class__, Comp)
self.assertEquals(c.context, r2)
@@ -475,8 +470,7 @@
self.assertEquals(queryResource('foo', r2, Test, providing=I3),
Test)
- getService(servicenames.Presentation).provideResource(
- 'foo', I2, Comp)
+ getService(Adapters).register((I2,), Interface, 'foo', Comp)
self.assertRaises(ComponentLookupError,
getResource, 'foo', r1, providing=I3)
@@ -485,10 +479,8 @@
self.assertEquals(queryResource('foo', r2, Test, providing=I3),
Test)
+ getService(Adapters).register((I2,), I3, 'foo', Comp)
- getService(servicenames.Presentation).provideResource(
- 'foo', I2, Comp, providing=I3)
-
c = getResource('foo', r2, providing=I3)
self.assertEquals(c.__class__, Comp)
self.assertEquals(c.context, r2)
@@ -507,8 +499,8 @@
self.assertEquals(queryView(ob, 'foo', Request(I2), Test, context=ob),
Test)
- getService(servicenames.Presentation).provideView(
- I1, 'foo', I2, Comp)
+ getService(Adapters, ob).register((I1, I2), Interface, 'foo', Comp)
+
c = getView(ob, 'foo', Request(I2), context=ob)
self.assertEquals(c.__class__, Comp)
self.assertEquals(c.context, ob)
@@ -528,11 +520,11 @@
def testDefaultViewName(self):
from zope.component import getService
from zope.exceptions import NotFoundError
- viewService = getService(servicenames.Presentation)
+ getService(Adapters).register((I1, I2), IDefaultViewName,
+ '', 'sample_name')
self.assertRaises(NotFoundError,
getDefaultViewName,
ob, Request(I1))
- viewService.setDefaultViewName(I1, I2, 'sample_name')
self.assertEquals(getDefaultViewName(ob, Request(I2)),
'sample_name')
self.assertRaises(NotFoundError,
More information about the Zope3-Checkins
mailing list