[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/tests/ztapi.py The presentation service is gone. Reimplement helper functions.

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Sep 17 12:15:44 EDT 2004


Log message for revision 27573:
  
  The presentation service is gone. Reimplement helper functions.
  
  Add new `provideMultiView` function.
  
  


Changed:
  U   Zope3/trunk/src/zope/app/tests/ztapi.py


-=-
Modified: Zope3/trunk/src/zope/app/tests/ztapi.py
===================================================================
--- Zope3/trunk/src/zope/app/tests/ztapi.py	2004-09-17 16:15:42 UTC (rev 27572)
+++ Zope3/trunk/src/zope/app/tests/ztapi.py	2004-09-17 16:15:44 UTC (rev 27573)
@@ -15,74 +15,76 @@
 
 $Id$
 """
-from zope.app import zapi
 import zope.interface
-from zope.component.servicenames import Presentation, Adapters, Utilities
+from zope.component.interfaces import IDefaultViewName
 from zope.publisher.browser import IBrowserRequest
+from zope.app import zapi
 from zope.app.traversing.interfaces import ITraversable
 
-def provideView(for_, type, providing, name, factory, layer="default"):
-    s = zapi.getGlobalServices().getService(Presentation)
-    return s.provideView(for_, name, type, factory, layer,
-                         providing=providing)
-    
+def provideView(for_, type, providing, name, factory, layer=None):
+    if layer is None:
+        layer = type
+    provideAdapter(for_, providing, factory, name, (layer,))    
 
-def browserView(for_, name, factory, layer='default',
+def provideMultiView(for_, type, providing, name, factory, layer=None):
+    if layer is None:
+        layer = type
+    provideAdapter(for_[0], providing, factory, name, tuple(for_[1:])+(layer,))
+
+def browserView(for_, name, factory, layer=IBrowserRequest,
                 providing=zope.interface.Interface):
     """Define a global browser view
     """
     if isinstance(factory, (list, tuple)):
         raise ValueError("Factory cannot be a list or tuple")
-    s = zapi.getGlobalServices().getService(Presentation)
-    return s.provideView(for_, name, IBrowserRequest, factory, layer,
-                         providing=providing)
+    provideAdapter(for_, providing, factory, name, (layer,))
 
-def browserViewProviding(for_, factory, providing, layer='default'):
+def browserViewProviding(for_, factory, providing, layer=IBrowserRequest):
     """Define a view providing a particular interface."""
     if isinstance(factory, (list, tuple)):
         raise ValueError("Factory cannot be a list or tuple")
     return browserView(for_, '', factory, layer, providing)
 
-def browserResource(name, factory, layer='default',
+def browserResource(name, factory, layer=IBrowserRequest,
                     providing=zope.interface.Interface):
     """Define a global browser view
     """
     if isinstance(factory, (list, tuple)):
         raise ValueError("Factory cannot be a list or tuple")
-    s = zapi.getGlobalServices().getService(Presentation)
-    return s.provideResource(name, IBrowserRequest, factory, layer,
-                             providing=providing)
+    provideAdapter((layer,), providing, factory, name)
 
-def setDefaultViewName(for_, name, layer='default'):
-    s = zapi.getGlobalServices().getService(Presentation)
-    s.setDefaultViewName(for_, IBrowserRequest, name, layer=layer)
+def setDefaultViewName(for_, name, layer=None, type=IBrowserRequest):
+    if layer is None:
+        layer = type
+    s = zapi.getGlobalServices().getService(zapi.servicenames.Adapters)
+    s.register((for_, layer), IDefaultViewName, '', name)
 
 stypes = list, tuple
 def provideAdapter(required, provided, factory, name='', with=()):
     if isinstance(factory, (list, tuple)):
         raise ValueError("Factory cannot be a list or tuple")
-    s = zapi.getGlobalServices().getService(Adapters)
+    s = zapi.getGlobalServices().getService(zapi.servicenames.Adapters)
 
     if with:
         required = (required, ) + tuple(with)
     elif not isinstance(required, stypes):
-        required = [required]
+        required = (required,)
 
     s.register(required, provided, name, factory)
 
 def subscribe(required, provided, factory):
-    s = zapi.getGlobalServices().getService(Adapters)
+    s = zapi.getGlobalServices().getService(zapi.servicenames.Adapters)
     s.subscribe(required, provided, factory)
 
 def handle(required, handler):
     subscribe(required, None, handler)
 
 def provideUtility(provided, component, name=''):
-    s = zapi.getGlobalServices().getService(Utilities)
+    s = zapi.getGlobalServices().getService(zapi.servicenames.Utilities)
     s.provideUtility(provided, component, name)
 
 def unprovideUtility(provided, name=''):
-    s = zapi.getGlobalServices().getService(Utilities)
+    s = zapi.getGlobalServices().getService(zapi.servicenames.Utilities)
     s.register((), provided, name, None)
 
 def provideNamespaceHandler(name, handler):



More information about the Zope3-Checkins mailing list