[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZopePublication/Browser - BrowserPublication.py:1.1.2.1 BrowserPublicationTraverse.py:1.1.2.1 BrowserTraversers.py:1.1.2.1 __init__.py:1.1.2.1 browser.zcml:1.1.2.1
Stephan Richter
srichter@cbu.edu
Mon, 4 Mar 2002 00:07:08 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/ZopePublication/Browser
In directory cvs.zope.org:/tmp/cvs-serv12070/Browser
Added Files:
Tag: srichter-OFS_Formulator-branch
BrowserPublication.py BrowserPublicationTraverse.py
BrowserTraversers.py __init__.py browser.zcml
Log Message:
This package got a major revamp, so here is what I have done:
- reorganized the package in a way that it becomes multiple-protocol
firendly, like the Publisher.
- Separated generic code from Browser code
- Removed Traversers.py and PublicationTraverse.py for the above reason
- Refactor Browser{Publication|PublicationTraverse|Traversers}
- Same as above with XML-RPC
ToDo:
- Write tests.
- Update interfaces
=== Added File Zope3/lib/python/Zope/App/ZopePublication/Browser/BrowserPublication.py ===
##############################################################################
#
# 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.0 (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
#
##############################################################################
"""
$Id: BrowserPublication.py,v 1.1.2.1 2002/03/04 05:07:07 srichter Exp $
"""
from Zope.ContextWrapper import wrapper
from Zope.App.Security.SecurityManagement import getSecurityManager
from Zope.ComponentArchitecture import getRequestView
from BrowserPublicationTraverse import BrowserPublicationTraverse
from Zope.App.ZopePublication.ZopePublication import ZopePublication
from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
class BrowserPublication(BrowserPublicationTraverse, ZopePublication):
"""Web browser (HTTP) publication handling."""
def _parameterSetskin(self, pname, pval, request):
request.setViewSkin(pval)
def getDefaultTraversal(self, request, ob):
r = ()
if IBrowserPublisher.isImplementedBy(ob):
r = ob.browser_default(request)
else:
adapter = getRequestView(ob, '_traverse', request , None)
if adapter is not None:
r = adapter.browser_default(request)
else:
return (ob, None)
if r[0] is ob: return r
wrapped = wrapper.Wrapper(r[0], ob, name=None)
getSecurityManager().validate(None, wrapped)
return (wrapped, r[1])
=== Added File Zope3/lib/python/Zope/App/ZopePublication/Browser/BrowserPublicationTraverse.py ===
##############################################################################
#
# 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.0 (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
#
##############################################################################
"""
$Id: BrowserPublicationTraverse.py,v 1.1.2.1 2002/03/04 05:07:07 srichter Exp $
"""
from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
from Zope.ComponentArchitecture import getRequestView
from Zope.Publisher.Exceptions import NotFound
from Zope.App.ZopePublication.HTTP.HTTPPublicationTraverse import \
HTTPPublicationTraverse, HTTPPublicationTraverser
class BrowserPublicationTraverse(HTTPPublicationTraverse):
""" """
# XXX WE REALLY SHOULD USE INTERFACES HERE
def getViewFromObject(self, object, name, request):
if IBrowserPublisher.isImplementedBy(object):
view = object.browser_traverse(request, name)
else:
adapter = getRequestView(object, '_traverse', request,
self ) # marker
if adapter is not self:
view = adapter.browser_traverse(request, name)
else:
raise NotFound(object, name, request)
return view
class BrowserPublicationTraverser(HTTPPublicationTraverser,
BrowserPublicationTraverse):
""" """
pass
=== Added File Zope3/lib/python/Zope/App/ZopePublication/Browser/BrowserTraversers.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.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.
from Zope.Publisher.Exceptions import Unauthorized, NotFound, DebugError
from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
from Zope.ComponentArchitecture \
import getRequestView, getRequestDefaultViewName
class DefaultTraverser:
"""
"""
__implements__ = IBrowserPublisher
def __init__(self, target):
self.target = target
def browser_default(self, request):
#XXX: (hack), we really need this to be component
# specific.
ob = self.target
# if ob is not a component return
if not hasattr(ob, '__implements__'):
return ob,()
view_name = getRequestDefaultViewName(ob, request)
view_uri = "%s;view" % view_name
return ob, (view_uri,)
def browser_traverse(self, request, name):
""" """
# TODO: Look for default view
ob = self.target
if name.startswith('_'):
raise Unauthorized("Name %s begins with an underscore" % `name`)
if name.endswith(';view'):
return getRequestView( ob, name[:-5], request)
if hasattr(ob, name):
subob = getattr(ob, name)
else:
try:
subob = ob[name]
except (KeyError, IndexError,
TypeError, AttributeError):
raise NotFound(ob, name, request)
return subob
=== Added File Zope3/lib/python/Zope/App/ZopePublication/Browser/__init__.py ===
##############################################################################
#
# 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.0 (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
#
##############################################################################
"""
Zope publication package.
$Id: __init__.py,v 1.1.2.1 2002/03/04 05:07:07 srichter Exp $
"""
=== Added File Zope3/lib/python/Zope/App/ZopePublication/Browser/browser.zcml ===
<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:browser='http://namespaces.zope.org/browser'
>
<browser:view name="_traverse"
factory="Zope.App.ZopePublication.Browser.BrowserTraversers.DefaultTraverser." />
</zopeConfigure>