[Checkins] SVN: zope.app.http/trunk/ PUT raises ``405 MethodNotAllowed`` when the context cannot be adapted to ``zope.filerepresentation.interfaces.IWriteFile`` for existing objects resp. ``zope.filerepresentation.interfaces.IFileFactory`` for not existing ones.
Michael Howitz
mh at gocept.com
Tue Jan 25 04:50:21 EST 2011
Log message for revision 119895:
PUT raises ``405 MethodNotAllowed`` when the context cannot be adapted to ``zope.filerepresentation.interfaces.IWriteFile`` for existing objects resp. ``zope.filerepresentation.interfaces.IFileFactory`` for not existing ones.
Changed:
U zope.app.http/trunk/CHANGES.txt
U zope.app.http/trunk/src/zope/app/http/put.py
U zope.app.http/trunk/src/zope/app/http/tests/test_put.py
-=-
Modified: zope.app.http/trunk/CHANGES.txt
===================================================================
--- zope.app.http/trunk/CHANGES.txt 2011-01-25 07:54:15 UTC (rev 119894)
+++ zope.app.http/trunk/CHANGES.txt 2011-01-25 09:50:21 UTC (rev 119895)
@@ -2,10 +2,13 @@
CHANGES
=======
-3.9.1 (unreleased)
+3.10.0 (unreleased)
------------------
-- Nothing changed yet.
+- PUT raises ``405 MethodNotAllowed`` when the context cannot be adapted to
+ ``zope.filerepresentation.interfaces.IWriteFile`` for existing objects
+ resp. ``zope.filerepresentation.interfaces.IFileFactory`` for not existing
+ ones.
3.9.0 (2010-09-17)
Modified: zope.app.http/trunk/src/zope/app/http/put.py
===================================================================
--- zope.app.http/trunk/src/zope/app/http/put.py 2011-01-25 07:54:15 UTC (rev 119894)
+++ zope.app.http/trunk/src/zope/app/http/put.py 2011-01-25 09:50:21 UTC (rev 119895)
@@ -9,10 +9,7 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
##############################################################################
-"""HTTP `PUT` verb
-
-$Id$
-"""
+"""HTTP `PUT` verb"""
__docformat__ = 'restructuredtext'
from zope.component import queryAdapter
@@ -23,9 +20,10 @@
from zope.filerepresentation.interfaces import \
IWriteDirectory, IReadDirectory, IFileFactory
import zope.traversing.browser
-
+import zope.publisher.interfaces.http
from zope.app.http.interfaces import INullResource
+
class NullResource(object):
"""Object representing objects to be created by a `PUT`.
"""
@@ -72,7 +70,10 @@
# Fall back to a non-custom one
if factory is None:
- factory = IFileFactory(container)
+ factory = IFileFactory(container, None)
+ if factory is None:
+ raise zope.publisher.interfaces.http.MethodNotAllowed(
+ container, self.request)
# TODO: Need to add support for large files
data = body.read()
@@ -81,7 +82,7 @@
notify(ObjectCreatedEvent(newfile))
dir_write[name] = newfile
- # Ickyness with non-predictable support for containment:
+ # Ickyness with non-predictable support for containment:
# make sure we get a containment proxy
newfile = dir_read[name]
@@ -103,7 +104,10 @@
def PUT(self):
body = self.request.bodyStream
file = self.context
- adapter = IWriteFile(file)
+ adapter = IWriteFile(file, None)
+ if adapter is None:
+ raise zope.publisher.interfaces.http.MethodNotAllowed(
+ self.context, self.request)
length = int(self.request.get('CONTENT_LENGTH', -1))
adapter.write(body.read(length))
Modified: zope.app.http/trunk/src/zope/app/http/tests/test_put.py
===================================================================
--- zope.app.http/trunk/src/zope/app/http/tests/test_put.py 2011-01-25 07:54:15 UTC (rev 119894)
+++ zope.app.http/trunk/src/zope/app/http/tests/test_put.py 2011-01-25 09:50:21 UTC (rev 119895)
@@ -116,6 +116,19 @@
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 201)
+ def test_put_on_invalid_container_raises_MethodNotAllowed(self):
+ import zope.publisher.interfaces.http
+
+ request = TestRequest(StringIO(),
+ {'CONTENT_TYPE': 'test/foo',
+ 'CONTENT_LENGTH': '0',
+ })
+ null = zope.app.http.put.NullResource(rootFolder(), 'spam.txt')
+ put = zope.app.http.put.NullPUT(null, request)
+ self.assertRaises(zope.publisher.interfaces.http.MethodNotAllowed,
+ put.PUT)
+
+
class TestFilePUT(TestCase):
layer = BrowserLayer(zope.app.http)
@@ -151,6 +164,19 @@
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 200)
+ def test_put_on_invalid_file_raises_MethodNotAllowed(self):
+ import zope.publisher.interfaces.http
+
+ file = object()
+ request = TestRequest(StringIO(),
+ {'CONTENT_TYPE': 'test/foo',
+ 'CONTENT_LENGTH': '0',
+ })
+ put = zope.app.http.put.FilePUT(file, request)
+ self.assertRaises(zope.publisher.interfaces.http.MethodNotAllowed,
+ put.PUT)
+
+
def test_suite():
return TestSuite((
makeSuite(TestFilePUT),
More information about the checkins
mailing list