Commit bcaeb4ae authored by Hanno Schlichting's avatar Hanno Schlichting

Use ResourceLockedError from zExceptions.

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