[Checkins] SVN: zope.app.publication/trunk/ Moved the DefaultViewName API from zope.app.publisher to
Shane Hathaway
shane at hathawaymix.org
Sat May 23 00:23:23 EDT 2009
Log message for revision 100276:
Moved the DefaultViewName API from zope.app.publisher to
zope.app.publication, removing the dependency on
zope.app.publisher except for testing purposes.
Changed:
U zope.app.publication/trunk/CHANGES.txt
U zope.app.publication/trunk/setup.py
A zope.app.publication/trunk/src/zope/app/publication/defaultview.py
A 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 03:03:53 UTC (rev 100275)
+++ zope.app.publication/trunk/CHANGES.txt 2009-05-23 04:23:22 UTC (rev 100276)
@@ -12,6 +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.
+
3.6.0 (2009-05-18)
------------------
Modified: zope.app.publication/trunk/setup.py
===================================================================
--- zope.app.publication/trunk/setup.py 2009-05-23 03:03:53 UTC (rev 100275)
+++ zope.app.publication/trunk/setup.py 2009-05-23 04:23:22 UTC (rev 100276)
@@ -54,6 +54,7 @@
'zope.app.securitypolicy',
'zope.app.zcmlfiles>=3.5.4',
'zope.app.dav',
+ 'zope.app.publisher',
'zope.app.zptpage',
'zope.principalregistry',
]),
@@ -68,7 +69,6 @@
'zope.browser>=1.2',
'zope.publisher>=3.8.0',
'zope.traversing>=3.7.0',
- 'zope.app.publisher',
'setuptools',
],
include_package_data = True,
Added: zope.app.publication/trunk/src/zope/app/publication/defaultview.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/defaultview.py (rev 0)
+++ zope.app.publication/trunk/src/zope/app/publication/defaultview.py 2009-05-23 04:23:22 UTC (rev 100276)
@@ -0,0 +1,92 @@
+##############################################################################
+#
+# 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
Added: zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py (rev 0)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_defaultview.py 2009-05-23 04:23:22 UTC (rev 100276)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# 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 unittest import main
+from zope.testing.doctestunit import DocTestSuite
+from zope.component.testing import setUp, tearDown
+
+def test_suite():
+ return DocTestSuite('zope.app.publication.defaultview',
+ setUp=setUp, tearDown=tearDown)
+
+if __name__ == '__main__':
+ 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 03:03:53 UTC (rev 100275)
+++ zope.app.publication/trunk/src/zope/app/publication/traversers.py 2009-05-23 04:23:22 UTC (rev 100276)
@@ -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.publisher.browser import getDefaultViewName
+from zope.app.publication.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 03:03:53 UTC (rev 100275)
+++ zope.app.publication/trunk/src/zope/app/publication/zopepublication.py 2009-05-23 04:23:22 UTC (rev 100276)
@@ -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.publisher.browser import queryDefaultViewName
+from zope.app.publication.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