[Checkins] SVN: zope.app.publisher/trunk/ Moved the <browser:defaultView> directive handler to

Shane Hathaway shane at hathawaymix.org
Sat May 23 01:13:23 EDT 2009


Log message for revision 100278:
  Moved the <browser:defaultView> directive handler to
  zope.app.publication, since zope.app.publication is what
  uses the registration.
  

Changed:
  U   zope.app.publisher/trunk/CHANGES.txt
  U   zope.app.publisher/trunk/setup.py
  U   zope.app.publisher/trunk/src/zope/app/publisher/browser/__init__.py
  A   zope.app.publisher/trunk/src/zope/app/publisher/browser/_defaultview.py
  U   zope.app.publisher/trunk/src/zope/app/publisher/browser/meta.zcml
  U   zope.app.publisher/trunk/src/zope/app/publisher/browser/metaconfigure.py
  U   zope.app.publisher/trunk/src/zope/app/publisher/browser/metadirectives.py
  U   zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_directives.py

-=-
Modified: zope.app.publisher/trunk/CHANGES.txt
===================================================================
--- zope.app.publisher/trunk/CHANGES.txt	2009-05-23 05:09:37 UTC (rev 100277)
+++ zope.app.publisher/trunk/CHANGES.txt	2009-05-23 05:13:22 UTC (rev 100278)
@@ -12,6 +12,9 @@
   zope.app.publisher -> zope.app.publication dependency (which was a
   cycle).
 
+- Moved the <browser:defaultView> directive handler to
+  zope.app.publication, since zope.app.publication is what
+  uses the registration.
 
 3.7.0 (2009-05-22)
 ==================

Modified: zope.app.publisher/trunk/setup.py
===================================================================
--- zope.app.publisher/trunk/setup.py	2009-05-23 05:09:37 UTC (rev 100277)
+++ zope.app.publisher/trunk/setup.py	2009-05-23 05:13:22 UTC (rev 100278)
@@ -47,6 +47,7 @@
                         'zope.container',
                         'zope.contenttype',
                         'zope.datetime',
+                        'zope.deferredimport',
                         'zope.i18n',
                         'zope.interface',
                         'zope.location',

Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/__init__.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/__init__.py	2009-05-23 05:09:37 UTC (rev 100277)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/__init__.py	2009-05-23 05:13:22 UTC (rev 100278)
@@ -15,86 +15,23 @@
 
 $Id$
 """
-from zope.component.interfaces import ComponentLookupError
-from zope.component import getSiteManager
 
-import zope.interface
 from zope.interface import implements
 from zope.publisher.browser import BrowserLanguages
-from zope.publisher.interfaces import IDefaultViewName
 from zope.i18n.interfaces import IUserPreferredLanguages
 from zope.i18n.interfaces import IModifiableUserPreferredLanguages
 
+import zope.deferredimport
 
-class IDefaultViewNameAPI(zope.interface.Interface):
+zope.deferredimport.deprecatedFrom(
+    "This import has moved to zope.app.publication.defaultview. "
+    "This import will stop working in the future.",
+    'zope.app.publisher.browser._defaultview',
+    'IDefaultViewNameAPI',
+    'getDefaultViewName',
+    'queryDefaultViewName',
+    )
 
-    def getDefaultViewName(object, request, context=None):
-        """Get the name of the default view for the object and request.
-
-        If a matching default view name cannot be found, raises
-        ComponentLookupError.
-
-        If context is not specified, attempts to use
-        object to specify a context.
-        """
-
-    def queryDefaultViewName(object, request, default=None, context=None):
-        """Look for the name of the default view for the object and request.
-
-        If a matching default view name cannot be found, returns the default.
-
-        If context is not specified, attempts to use object to specify
-        a context.
-        """
-
-# TODO: needs tests
-def getDefaultViewName(object, request, context=None):
-    name = queryDefaultViewName(object, request, context=context)
-    if name is not None:
-        return name
-    raise ComponentLookupError("Couldn't find default view name",
-                               context, request)
-
-def queryDefaultViewName(object, request, default=None, context=None):
-    """
-    query the default view for a given object and request.
-
-      >>> from zope.app.publisher.browser import queryDefaultViewName
-
-    lets create an object with a default view.
-
-      >>> import zope.interface
-      >>> class IMyObject(zope.interface.Interface):
-      ...   pass
-      >>> class MyObject(object):
-      ...   zope.interface.implements(IMyObject)
-      >>> queryDefaultViewName(MyObject(), object()) is None
-      True
-
-    Now we can will set a default view.
-
-      >>> import zope.component
-      >>> import zope.publisher.interfaces
-      >>> zope.component.provideAdapter('name',
-      ...     adapts=(IMyObject, zope.interface.Interface),
-      ...     provides=zope.publisher.interfaces.IDefaultViewName)
-      >>> queryDefaultViewName(MyObject(), object())
-      'name'
-
-    This also works if the name is empty
-
-      >>> zope.component.provideAdapter('',
-      ...     adapts=(IMyObject, zope.interface.Interface),
-      ...     provides=zope.publisher.interfaces.IDefaultViewName)
-      >>> queryDefaultViewName(MyObject(), object())
-      ''
-    """
-    name = getSiteManager(context).adapters.lookup(
-        map(zope.interface.providedBy, (object, request)), IDefaultViewName)
-    if name is None:
-        return default
-    return name
-
 class NotCompatibleAdapterError(Exception):
     """Adapter not compatible with
        zope.i18n.interfaces.IModifiableBrowserLanguages has been used.

Copied: zope.app.publisher/trunk/src/zope/app/publisher/browser/_defaultview.py (from rev 100243, zope.app.publisher/trunk/src/zope/app/publisher/browser/__init__.py)
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/_defaultview.py	                        (rev 0)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/_defaultview.py	2009-05-23 05:13:22 UTC (rev 100278)
@@ -0,0 +1,94 @@
+##############################################################################
+#
+# Copyright (c) 2003 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.
+#
+##############################################################################
+"""Deprecated copy of zope.app.publication.defaultview.
+
+Use zope.app.publication.defaultview instead!
+
+$Id$
+"""
+from zope.component.interfaces import ComponentLookupError
+from zope.component import getSiteManager
+
+import zope.interface
+from zope.publisher.interfaces import IDefaultViewName
+
+
+class IDefaultViewNameAPI(zope.interface.Interface):
+
+    def getDefaultViewName(object, request, context=None):
+        """Get the name of the default view for the object and request.
+
+        If a matching default view name cannot be found, raises
+        ComponentLookupError.
+
+        If context is not specified, attempts to use
+        object to specify a context.
+        """
+
+    def queryDefaultViewName(object, request, default=None, context=None):
+        """Look for the name of the default view for the object and request.
+
+        If a matching default view name cannot be found, returns the default.
+
+        If context is not specified, attempts to use object to specify
+        a context.
+        """
+
+def getDefaultViewName(object, request, context=None):
+    name = queryDefaultViewName(object, request, context=context)
+    if name is not None:
+        return name
+    raise ComponentLookupError("Couldn't find default view name",
+                               context, request)
+
+def queryDefaultViewName(object, request, default=None, context=None):
+    """
+    query the default view for a given object and request.
+
+      >>> from zope.app.publisher.browser._defaultview import (
+      ...     queryDefaultViewName)
+
+    lets create an object with a default view.
+
+      >>> import zope.interface
+      >>> class IMyObject(zope.interface.Interface):
+      ...   pass
+      >>> class MyObject(object):
+      ...   zope.interface.implements(IMyObject)
+      >>> queryDefaultViewName(MyObject(), object()) is None
+      True
+
+    Now we can will set a default view.
+
+      >>> import zope.component
+      >>> import zope.publisher.interfaces
+      >>> zope.component.provideAdapter('name',
+      ...     adapts=(IMyObject, zope.interface.Interface),
+      ...     provides=zope.publisher.interfaces.IDefaultViewName)
+      >>> queryDefaultViewName(MyObject(), object())
+      'name'
+
+    This also works if the name is empty
+
+      >>> zope.component.provideAdapter('',
+      ...     adapts=(IMyObject, zope.interface.Interface),
+      ...     provides=zope.publisher.interfaces.IDefaultViewName)
+      >>> queryDefaultViewName(MyObject(), object())
+      ''
+    """
+    name = getSiteManager(context).adapters.lookup(
+        map(zope.interface.providedBy, (object, request)), IDefaultViewName)
+    if name is None:
+        return default
+    return name


Property changes on: zope.app.publisher/trunk/src/zope/app/publisher/browser/_defaultview.py
___________________________________________________________________
Added: cvs2svn:cvs-rev
   + 1.6
Added: svn:keywords
   + Id
Added: svn:mergeinfo
   + 
Added: svn:eol-style
   + native

Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/meta.zcml
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/meta.zcml	2009-05-23 05:09:37 UTC (rev 100277)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/meta.zcml	2009-05-23 05:13:22 UTC (rev 100278)
@@ -70,13 +70,6 @@
 
     </meta:complexDirective>
 
-    <meta:directive
-        name="defaultView"
-        schema=".metadirectives.IDefaultViewDirective"
-        handler=".metaconfigure.defaultView"
-        />
-
-
     <!-- browser pages -->
 
     <meta:directive

Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/metaconfigure.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/metaconfigure.py	2009-05-23 05:09:37 UTC (rev 100277)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/metaconfigure.py	2009-05-23 05:13:22 UTC (rev 100278)
@@ -19,14 +19,10 @@
 
 import warnings
 from zope import component
-from zope.component.interface import provideInterface
 from zope.component.zcml import handler
-from zope.configuration.exceptions import ConfigurationError
-from zope.interface import directlyProvides
-from zope.interface.interface import InterfaceClass
-from zope.publisher.interfaces import IDefaultViewName
-from zope.publisher.interfaces.browser import IBrowserRequest, IDefaultSkin
+from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.publisher.interfaces.browser import IBrowserSkinType
+from zope.publisher.interfaces.browser import IDefaultSkin
 
 # referred to through ZCML
 from zope.app.publisher.browser.resourcemeta import resource
@@ -64,19 +60,3 @@
         callable = setDefaultSkin,
         args = (name, _context.info)
         )
-
-def defaultView(_context, name, for_=None, layer=IBrowserRequest):
-
-    _context.action(
-        discriminator = ('defaultViewName', for_, layer, name),
-        callable = handler,
-        args = ('registerAdapter',
-                name, (for_, layer), IDefaultViewName, '', _context.info)
-        )
-
-    if for_ is not None:
-        _context.action(
-            discriminator = None,
-            callable = provideInterface,
-            args = ('', for_)
-            )

Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/metadirectives.py	2009-05-23 05:09:37 UTC (rev 100277)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/metadirectives.py	2009-05-23 05:13:22 UTC (rev 100278)
@@ -148,39 +148,6 @@
         required=True
         )
 
-class IDefaultViewDirective(Interface):
-    """
-    The name of the view that should be the default.
-
-    This name refers to view that should be the
-    view used by default (if no view name is supplied
-    explicitly).
-    """
-
-    name = TextLine(
-        title=u"The name of the view that should be the default.",
-        description=u"""
-        This name refers to view that should be the view used by
-        default (if no view name is supplied explicitly).""",
-        required=True
-        )
-
-    for_ = GlobalObject(
-        title=u"The interface this view is the default for.",
-        description=u"""Specifies the interface for which the view is
-        registered. All objects implementing this interface can make use of
-        this view. If this attribute is not specified, the view is available
-        for all objects.""",
-        required=False
-        )
-
-    layer = GlobalInterface(
-        title=u"The layer the default view is declared for",
-        description=u"The default layer for which the default view is "
-                    u"applicable. By default it is applied to all layers.",
-        required=False
-        )
-
 #
 # browser pages
 #

Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_directives.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_directives.py	2009-05-23 05:09:37 UTC (rev 100277)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_directives.py	2009-05-23 05:13:22 UTC (rev 100278)
@@ -28,7 +28,6 @@
 from zope.configuration.xmlconfig import xmlconfig, XMLConfig
 from zope.configuration.exceptions import ConfigurationError
 from zope.publisher.browser import TestRequest
-from zope.publisher.interfaces import IDefaultViewName
 from zope.publisher.interfaces.browser import IBrowserPublisher
 from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.publisher.interfaces.browser import IBrowserSkinType, IDefaultSkin
@@ -302,73 +301,6 @@
         v = component.queryMultiAdapter((ob, request), name='test')
         self.assertEqual(v(), "<html><body><p>test</p></body></html>\n")
 
-    def testDefaultView(self):
-        self.assertEqual(
-            component.queryMultiAdapter((ob, request), IDefaultViewName),
-            None)
-
-        xmlconfig(StringIO(template % (
-            '''
-            <browser:defaultView
-                name="test"
-                for="zope.component.testfiles.views.IC" />
-            '''
-            )))
-
-        self.assertEqual(
-            zope.app.publisher.browser.getDefaultViewName(ob, request),
-            'test')
-
-    def testDefaultViewWithLayer(self):
-        class FakeRequest(TestRequest):
-            implements(ITestLayer)
-        request2 = FakeRequest()
-
-        self.assertEqual(
-            component.queryMultiAdapter((ob, request2), IDefaultViewName),
-            None)
-
-        xmlconfig(StringIO(template % (
-            '''
-            <browser:defaultView
-                name="test"
-                for="zope.component.testfiles.views.IC" />
-
-            <browser:defaultView
-                name="test2"
-                for="zope.component.testfiles.views.IC"
-                layer="
-                  zope.app.publisher.browser.tests.test_directives.ITestLayer"
-                />
-            '''
-            )))
-
-        self.assertEqual(
-            zope.app.publisher.browser.getDefaultViewName(ob, request2),
-            'test2')
-        self.assertEqual(
-            zope.app.publisher.browser.getDefaultViewName(ob, request),
-            'test')
-
-    def testDefaultViewForClass(self):
-        self.assertEqual(
-            component.queryMultiAdapter((ob, request), IDefaultViewName),
-            None)
-
-        xmlconfig(StringIO(template % (
-            '''
-            <browser:defaultView
-                for="zope.app.publisher.browser.tests.test_directives.Ob"
-                name="test"
-                />
-            '''
-            )))
-
-        self.assertEqual(
-            zope.app.publisher.browser.getDefaultViewName(ob, request),
-            'test')
-
-
     def testSkinResource(self):
         self.assertEqual(
             component.queryAdapter(Request(IV), name='test'), None)



More information about the Checkins mailing list