[Zope-Checkins] CVS: Zope/lib/python/ZPublisher/Browser - __init__.py:1.1.2.2 attrpub.py:1.1.2.2 browser.py:1.1.2.2
Shane Hathaway
shane@digicool.com
Thu, 25 Oct 2001 16:39:36 -0400
Update of /cvs-repository/Zope/lib/python/ZPublisher/Browser
In directory cvs.zope.org:/tmp/cvs-serv16082/Browser
Modified Files:
Tag: ComponentArchitecture-branch
__init__.py attrpub.py browser.py
Log Message:
Added DefaultBrowserPublish and cleaned up traverse() some more.
Also added _browser_renderable() but this will need review.
=== Zope/lib/python/ZPublisher/Browser/__init__.py 1.1.2.1 => 1.1.2.2 ===
BrowserPublish = IBrowserPublish
-from browser import LeafContentBrowserPublish
from attrpub import AttributePublisher
=== Zope/lib/python/ZPublisher/Browser/attrpub.py 1.1.2.1 => 1.1.2.2 ===
+
+from browser import IBrowserPublish
class AttributePublisher:
- __implements__ = IBrowserPublisher
+ __implements__ = IBrowserPublish
def browser_traverse(self, request, name):
if name[:1] == '_':
@@ -10,5 +11,5 @@
return getattr(self, name)
def browser_default(self, request):
- return "view"
-
+ return (self, ("view",))
+
=== Zope/lib/python/ZPublisher/Browser/browser.py 1.1.2.1 => 1.1.2.2 ===
import Interface
import ComponentArchitecture
-from ComponentArchitecture.Content import LeafContent
+from ComponentArchitecture import getPresentation, providePresentation
class HTTPException (Exception):
@@ -26,30 +26,56 @@
"""
-class LeafContentBrowserPublish:
+class DefaultBrowserPublish:
"""
- Adapter for content without items.
+ Default browser adapter.
"""
- __implements__ = BrowserPublish
+ __implements__ = IBrowserPublish
def __init__(self, content):
self._content = content
def _browser_traverse(self, request, name):
+ content = self._content
if name[:3] == '(p)':
- return ComponentArchitecture.getPresentation(
- self._content, name[3:], BrowserPublish)
+ return getPresentation(content, name[3:], IBrowserPublish)
else:
- # Can't traverse beyond leaf content.
- raise NotFound, name
+ # DWIM
+ try:
+ subob = getattr(content, name)
+ except AttributeError:
+ try: subob=content[name]
+ except (KeyError, IndexError,
+ TypeError, AttributeError):
+ try:
+ raise request.response.notFoundError(request['URL'])
+ except AttributeError:
+ raise KeyError, name
+ if not IBrowserPublish.isImplementedBy(subob):
+ # Will return another DefaultBrowserPublish if no other
+ # presentation is registered.
+ subob = getPresentation(subob, '_default', IBrowserPublish)
+ return subob
def _browser_default(self, request):
- p = ComponentArchitecture.getPresentation(
- self._content, '', BrowserPublish)
- return p._browser_default(request)
+ content = self._content
+ p = getPresentation(content, '', IBrowserPublish, None)
+ if p is not None:
+ return p._browser_default(request)
+ else:
+ m = request._request_method
+ if m == 'GET' or m == 'POST':
+ default = 'index_html'
+ else:
+ default = m
+ if default and getattr(content, default, None) is not None:
+ return (content, (default,))
+ return (content, ())
+
+ def _browser_renderable(self):
+ return self._content
-ComponentArchitecture.providePresentation(
- LeafContent, '_default', BrowserPublish, LeafContentBrowserPublish)
+providePresentation(None, '_default', IBrowserPublish, DefaultBrowserPublish)