Commit 687ff981 authored by Stefan H. Holek's avatar Stefan H. Holek

Merged 2.10 branch r70085:70086 and r70356:70357 into the trunk.

Collector #2187: PUT_factory broken.
parents 69e478dd 7b4c9134
...@@ -109,6 +109,8 @@ Zope Changes ...@@ -109,6 +109,8 @@ Zope Changes
- The defaultView directive now only looks up views, not attributes. - The defaultView directive now only looks up views, not attributes.
- Collector #2187: PUT_factory broken (fwd port from 2.10 branch).
Other Changes Other Changes
- Disabled docutils file inclusion completely, rather than trying - Disabled docutils file inclusion completely, rather than trying
......
...@@ -72,37 +72,41 @@ class DefaultPublishTraverse(object): ...@@ -72,37 +72,41 @@ class DefaultPublishTraverse(object):
if name[:1]=='_': if name[:1]=='_':
raise Forbidden("Object name begins with an underscore at: %s" % URL) raise Forbidden("Object name begins with an underscore at: %s" % URL)
try:
if hasattr(object,'__bobo_traverse__'): if hasattr(object,'__bobo_traverse__'):
try:
subobject=object.__bobo_traverse__(request, name) subobject=object.__bobo_traverse__(request, name)
if type(subobject) is type(()) and len(subobject) > 1: if type(subobject) is type(()) and len(subobject) > 1:
# Add additional parents into the path # Add additional parents into the path
# XXX This needs handling. Check the publish refactor branch... # XXX There are no tests for this:
parents[-1:] = list(subobject[:-1]) request['PARENTS'][-1:] = list(subobject[:-1])
object, subobject = subobject[-2:] object, subobject = subobject[-2:]
except (AttributeError, KeyError, NotFound), e:
# Try to find a view
subobject = queryMultiAdapter((object, request), Interface, name)
if subobject is not None:
# OFS.Application.__bobo_traverse__ calls
# REQUEST.RESPONSE.notFoundError which sets the HTTP
# status code to 404
request.response.setStatus(200)
# We don't need to do the docstring security check
# for views, so lets skip it and return the object here.
return subobject.__of__(object)
# No view found. Reraise the error raised by __bobo_traverse__
raise e
else:
# No __bobo_traverse__
# Try with an unacquired attribute:
if hasattr(aq_base(object), name):
subobject = getattr(object, name)
else: else:
# Try getting unacquired attributes: # We try to fall back to a view:
if hasattr(aq_base(object), name): subobject = queryMultiAdapter((object, request), Interface, name)
subobject = getattr(object, name) if subobject is not None:
else: return subobject.__of__(object)
subobject=object[name]
except (AttributeError, KeyError, NotFound), e:
# Nothing was found with __bobo_traverse__ or directly on
# the object. We try to fall back to a view:
subobject = queryMultiAdapter((object, request), Interface, name)
if subobject is not None:
# OFS.Application.__bobo_traverse__ calls
# REQUEST.RESPONSE.notFoundError which sets the HTTP
# status code to 404
request.response.setStatus(200)
# We don't need to do the docstring security check
# for views, so lets skip it and return the object here.
return subobject.__of__(object)
# And lastly, of there is no view, try acquired attributes, but # And lastly, of there is no view, try acquired attributes, but
# only if there is no __bobo_traverse__: # only if there is no __bobo_traverse__:
if not hasattr(object,'__bobo_traverse__'):
try: try:
subobject=getattr(object, name) subobject=getattr(object, name)
# Again, clear any error status created by __bobo_traverse__ # Again, clear any error status created by __bobo_traverse__
...@@ -111,7 +115,10 @@ class DefaultPublishTraverse(object): ...@@ -111,7 +115,10 @@ class DefaultPublishTraverse(object):
return subobject return subobject
except AttributeError: except AttributeError:
pass pass
raise e
# Lastly we try with key access:
subobject = object[name]
# Ensure that the object has a docstring, or that the parent # Ensure that the object has a docstring, or that the parent
# object has a pseudo-docstring for the object. Objects that # object has a pseudo-docstring for the object. Objects that
......
import unittest
import Testing
import Zope2
Zope2.startup()
from Testing.makerequest import makerequest
import transaction
import base64
auth_info = 'Basic %s' % base64.encodestring('manager:secret').rstrip()
class TestPUTFactory(unittest.TestCase):
def setUp(self):
self.app = makerequest(Zope2.app())
try:
# Make a manager user
uf = self.app.acl_users
uf._doAddUser('manager', 'secret', ['Manager'], [])
# Make a folder to put stuff into
self.app.manage_addFolder('folder', '')
self.folder = self.app.folder
# Fake a WebDAV PUT request
request = self.app.REQUEST
request['PARENTS'] = [self.app]
request['BODY'] = 'bar'
request.environ['CONTENT_TYPE'] = 'text/plain'
request.environ['REQUEST_METHOD'] = 'PUT'
request._auth = auth_info
except:
self.tearDown()
raise
def tearDown(self):
transaction.abort()
self.app.REQUEST.close()
self.app._p_jar.close()
def testNoVirtualHosting(self):
request = self.app.REQUEST
put = request.traverse('/folder/doc')
put(request, request.RESPONSE)
self.failUnless('doc' in self.folder.objectIds())
def testSimpleVirtualHosting(self):
request = self.app.REQUEST
put = request.traverse('/VirtualHostBase/http/foo.com:80/VirtualHostRoot/folder/doc')
put(request, request.RESPONSE)
self.failUnless('doc' in self.folder.objectIds())
def testSubfolderVirtualHosting(self):
request = self.app.REQUEST
put = request.traverse('/VirtualHostBase/http/foo.com:80/folder/VirtualHostRoot/doc')
put(request, request.RESPONSE)
self.failUnless('doc' in self.folder.objectIds())
def testInsideOutVirtualHosting(self):
request = self.app.REQUEST
put = request.traverse('/VirtualHostBase/http/foo.com:80/VirtualHostRoot/_vh_foo/folder/doc')
put(request, request.RESPONSE)
self.failUnless('doc' in self.folder.objectIds())
def testSubfolderInsideOutVirtualHosting(self):
request = self.app.REQUEST
put = request.traverse('/VirtualHostBase/http/foo.com:80/folder/VirtualHostRoot/_vh_foo/doc')
put(request, request.RESPONSE)
self.failUnless('doc' in self.folder.objectIds())
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestPUTFactory),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment