[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/ More on MakeZopeAppSmaller:

Philipp von Weitershausen philikon at philikon.de
Tue Apr 4 04:07:11 EDT 2006


Log message for revision 66368:
  More on MakeZopeAppSmaller:
  * Move setDefaultSkin to zope.publisher.browser
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/app/debug/debug.py
  U   Zope3/branches/jim-adapter/src/zope/app/publication/browser.py
  U   Zope3/branches/jim-adapter/src/zope/app/publication/httpfactory.py
  U   Zope3/branches/jim-adapter/src/zope/app/publication/tests/test_browserpublication.py
  U   Zope3/branches/jim-adapter/src/zope/app/testing/functional.py
  U   Zope3/branches/jim-adapter/src/zope/publisher/browser.py
  A   Zope3/branches/jim-adapter/src/zope/publisher/tests/test_browser.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/debug/debug.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/debug/debug.py	2006-04-04 07:32:37 UTC (rev 66367)
+++ Zope3/branches/jim-adapter/src/zope/app/debug/debug.py	2006-04-04 08:07:08 UTC (rev 66368)
@@ -20,8 +20,8 @@
 import base64, time
 from StringIO import StringIO
 from zope.publisher.publish import publish as _publish, debug_call
-from zope.publisher.browser import TestRequest
-from zope.app.publication.browser import BrowserPublication, setDefaultSkin
+from zope.publisher.browser import TestRequest, setDefaultSkin
+from zope.app.publication.browser import BrowserPublication
 from zope.app.appsetup import config, database
 
 class Debugger(object):

Modified: Zope3/branches/jim-adapter/src/zope/app/publication/browser.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publication/browser.py	2006-04-04 07:32:37 UTC (rev 66367)
+++ Zope3/branches/jim-adapter/src/zope/app/publication/browser.py	2006-04-04 08:07:08 UTC (rev 66368)
@@ -20,19 +20,27 @@
 """
 __docformat__ = 'restructuredtext'
 
-from zope.interface import providedBy
-from zope.interface import directlyProvides
-
+from zope.component import queryMultiAdapter
 from zope.publisher.interfaces.browser import IBrowserPublisher
-from zope.publisher.interfaces.browser import IDefaultSkin
-from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from zope.security.checker import ProxyFactory
 
-from zope.app import zapi
 from zope.app.publication.publicationtraverse \
      import PublicationTraverser as PublicationTraverser_
 from zope.app.publication.http import BaseHTTPPublication
-from zope.security.checker import ProxyFactory
 
+##############################################################################
+# BBB 2006/04/03 - to be removed after 12 months
+
+import zope.deferredimport
+zope.deferredimport.deprecated(
+    "setDefaultSkin has been moved to zope.publisher.browser. This "
+    "reference will be removed in Zope 3.5.",
+    setDefaultSkin = 'zope.publisher.browser:setDefaultSkin',
+    )
+
+#
+##############################################################################
+
 class PublicationTraverser(PublicationTraverser_):
 
     def traverseRelativeURL(self, request, ob, path):
@@ -57,7 +65,7 @@
             # ob is already proxied, so the result of calling a method will be
             return ob.browserDefault(request)
         else:
-            adapter = zapi.queryMultiAdapter((ob, request), IBrowserPublisher)
+            adapter = queryMultiAdapter((ob, request), IBrowserPublisher)
             if adapter is not None:
                 ob, path = adapter.browserDefault(request)
                 ob = ProxyFactory(ob)
@@ -79,72 +87,3 @@
 
     def __call__(self):
         return self.__pub
-
-def setDefaultSkin(request):
-    """Sets the default skin for the request.
-
-    The default skin is a marker interface that can be registered as an
-    adapter that provides IDefaultSkin for the request type.
-
-    If a default skin is not available, the default layer
-    (IDefaultBrowserLayer) is used.
-
-    To illustrate, we'll first use setDefaultSkin without a registered
-    IDefaultSkin adapter:
-
-      >>> from zope.publisher.interfaces.browser import IBrowserRequest
-      >>> from zope.interface import implements
-      >>> class Request(object):
-      ...     implements(IBrowserRequest)
-
-      >>> request = Request()
-      >>> IDefaultBrowserLayer.providedBy(request)
-      False
-
-      >>> setDefaultSkin(request)
-      >>> IDefaultBrowserLayer.providedBy(request)
-      True
-
-    When we register a default layer, however:
-
-      >>> from zope.interface import Interface
-      >>> class IMySkin(Interface):
-      ...     pass
-      >>> from zope.app.testing import ztapi
-      >>> ztapi.provideAdapter(IBrowserRequest, IDefaultSkin, IMySkin)
-
-    setDefaultSkin uses the layer instead of IDefaultBrowserLayer.providedBy:
-
-      >>> request = Request()
-      >>> IMySkin.providedBy(request)
-      False
-      >>> IDefaultSkin.providedBy(request)
-      False
-
-      >>> setDefaultSkin(request)
-
-      >>> IMySkin.providedBy(request)
-      True
-      >>> IDefaultBrowserLayer.providedBy(request)
-      False
-
-    Any interfaces that are directly provided by the request coming into this
-    method are replaced by the applied layer/skin interface:
-
-      >>> request = Request()
-      >>> class IFoo(Interface):
-      ...     pass
-      >>> directlyProvides(request, IFoo)
-      >>> IFoo.providedBy(request)
-      True
-      >>> setDefaultSkin(request)
-      >>> IFoo.providedBy(request)
-      False
-
-    """
-    adapters = zapi.getSiteManager().adapters
-    skin = adapters.lookup((providedBy(request),), IDefaultSkin, '')
-    if skin is not None:
-        directlyProvides(request, skin)
-    else:
-        directlyProvides(request, IDefaultBrowserLayer)

Modified: Zope3/branches/jim-adapter/src/zope/app/publication/httpfactory.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publication/httpfactory.py	2006-04-04 07:32:37 UTC (rev 66367)
+++ Zope3/branches/jim-adapter/src/zope/app/publication/httpfactory.py	2006-04-04 08:07:08 UTC (rev 66368)
@@ -20,9 +20,9 @@
 from zope import interface
 
 from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.publisher.browser import setDefaultSkin
 
 from zope.app.publication import interfaces
-from zope.app.publication.browser import setDefaultSkin
 from zope.app.publication.requestpublicationregistry import factoryRegistry
 
 

Modified: Zope3/branches/jim-adapter/src/zope/app/publication/tests/test_browserpublication.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publication/tests/test_browserpublication.py	2006-04-04 07:32:37 UTC (rev 66367)
+++ Zope3/branches/jim-adapter/src/zope/app/publication/tests/test_browserpublication.py	2006-04-04 08:07:08 UTC (rev 66368)
@@ -16,9 +16,8 @@
 $Id: test_browserpublication.py 38357 2005-09-07 20:14:34Z srichter $
 """
 import unittest
-from zope.testing import doctest
 
-from zope.app.testing import placelesssetup, ztapi
+from zope.app.testing import ztapi
 from StringIO import StringIO
 
 from zope.security.interfaces import ForbiddenAttribute
@@ -316,10 +315,6 @@
         unittest.makeSuite(BrowserPublicationTests, 'test'),
         unittest.makeSuite(BrowserDefaultTests, 'test'),
         unittest.makeSuite(HTTPPublicationRequestFactoryTests, 'test'),
-        doctest.DocTestSuite('zope.app.publication.browser',
-                             setUp=placelesssetup.setUp,
-                             tearDown=placelesssetup.tearDown),
-
         ))
 
 

Modified: Zope3/branches/jim-adapter/src/zope/app/testing/functional.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/testing/functional.py	2006-04-04 07:32:37 UTC (rev 66367)
+++ Zope3/branches/jim-adapter/src/zope/app/testing/functional.py	2006-04-04 08:07:08 UTC (rev 66368)
@@ -32,7 +32,7 @@
 from ZODB.DemoStorage import DemoStorage
 
 from zope import interface, component
-from zope.publisher.browser import BrowserRequest
+from zope.publisher.browser import BrowserRequest, setDefaultSkin
 from zope.publisher.http import HTTPRequest
 from zope.publisher.publish import publish
 from zope.publisher.xmlrpc import XMLRPCRequest
@@ -44,7 +44,7 @@
 from zope.app import zapi
 from zope.app.debug import Debugger
 from zope.app.publication.http import HTTPPublication
-from zope.app.publication.browser import BrowserPublication, setDefaultSkin
+from zope.app.publication.browser import BrowserPublication
 from zope.app.publication.xmlrpc import XMLRPCPublication
 from zope.app.publication.soap import SOAPPublication
 from zope.app.publication.interfaces import ISOAPRequestFactory

Modified: Zope3/branches/jim-adapter/src/zope/publisher/browser.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/publisher/browser.py	2006-04-04 07:32:37 UTC (rev 66367)
+++ Zope3/branches/jim-adapter/src/zope/publisher/browser.py	2006-04-04 08:07:08 UTC (rev 66368)
@@ -24,11 +24,13 @@
 from types import ListType, TupleType, StringType, StringTypes
 from cgi import FieldStorage, escape
 
-from zope.interface import implements, directlyProvides
+import zope.component
+from zope.interface import implements, directlyProvides, providedBy
 from zope.i18n.interfaces import IUserPreferredLanguages
 from zope.i18n.interfaces import IUserPreferredCharsets
 from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from zope.publisher.interfaces.browser import IDefaultSkin
 from zope.publisher.interfaces.browser import IBrowserApplicationRequest
 
 from zope.publisher import contenttype
@@ -821,3 +823,70 @@
         accepts.reverse()
 
         return [lang for quality, lang in accepts]
+
+def setDefaultSkin(request):
+    """Sets the default skin for the request.
+
+    The default skin is a marker interface that can be registered as an
+    adapter that provides IDefaultSkin for the request type.
+
+    If a default skin is not available, the default layer
+    (IDefaultBrowserLayer) is used.
+
+    To illustrate, we'll first use setDefaultSkin without a registered
+    IDefaultSkin adapter:
+
+      >>> class Request(object):
+      ...     implements(IBrowserRequest)
+
+      >>> request = Request()
+      >>> IDefaultBrowserLayer.providedBy(request)
+      False
+
+      >>> setDefaultSkin(request)
+      >>> IDefaultBrowserLayer.providedBy(request)
+      True
+
+    When we register a default layer, however:
+
+      >>> from zope.interface import Interface
+      >>> class IMySkin(Interface):
+      ...     pass
+      >>> zope.component.provideAdapter(IMySkin, (IBrowserRequest,),
+      ...                               IDefaultSkin)
+
+    setDefaultSkin uses the layer instead of IDefaultBrowserLayer.providedBy:
+
+      >>> request = Request()
+      >>> IMySkin.providedBy(request)
+      False
+      >>> IDefaultSkin.providedBy(request)
+      False
+
+      >>> setDefaultSkin(request)
+
+      >>> IMySkin.providedBy(request)
+      True
+      >>> IDefaultBrowserLayer.providedBy(request)
+      False
+
+    Any interfaces that are directly provided by the request coming into this
+    method are replaced by the applied layer/skin interface:
+
+      >>> request = Request()
+      >>> class IFoo(Interface):
+      ...     pass
+      >>> directlyProvides(request, IFoo)
+      >>> IFoo.providedBy(request)
+      True
+      >>> setDefaultSkin(request)
+      >>> IFoo.providedBy(request)
+      False
+
+    """
+    adapters = zope.component.getSiteManager().adapters
+    skin = adapters.lookup((providedBy(request),), IDefaultSkin, '')
+    if skin is not None:
+        directlyProvides(request, skin)
+    else:
+        directlyProvides(request, IDefaultBrowserLayer)

Added: Zope3/branches/jim-adapter/src/zope/publisher/tests/test_browser.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/publisher/tests/test_browser.py	2006-04-04 07:32:37 UTC (rev 66367)
+++ Zope3/branches/jim-adapter/src/zope/publisher/tests/test_browser.py	2006-04-04 08:07:08 UTC (rev 66368)
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Test zope.publisher.browser doctests
+
+$Id$
+"""
+import unittest
+from zope.testing.doctestunit import DocTestSuite
+
+__docformat__ = "reStructuredText"
+
+def test_suite():
+    return unittest.TestSuite((
+        DocTestSuite('zope.publisher.browser'),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: Zope3/branches/jim-adapter/src/zope/publisher/tests/test_browser.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list