[Checkins] SVN: zope.app.publication/trunk/ Changed my mind: put the <browser:defaultView> handler back in zope.app.publisher, but moved the defaultview API to zope.publisher.

Shane Hathaway shane at hathawaymix.org
Sat May 23 02:04:43 EDT 2009


Log message for revision 100281:
  Changed my mind: put the <browser:defaultView> handler back in zope.app.publisher, but moved the defaultview API to zope.publisher.
  

Changed:
  U   zope.app.publication/trunk/CHANGES.txt
  D   zope.app.publication/trunk/src/zope/app/publication/defaultview.py
  U   zope.app.publication/trunk/src/zope/app/publication/meta.zcml
  U   zope.app.publication/trunk/src/zope/app/publication/metaconfigure.py
  U   zope.app.publication/trunk/src/zope/app/publication/metadirectives.py
  D   zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py
  U   zope.app.publication/trunk/src/zope/app/publication/traversers.py
  U   zope.app.publication/trunk/src/zope/app/publication/zopepublication.py

-=-
Modified: zope.app.publication/trunk/CHANGES.txt
===================================================================
--- zope.app.publication/trunk/CHANGES.txt	2009-05-23 06:03:27 UTC (rev 100280)
+++ zope.app.publication/trunk/CHANGES.txt	2009-05-23 06:04:43 UTC (rev 100281)
@@ -12,14 +12,10 @@
 - Moved IHTTPException to zope.publisher, removing the dependency
   on zope.app.http.
 
-- Moved the DefaultViewName API from zope.app.publisher to
-  zope.app.publication, removing the dependency on
-  zope.app.publisher except for testing purposes.
+- Moved the DefaultViewName API from zope.app.publisher.browser to
+  zope.publisher.defaultview, making it accessible to other packages
+  that need it.
 
-- Moved the <browser:defaultView> directive handler to
-  zope.app.publication, since zope.app.publication is what
-  uses the registration.
-
 3.6.0 (2009-05-18)
 ------------------
 

Deleted: zope.app.publication/trunk/src/zope/app/publication/defaultview.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/defaultview.py	2009-05-23 06:03:27 UTC (rev 100280)
+++ zope.app.publication/trunk/src/zope/app/publication/defaultview.py	2009-05-23 06:04:43 UTC (rev 100281)
@@ -1,92 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""Default view name API
-
-$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.
-        """
-
-# 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.publication.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

Modified: zope.app.publication/trunk/src/zope/app/publication/meta.zcml
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/meta.zcml	2009-05-23 06:03:27 UTC (rev 100280)
+++ zope.app.publication/trunk/src/zope/app/publication/meta.zcml	2009-05-23 06:04:43 UTC (rev 100281)
@@ -5,12 +5,4 @@
         schema=".metadirectives.IRequestPublicationDirective"
         handler=".metaconfigure.publisher"
         />
-
-  <meta:directive
-        namespace="http://namespaces.zope.org/browser"
-        name="defaultView"
-        schema=".metadirectives.IDefaultViewDirective"
-        handler=".metaconfigure.defaultView"
-        />
-
 </configure>

Modified: zope.app.publication/trunk/src/zope/app/publication/metaconfigure.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/metaconfigure.py	2009-05-23 06:03:27 UTC (rev 100280)
+++ zope.app.publication/trunk/src/zope/app/publication/metaconfigure.py	2009-05-23 06:04:43 UTC (rev 100281)
@@ -11,21 +11,16 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" Directive handlers
+""" Directive handler for publication factory
 
-See metadirectives.py
+See metadirective.py
 
 $Id$
 """
 __docformat__ = 'restructuredtext'
 
 from zope.app.publication.requestpublicationregistry import factoryRegistry
-from zope.component.interface import provideInterface
-from zope.component.zcml import handler
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.publisher.interfaces import IDefaultViewName
 
-
 def publisher(_context, name, factory, methods=['*'], mimetypes=['*'],
               priority=0):
 
@@ -38,20 +33,3 @@
                 callable = factoryRegistry.register,
                 args = (method, mimetype, name, priority, factory)
                 )
-
-
-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.publication/trunk/src/zope/app/publication/metadirectives.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/metadirectives.py	2009-05-23 06:03:27 UTC (rev 100280)
+++ zope.app.publication/trunk/src/zope/app/publication/metadirectives.py	2009-05-23 06:04:43 UTC (rev 100281)
@@ -28,7 +28,6 @@
 
 from zope.interface import Interface
 from zope.configuration.fields import GlobalObject, Tokens
-from zope.configuration.fields import GlobalInterface
 from zope.schema import TextLine, Int
 
 class IRequestPublicationDirective(Interface):
@@ -62,37 +61,3 @@
         description=(u'A priority key used to concurrent'
                      ' publication factories.'),
         required=False)
-
-
-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
-        )

Deleted: zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py	2009-05-23 06:03:27 UTC (rev 100280)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py	2009-05-23 06:04:43 UTC (rev 100281)
@@ -1,131 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 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
-#
-##############################################################################
-"""Default View Tests
-
-$Id$
-"""
-from cStringIO import StringIO
-from zope.component import queryMultiAdapter
-from zope.component.testfiles.views import IC
-from zope.configuration.xmlconfig import XMLConfig
-from zope.configuration.xmlconfig import xmlconfig
-from zope.interface import implements
-from zope.publisher.browser import TestRequest
-from zope.publisher.interfaces import IDefaultViewName
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.testing.cleanup import cleanUp
-from zope.testing.doctestunit import DocTestSuite
-import unittest
-
-template = """<configure
-   xmlns='http://namespaces.zope.org/zope'
-   xmlns:browser='http://namespaces.zope.org/browser'
-   i18n_domain='zope'>
-   %s
-   </configure>"""
-
-
-class TestDefaultViewDirective(unittest.TestCase):
-
-    def setUp(self):
-        cleanUp()
-        import zope.app.publication
-        XMLConfig('meta.zcml', zope.app.publication)()
-
-    def tearDown(self):
-        cleanUp()
-
-    def testDefaultView(self):
-        ob = TestOb()
-        request = TestRequest()
-        self.assertEqual(
-            queryMultiAdapter((ob, request), IDefaultViewName), None)
-
-        xmlconfig(StringIO(template % (
-            '''
-            <browser:defaultView
-                name="test"
-                for="zope.component.testfiles.views.IC" />
-            '''
-            )))
-
-        from zope.app.publication.defaultview import getDefaultViewName
-        self.assertEqual(getDefaultViewName(ob, request), 'test')
-
-    def testDefaultViewWithLayer(self):
-        ob = TestOb()
-        request = TestRequest()
-        class FakeRequest(TestRequest):
-            implements(ITestLayer)
-        request2 = FakeRequest()
-
-        self.assertEqual(
-            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.publication.tests.test_defaultview.ITestLayer"
-                />
-            '''
-            )))
-
-        from zope.app.publication.defaultview import getDefaultViewName
-        self.assertEqual(getDefaultViewName(ob, request2), 'test2')
-        self.assertEqual(getDefaultViewName(ob, request), 'test')
-
-    def testDefaultViewForClass(self):
-        ob = TestOb()
-        request = TestRequest()
-        self.assertEqual(
-            queryMultiAdapter((ob, request), IDefaultViewName), None)
-
-        xmlconfig(StringIO(template % (
-            '''
-            <browser:defaultView
-                for="zope.app.publication.tests.test_defaultview.TestOb"
-                name="test"
-                />
-            '''
-            )))
-
-        from zope.app.publication.defaultview import getDefaultViewName
-        self.assertEqual(getDefaultViewName(ob, request), 'test')
-
-
-class ITestLayer(IBrowserRequest):
-    """Test Layer."""
-
-class TestOb(object):
-    implements(IC)
-
-def cleanUpDoc(args):
-    cleanUp()
-
-def test_suite():
-    return unittest.TestSuite([
-        DocTestSuite('zope.app.publication.defaultview',
-            setUp=cleanUpDoc, tearDown=cleanUpDoc),
-        unittest.makeSuite(TestDefaultViewDirective),
-        ])
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')

Modified: zope.app.publication/trunk/src/zope/app/publication/traversers.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/traversers.py	2009-05-23 06:03:27 UTC (rev 100280)
+++ zope.app.publication/trunk/src/zope/app/publication/traversers.py	2009-05-23 06:04:43 UTC (rev 100281)
@@ -23,7 +23,7 @@
 from zope.publisher.interfaces import Unauthorized, NotFound
 from zope.publisher.interfaces.browser import IBrowserPublisher
 from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
-from zope.app.publication.defaultview import getDefaultViewName
+from zope.publisher.defaultview import getDefaultViewName
 
 class SimpleComponentTraverser(object):
     """Browser traverser for simple components that can only traverse to views

Modified: zope.app.publication/trunk/src/zope/app/publication/zopepublication.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/zopepublication.py	2009-05-23 06:03:27 UTC (rev 100280)
+++ zope.app.publication/trunk/src/zope/app/publication/zopepublication.py	2009-05-23 06:04:43 UTC (rev 100281)
@@ -45,7 +45,7 @@
 from zope.app.publication.interfaces import BeforeTraverseEvent
 from zope.app.publication.interfaces import EndRequestEvent
 from zope.traversing.publicationtraverse import PublicationTraverse
-from zope.app.publication.defaultview import queryDefaultViewName
+from zope.publisher.defaultview import queryDefaultViewName
 from zope.authentication.interfaces import IUnauthenticatedPrincipal
 from zope.authentication.interfaces import IFallbackUnauthenticatedPrincipal
 from zope.authentication.interfaces import IAuthentication



More information about the Checkins mailing list