[Zope3-checkins] SVN: Zope3/branches/3.2/ Fixed issue 497: HTTP
DELETE now returns 405 Method Not Allowed when the
Marius Gedminas
marius at pov.lt
Fri Dec 16 13:58:50 EST 2005
Log message for revision 40824:
Fixed issue 497: HTTP DELETE now returns 405 Method Not Allowed when the
container cannot be adapted to IWriteDirectory.
Changed:
U Zope3/branches/3.2/doc/CHANGES.txt
U Zope3/branches/3.2/src/zope/app/http/delete.py
U Zope3/branches/3.2/src/zope/app/http/tests/test_delete.py
U Zope3/branches/3.2/src/zope/app/publication/methodnotallowed.txt
-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt 2005-12-16 18:48:13 UTC (rev 40823)
+++ Zope3/branches/3.2/doc/CHANGES.txt 2005-12-16 18:58:49 UTC (rev 40824)
@@ -23,6 +23,9 @@
attributes were ignored if you didn't explicitly specify a
class for the viewlet.
+ - Fixed issue 497: HTTP DELETE now returns 405 Method Not Allowed
+ when the container cannot be adapted to IWriteDirectory.
+
Zope 3.2.0b1 (2005/12/06)
New features
Modified: Zope3/branches/3.2/src/zope/app/http/delete.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/http/delete.py 2005-12-16 18:48:13 UTC (rev 40823)
+++ Zope3/branches/3.2/src/zope/app/http/delete.py 2005-12-16 18:58:49 UTC (rev 40824)
@@ -16,7 +16,9 @@
__docformat__ = 'restructuredtext'
from zope.app.filerepresentation.interfaces import IWriteDirectory
+from zope.app.publication.http import MethodNotAllowed
+
class DELETE(object):
"""Delete handler for all objects
"""
@@ -34,7 +36,9 @@
# Get a "directory" surrogate for the container
- dir = IWriteDirectory(container)
+ dir = IWriteDirectory(container, None)
+ if dir is None:
+ raise MethodNotAllowed(self.context, self.request)
del dir[name]
Modified: Zope3/branches/3.2/src/zope/app/http/tests/test_delete.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/http/tests/test_delete.py 2005-12-16 18:48:13 UTC (rev 40823)
+++ Zope3/branches/3.2/src/zope/app/http/tests/test_delete.py 2005-12-16 18:58:49 UTC (rev 40824)
@@ -22,7 +22,13 @@
from zope.app.testing.placelesssetup import PlacelessSetup
from zope.interface import implements
from zope.app.container.contained import contained
+from zope.app.publication.http import MethodNotAllowed
+
+class UnwritableContainer(object):
+ pass
+
+
class Container(object):
implements(IWriteDirectory, IFileFactory)
@@ -44,6 +50,15 @@
self.assertEqual(delete.DELETE(), '')
self.assert_(not hasattr(container, 'a'))
+ def test_not_deletable(self):
+ container = UnwritableContainer()
+ container.a = 'spam'
+ item = contained(UnwritableContainer(), container, name='a')
+ request = TestRequest()
+ delete = zope.app.http.delete.DELETE(item, request)
+ self.assertRaises(MethodNotAllowed, delete.DELETE)
+
+
def test_suite():
return TestSuite((
makeSuite(TestDelete),
Modified: Zope3/branches/3.2/src/zope/app/publication/methodnotallowed.txt
===================================================================
--- Zope3/branches/3.2/src/zope/app/publication/methodnotallowed.txt 2005-12-16 18:48:13 UTC (rev 40823)
+++ Zope3/branches/3.2/src/zope/app/publication/methodnotallowed.txt 2005-12-16 18:58:49 UTC (rev 40824)
@@ -13,17 +13,17 @@
<BLANKLINE>
Method Not Allowed
-The requests below should return 405, but instead crash with a TypeError,
+ >>> print http(r"""
+ ... DELETE / HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 405 Method Not Allowed
+ ...
+
+The request below should return 405, but instead crashes with a TypeError,
when the view tries to adapt context to IWriteFile.
# >>> print http(r"""
-# ... DELETE / HTTP/1.1
-# ... Authorization: Basic mgr:mgrpw
-# ... """, handle_errors=False)
-# HTTP/1.1 405 Method Not Allowed
-# ...
-#
-# >>> print http(r"""
# ... PUT / HTTP/1.1
# ... Authorization: Basic mgr:mgrpw
# ... """, handle_errors=False)
More information about the Zope3-Checkins
mailing list