[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/traversing/ The presentation service is gone.

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


Log message for revision 27576:
  
  The presentation service is gone.
  
  Skins are now interfaces that are directly provided by the request. The skin
  namespace handler simply makes the call.
  
  Also adjusted testing code to get rid of `getPresentationSkin()`.
  
  


Changed:
  U   Zope3/trunk/src/zope/app/traversing/namespace.py
  U   Zope3/trunk/src/zope/app/traversing/tests/test_namespacetrversal.py
  U   Zope3/trunk/src/zope/app/traversing/tests/test_skin.py


-=-
Modified: Zope3/trunk/src/zope/app/traversing/namespace.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/namespace.py	2004-09-17 16:15:47 UTC (rev 27575)
+++ Zope3/trunk/src/zope/app/traversing/namespace.py	2004-09-17 16:15:50 UTC (rev 27576)
@@ -16,13 +16,15 @@
 $Id$
 """
 import re
+
 import zope.interface
+from zope.interface import providedBy, directlyProvides, directlyProvidedBy
 from zope import component
-from zope.component.servicenames import Presentation
 from zope.exceptions import NotFoundError
+from zope.publisher.interfaces.browser import ISkin
+from zope.security.proxy import removeSecurityProxy
 
 from zope.app.traversing.interfaces import ITraversable, IPathAdapter
-from zope.security.proxy import removeSecurityProxy
 
 class UnexpectedParameters(NotFoundError):
     "Unexpected namespace parameters were provided."
@@ -348,8 +350,14 @@
 
     def traverse(self, name, ignored):
         self.request.shiftNameToApplication()
-        self.request.setPresentationSkin(name)
-
+        skin = component.getUtility(ISkin, name)
+        # Remove all existing skin declarations (commonly the default skin).
+        ifaces = [iface
+                  for iface in directlyProvidedBy(self.request)
+                  if not ISkin.providedBy(iface)]
+        # Add the new skin.
+        ifaces.append(skin)
+        directlyProvides(self.request, *ifaces)
         return self.context
 
 class vh(view):
@@ -465,12 +473,20 @@
 
         ++debug++errors enables tracebacks (by switching to debug skin)
 
-            >>> request.getPresentationSkin()
-            'default'
+            >>> from zope.app.tests import ztapi
+            >>> from zope.publisher.interfaces.browser import IBrowserRequest
+
+            >>> class Debug(IBrowserRequest):
+            ...     pass
+            >>> directlyProvides(Debug, ISkin)
+            >>> ztapi.provideUtility(ISkin, Debug, 'Debug')
+
+            >>> Debug.providedBy(request)
+            False
             >>> adapter.traverse('errors', ()) is ob
             True
-            >>> request.getPresentationSkin()
-            'Debug'
+            >>> Debug.providedBy(request)
+            True
 
         You can specify several flags separated by commas
 
@@ -497,7 +513,8 @@
                     # 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?
-                    request.setPresentationSkin('Debug')
+                    skin = component.getUtility(ISkin, 'Debug')
+                    directlyProvides(request, providedBy(request)+skin)
                 else:
                     raise ValueError("Unknown debug flag: %s" % flag)
             return self.context
@@ -538,8 +555,8 @@
 
         ++debug++errors enables tracebacks (by switching to debug skin)
 
-            >>> request.getPresentationSkin()
-            'default'
+            >>> Debug.providedBy(request)
+            False
             >>> adapter.traverse('errors', ()) is ob
             Traceback (most recent call last):
             ...

Modified: Zope3/trunk/src/zope/app/traversing/tests/test_namespacetrversal.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/tests/test_namespacetrversal.py	2004-09-17 16:15:47 UTC (rev 27575)
+++ Zope3/trunk/src/zope/app/traversing/tests/test_namespacetrversal.py	2004-09-17 16:15:50 UTC (rev 27576)
@@ -15,11 +15,14 @@
 
 $Id$
 """
+from unittest import main
+from zope.testing.doctestunit import DocTestSuite
 
+from zope.app.tests.placelesssetup import setUp, tearDown
+
 def test_suite():
-    from doctest import DocTestSuite
-    return DocTestSuite('zope.app.traversing.namespace')
+    return DocTestSuite('zope.app.traversing.namespace',
+                        setUp=setUp, tearDown=tearDown)
 
 if __name__ == '__main__':
-    from unittest import main
     main(defaultTest='test_suite')

Modified: Zope3/trunk/src/zope/app/traversing/tests/test_skin.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/tests/test_skin.py	2004-09-17 16:15:47 UTC (rev 27575)
+++ Zope3/trunk/src/zope/app/traversing/tests/test_skin.py	2004-09-17 16:15:50 UTC (rev 27576)
@@ -16,24 +16,37 @@
 $Id$
 """
 from unittest import TestCase, main, makeSuite
+from zope.interface import Interface, directlyProvides
 
-class Test(TestCase):
+from zope.publisher.interfaces.browser import ISkin
+from zope.app.tests import ztapi
+from zope.app.tests.placelesssetup import PlacelessSetup
 
+
+class FauxRequest(object):
+    def shiftNameToApplication(self):
+        self.shifted = 1
+
+class IFoo(Interface):
+    pass
+directlyProvides(IFoo, ISkin)
+
+
+class Test(PlacelessSetup, TestCase):
+
+    def setUp(self):
+        super(Test, self).setUp()
+        ztapi.provideUtility(ISkin, IFoo, 'foo')
+
     def test(self):
         from zope.app.traversing.namespace import skin
 
-        class FauxRequest(object):
-            def shiftNameToApplication(self):
-                self.shifted = 1
-            skin = ''
-            def setPresentationSkin(self, skin):
-                self.skin = skin
 
         request = FauxRequest()
         ob = object()
         ob2 = skin(ob, request).traverse('foo', ())
         self.assertEqual(ob, ob2)
-        self.assertEqual(request.skin, 'foo')
+        self.assert_(IFoo.providedBy(request))
         self.assertEqual(request.shifted, 1)
 
 def test_suite():



More information about the Zope3-Checkins mailing list