Commit bcaeb4ae authored by Hanno Schlichting's avatar Hanno Schlichting

Use ResourceLockedError from zExceptions.

parent 7ffb81cb
...@@ -22,6 +22,7 @@ Features Added ...@@ -22,6 +22,7 @@ Features Added
- AccessControl = 4.0a3 - AccessControl = 4.0a3
- AuthEncoding = 4.0.0 - AuthEncoding = 4.0.0
- zExceptions = 3.3
Restructuring Restructuring
+++++++++++++ +++++++++++++
......
...@@ -38,7 +38,7 @@ six==1.10.0 ...@@ -38,7 +38,7 @@ six==1.10.0
tempstorage==3.0 tempstorage==3.0
transaction==1.6.1 transaction==1.6.1
waitress==0.9.0 waitress==0.9.0
zExceptions==3.2 zExceptions==3.3
zLOG==3.0 zLOG==3.0
zc.lockfile==1.2.1 zc.lockfile==1.2.1
zdaemon==4.1.0 zdaemon==4.1.0
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
"""Application support """Application support
""" """
import os, sys import os
import sys
from logging import getLogger from logging import getLogger
import Products import Products
......
...@@ -39,8 +39,7 @@ from App.Dialogs import MessageDialog ...@@ -39,8 +39,7 @@ from App.Dialogs import MessageDialog
from App.special_dtml import HTML from App.special_dtml import HTML
from App.special_dtml import DTMLFile from App.special_dtml import DTMLFile
from ExtensionClass import Base from ExtensionClass import Base
from webdav.Lockable import ResourceLockedError from zExceptions import Unauthorized, BadRequest, ResourceLockedError
from zExceptions import Unauthorized, BadRequest
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from zope.interface import implements from zope.interface import implements
from zope.event import notify from zope.event import notify
...@@ -62,7 +61,7 @@ class CopyError(Exception): ...@@ -62,7 +61,7 @@ class CopyError(Exception):
copy_re = re.compile('^copy([0-9]*)_of_(.*)') copy_re = re.compile('^copy([0-9]*)_of_(.*)')
_marker=[] _marker = []
class CopyContainer(Base): class CopyContainer(Base):
...@@ -109,8 +108,7 @@ class CopyContainer(Base): ...@@ -109,8 +108,7 @@ class CopyContainer(Base):
ob=self._getOb(id) ob=self._getOb(id)
if ob.wl_isLocked(): if ob.wl_isLocked():
raise ResourceLockedError('Object "%s" is locked via WebDAV' raise ResourceLockedError('Object "%s" is locked' % ob.getId())
% ob.getId())
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError(eNotSupported % escape(id)) raise CopyError(eNotSupported % escape(id))
...@@ -350,8 +348,7 @@ class CopyContainer(Base): ...@@ -350,8 +348,7 @@ class CopyContainer(Base):
ob = self._getOb(id) ob = self._getOb(id)
if ob.wl_isLocked(): if ob.wl_isLocked():
raise ResourceLockedError('Object "%s" is locked via WebDAV' raise ResourceLockedError('Object "%s" is locked' % ob.getId())
% ob.getId())
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError(eNotSupported % escape(id)) raise CopyError(eNotSupported % escape(id))
self._verifyObjectPaste(ob) self._verifyObjectPaste(ob)
......
...@@ -23,7 +23,7 @@ from DocumentTemplate.permissions import change_dtml_documents ...@@ -23,7 +23,7 @@ from DocumentTemplate.permissions import change_dtml_documents
from OFS.DTMLMethod import decapitate from OFS.DTMLMethod import decapitate
from OFS.DTMLMethod import DTMLMethod from OFS.DTMLMethod import DTMLMethod
from OFS.PropertyManager import PropertyManager from OFS.PropertyManager import PropertyManager
from webdav.Lockable import ResourceLockedError from zExceptions import ResourceLockedError
from zExceptions.TracebackSupplement import PathTracebackSupplement from zExceptions.TracebackSupplement import PathTracebackSupplement
from zope.contenttype import guess_content_type from zope.contenttype import guess_content_type
...@@ -55,12 +55,11 @@ class DTMLDocument(PropertyManager, DTMLMethod): ...@@ -55,12 +55,11 @@ class DTMLDocument(PropertyManager, DTMLMethod):
""" """
self._validateProxy(REQUEST) self._validateProxy(REQUEST)
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError( raise ResourceLockedError('This document has been locked.')
'This document has been locked via WebDAV.')
if type(file) is not type(''): if type(file) is not type(''):
if REQUEST and not file: if REQUEST and not file:
raise ValueError, 'No file specified' raise ValueError('No file specified')
file = file.read() file = file.read()
self.munge(file) self.munge(file)
......
...@@ -34,8 +34,7 @@ from OFS.History import Historical ...@@ -34,8 +34,7 @@ from OFS.History import Historical
from OFS.History import html_diff from OFS.History import html_diff
from OFS.role import RoleManager from OFS.role import RoleManager
from OFS.SimpleItem import Item_w__name__ from OFS.SimpleItem import Item_w__name__
from webdav.Lockable import ResourceLockedError from zExceptions import Forbidden, ResourceLockedError
from zExceptions import Forbidden
from zExceptions.TracebackSupplement import PathTracebackSupplement from zExceptions.TracebackSupplement import PathTracebackSupplement
from ZPublisher.Iterators import IStreamIterator from ZPublisher.Iterators import IStreamIterator
from zope.contenttype import guess_content_type from zope.contenttype import guess_content_type
...@@ -280,7 +279,7 @@ class DTMLMethod(RestrictedDTML, ...@@ -280,7 +279,7 @@ class DTMLMethod(RestrictedDTML,
return self._er(data, title, return self._er(data, title,
SUBMIT, dtpref_cols, dtpref_rows, REQUEST) SUBMIT, dtpref_cols, dtpref_rows, REQUEST)
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError('This item is locked via WebDAV') raise ResourceLockedError('This item is locked.')
self.title = str(title) self.title = str(title)
if isinstance(data, TaintedString): if isinstance(data, TaintedString):
...@@ -299,7 +298,7 @@ class DTMLMethod(RestrictedDTML, ...@@ -299,7 +298,7 @@ class DTMLMethod(RestrictedDTML,
""" """
self._validateProxy(REQUEST) self._validateProxy(REQUEST)
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError('This DTML Method is locked via WebDAV') raise ResourceLockedError('This DTML Method is locked.')
if type(file) is not type(''): if type(file) is not type(''):
if REQUEST and not file: if REQUEST and not file:
......
...@@ -31,10 +31,9 @@ from DateTime.DateTime import DateTime ...@@ -31,10 +31,9 @@ from DateTime.DateTime import DateTime
from Persistence import Persistent from Persistence import Persistent
from webdav.common import rfc1123_date from webdav.common import rfc1123_date
from webdav.interfaces import IWriteLock from webdav.interfaces import IWriteLock
from webdav.Lockable import ResourceLockedError
from ZPublisher import HTTPRangeSupport from ZPublisher import HTTPRangeSupport
from ZPublisher.HTTPRequest import FileUpload from ZPublisher.HTTPRequest import FileUpload
from zExceptions import Redirect from zExceptions import Redirect, ResourceLockedError
from zope.contenttype import guess_content_type from zope.contenttype import guess_content_type
from zope.interface import implementedBy from zope.interface import implementedBy
from zope.interface import implements from zope.interface import implements
...@@ -459,7 +458,7 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -459,7 +458,7 @@ class File(Persistent, Implicit, PropertyManager,
Changes the title and content type attributes of the File or Image. Changes the title and content type attributes of the File or Image.
""" """
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError, "File is locked via WebDAV" raise ResourceLockedError("File is locked.")
self.title=str(title) self.title=str(title)
self.content_type=str(content_type) self.content_type=str(content_type)
...@@ -484,7 +483,7 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -484,7 +483,7 @@ class File(Persistent, Implicit, PropertyManager,
The file or images contents are replaced with the contents of 'file'. The file or images contents are replaced with the contents of 'file'.
""" """
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError, "File is locked via WebDAV" raise ResourceLockedError("File is locked.")
data, size = self._read_data(file) data, size = self._read_data(file)
content_type=self._get_content_type(file, data, self.__name__, content_type=self._get_content_type(file, data, self.__name__,
......
...@@ -47,9 +47,8 @@ from App.special_dtml import DTMLFile ...@@ -47,9 +47,8 @@ from App.special_dtml import DTMLFile
from DateTime import DateTime from DateTime import DateTime
from Persistence import Persistent from Persistence import Persistent
from webdav.Collection import Collection from webdav.Collection import Collection
from webdav.Lockable import ResourceLockedError
from webdav.NullResource import NullResource from webdav.NullResource import NullResource
from zExceptions import BadRequest from zExceptions import BadRequest, ResourceLockedError
from zope.container.contained import notifyContainerModified from zope.container.contained import notifyContainerModified
from zope.event import notify from zope.event import notify
from zope.interface import implements from zope.interface import implements
...@@ -527,7 +526,7 @@ class ObjectManager(CopyContainer, ...@@ -527,7 +526,7 @@ class ObjectManager(CopyContainer,
if v.wl_isLocked(): if v.wl_isLocked():
raise ResourceLockedError( raise ResourceLockedError(
'Object "%s" is locked via WebDAV' % v.getId()) 'Object "%s" is locked.' % v.getId())
if v is self: if v is self:
raise BadRequest('%s does not exist' % escape(ids[-1])) raise BadRequest('%s does not exist' % escape(ids[-1]))
......
...@@ -289,7 +289,7 @@ class Traversable: ...@@ -289,7 +289,7 @@ class Traversable:
# or TypeError: not subscriptable # or TypeError: not subscriptable
raise NotFound(name) raise NotFound(name)
if restricted and not validate( if restricted and not validate(
obj, obj, None, next): obj, obj, None, next):
raise Unauthorized(name) raise Unauthorized(name)
except (AttributeError, NotFound, KeyError), e: except (AttributeError, NotFound, KeyError), e:
......
...@@ -668,29 +668,16 @@ def test_view_doesnt_shadow_attribute(): ...@@ -668,29 +668,16 @@ def test_view_doesnt_shadow_attribute():
>>> self.folder.ftf.unrestrictedTraverse('mouse')() >>> self.folder.ftf.unrestrictedTraverse('mouse')()
u'The mouse has been eaten by the eagle' u'The mouse has been eaten by the eagle'
Head requests have some unusual behavior in Zope 2, in particular, a
failed item lookup on an ObjectManager returns a NullResource, rather
than raising a KeyError. We need to make sure that this doesn't
result in acquired attributes being shadowed by the NullResource,
but that unknown names still give NullResources:
>>> self.app.REQUEST.maybe_webdav_client = True
>>> self.app.REQUEST['REQUEST_METHOD'] = 'HEAD'
>>> self.folder.ftf.unrestrictedTraverse('mouse')()
u'The mouse has been eaten by the eagle'
>>> self.folder.ftf.unrestrictedTraverse('nonsense')
<webdav.NullResource.NullResource object at ...>
Clean up: Clean up:
>>> from zope.component.testing import tearDown >>> from zope.component.testing import tearDown
>>> tearDown() >>> tearDown()
""" """
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestTraverse ) ) suite.addTest(unittest.makeSuite(TestTraverse))
from Testing.ZopeTestCase import FunctionalDocTestSuite from Testing.ZopeTestCase import FunctionalDocTestSuite
suite.addTest( FunctionalDocTestSuite() ) suite.addTest(FunctionalDocTestSuite())
return suite return suite
...@@ -27,14 +27,14 @@ from Acquisition import Explicit ...@@ -27,14 +27,14 @@ from Acquisition import Explicit
from Acquisition import aq_get from Acquisition import aq_get
from App.Common import package_home from App.Common import package_home
from DateTime.DateTime import DateTime from DateTime.DateTime import DateTime
from OFS.Cache import Cacheable
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from OFS.History import Historical, html_diff from OFS.History import Historical, html_diff
from OFS.Cache import Cacheable
from OFS.Traversable import Traversable
from OFS.PropertyManager import PropertyManager from OFS.PropertyManager import PropertyManager
from OFS.Traversable import Traversable
from Shared.DC.Scripts.Script import Script from Shared.DC.Scripts.Script import Script
from Shared.DC.Scripts.Signature import FuncCode from Shared.DC.Scripts.Signature import FuncCode
from webdav.Lockable import ResourceLockedError from zExceptions import ResourceLockedError
from Products.PageTemplates.PageTemplate import PageTemplate from Products.PageTemplates.PageTemplate import PageTemplate
from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplateFile import PageTemplateFile
...@@ -183,7 +183,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -183,7 +183,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
"""Change the title and document.""" """Change the title and document."""
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError("File is locked via WebDAV") raise ResourceLockedError("File is locked.")
self.expand = expand self.expand = expand
...@@ -219,7 +219,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -219,7 +219,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
"""Replace the document with the text in file.""" """Replace the document with the text in file."""
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError("File is locked via WebDAV") raise ResourceLockedError("File is locked.")
if isinstance(file, str): if isinstance(file, str):
filename = None filename = None
......
...@@ -171,7 +171,7 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -171,7 +171,7 @@ class HTTPResponseTests(unittest.TestCase):
def test_setStatus_ResourceLockedError_exception(self): def test_setStatus_ResourceLockedError_exception(self):
response = self._makeOne() response = self._makeOne()
from webdav.Lockable import ResourceLockedError from zExceptions import ResourceLockedError
response.setStatus(ResourceLockedError) response.setStatus(ResourceLockedError)
self.assertEqual(response.status, 423) self.assertEqual(response.status, 423)
self.assertEqual(response.errmsg, 'Locked') self.assertEqual(response.errmsg, 'Locked')
......
...@@ -122,7 +122,7 @@ class EtagSupport: ...@@ -122,7 +122,7 @@ class EtagSupport:
# The resource etag is not in the list of etags required # The resource etag is not in the list of etags required
# to match, as specified in the 'if-match' header. The # to match, as specified in the 'if-match' header. The
# condition fails and the HTTP Method may *not* execute. # condition fails and the HTTP Method may *not* execute.
raise PreconditionFailed raise PreconditionFailed()
elif self.http__etag() in matchlist: elif self.http__etag() in matchlist:
return 1 return 1
...@@ -133,12 +133,10 @@ class EtagSupport: ...@@ -133,12 +133,10 @@ class EtagSupport:
elif ('*' in nonematch): elif ('*' in nonematch):
# if-none-match: * means that the operation should not # if-none-match: * means that the operation should not
# be performed if the specified resource exists # be performed if the specified resource exists
# (webdav.NullResource will want to do special behavior raise PreconditionFailed()
# here)
raise PreconditionFailed
elif self.http__etag() in nonematch: elif self.http__etag() in nonematch:
# The opposite of if-match, the condition fails # The opposite of if-match, the condition fails
# IF the resources Etag is in the if-none-match list # IF the resources Etag is in the if-none-match list
raise PreconditionFailed raise PreconditionFailed()
elif self.http__etag() not in nonematch: elif self.http__etag() not in nonematch:
return 1 return 1
...@@ -23,9 +23,8 @@ from webdav.EtagSupport import EtagSupport ...@@ -23,9 +23,8 @@ from webdav.EtagSupport import EtagSupport
from webdav.interfaces import ILockItem from webdav.interfaces import ILockItem
from webdav.interfaces import IWriteLock from webdav.interfaces import IWriteLock
# BBB
class ResourceLockedError(Exception): from zExceptions import ResourceLockedError # NOQA
pass
class LockableItem(EtagSupport): class LockableItem(EtagSupport):
......
...@@ -41,7 +41,7 @@ zc.lockfile = 1.2.1 ...@@ -41,7 +41,7 @@ zc.lockfile = 1.2.1
ZConfig = 3.1.0 ZConfig = 3.1.0
zdaemon = 4.1.0 zdaemon = 4.1.0
ZEO = 4.2.1 ZEO = 4.2.1
zExceptions = 3.2 zExceptions = 3.3
zLOG = 3.0 zLOG = 3.0
ZODB = 4.4.2 ZODB = 4.4.2
zodbpickle = 0.6.0 zodbpickle = 0.6.0
......
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