/usr/share/pyshared/zope/app/publication/traversers.py is in python-zope.app.publication 3.13.2-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation 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.
#
##############################################################################
"""Generic object traversers
"""
__docformat__ = 'restructuredtext'
import zope.component
from zope.interface import providedBy, implements
from zope.publisher.interfaces import Unauthorized, NotFound
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.publisher.defaultview import getDefaultViewName
class SimpleComponentTraverser(object):
"""Browser traverser for simple components that can only traverse to views
"""
implements(IBrowserPublisher, IXMLRPCPublisher)
def __init__(self, context, request):
self.context = context
self.request = request
def browserDefault(self, request):
ob = self.context
view_name = getDefaultViewName(ob, request)
return ob, (view_name,)
def publishTraverse(self, request, name):
ob = self.context
view = zope.component.queryMultiAdapter((ob, request), name=name)
if view is None:
raise NotFound(ob, name)
return view
class FileContentTraverser(SimpleComponentTraverser):
"""Browser traverser for file content.
The default view for file content has effective URLs that don't end in
/. In particular, if the content inclused HTML, relative links in
the HTML are relative to the container the content is in.
"""
def browserDefault(self, request):
ob = self.context
view_name = getDefaultViewName(ob, request)
view = self.publishTraverse(request, view_name)
if hasattr(view, 'browserDefault'):
view, path = view.browserDefault(request)
if len(path) == 1:
view = view.publishTraverse(request, path[0])
path = ()
else:
path = ()
return view, path
def NoTraverser(ob, request):
return None
class TestTraverser(object):
"""Bobo-style traverser, mostly useful for testing"""
implements(IBrowserPublisher)
def __init__(self, context, request):
self.context = context
def browserDefault(self, request):
ob = self.context
if list(providedBy(ob)):
view_name = getDefaultViewName(ob, request)
return ob, (("@@%s" % view_name),)
return ob, ()
def publishTraverse(self, request, name):
ob = self.context
if name.startswith('@@'):
return zope.component.getMultiAdapter((ob, request), name=name[6:])
if name.startswith('_'):
raise Unauthorized(name)
subob = getattr(ob, name, self) # self is marker here
if subob is self:
# no attribute
try:
subob = ob[name]
except (KeyError, IndexError,
TypeError, AttributeError):
raise NotFound(ob, name, request)
return subob
|