Log message for revision 39806: - always look for WriteLockInterface *and* IWriteLock (the z3 version of the same interface) - import and whitespace cleanup
Changed: U Zope/trunk/lib/python/webdav/Lockable.py UU Zope/trunk/lib/python/webdav/NullResource.py U Zope/trunk/lib/python/webdav/Resource.py UU Zope/trunk/lib/python/webdav/davcmds.py -=- Modified: Zope/trunk/lib/python/webdav/Lockable.py =================================================================== --- Zope/trunk/lib/python/webdav/Lockable.py 2005-11-01 11:49:21 UTC (rev 39805) +++ Zope/trunk/lib/python/webdav/Lockable.py 2005-11-01 12:55:46 UTC (rev 39806) @@ -7,7 +7,7 @@ # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE +# FOR A PARTICULAR PURPOSE. # ############################################################################## """WebDAV support - lockable item. @@ -15,17 +15,17 @@ $Id$ """ +import Acquisition from AccessControl import ClassSecurityInfo from Globals import InitializeClass from Globals import PersistentMapping -import Acquisition from zope.interface import implements from EtagSupport import EtagSupport +from interfaces import IWriteLock from WriteLockInterface import LockItemInterface from WriteLockInterface import WriteLockInterface -from interfaces import IWriteLock class ResourceLockedError(Exception): pass @@ -132,8 +132,10 @@ except: # The locks may be totally messed up, so we'll just delete # and replace. - if hasattr(self, '_dav_writelocks'): del self._dav_writelocks - if WriteLockInterface.isImplementedBy(self): + if hasattr(self, '_dav_writelocks'): + del self._dav_writelocks + if IWriteLock.providedBy(self) or \ + WriteLockInterface.isImplementedBy(self): self._dav_writelocks = PersistentMapping() # Call into a special hook used by LockNullResources to delete @@ -150,4 +152,5 @@ def wl_isLocked(ob): """ Returns true if the object is locked, returns 0 if the object is not locked or does not implement the WriteLockInterface """ - return WriteLockInterface.isImplementedBy(ob) and ob.wl_isLocked() + return (IWriteLock.providedBy(ob) or + WriteLockInterface.isImplementedBy(ob)) and ob.wl_isLocked() Modified: Zope/trunk/lib/python/webdav/NullResource.py =================================================================== --- Zope/trunk/lib/python/webdav/NullResource.py 2005-11-01 11:49:21 UTC (rev 39805) +++ Zope/trunk/lib/python/webdav/NullResource.py 2005-11-01 12:55:46 UTC (rev 39806) @@ -7,29 +7,36 @@ # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE +# FOR A PARTICULAR PURPOSE. # ############################################################################## +"""WebDAV support - null resource objects. -"""WebDAV support - null resource objects.""" +$Id$ +""" -__version__='$Revision: 1.43 $'[11:-2] +import sys -import sys, Globals, davcmds import Acquisition, OFS.content_types -from common import aq_base, tokenFinder, IfParser +import Globals +import OFS.SimpleItem from AccessControl import getSecurityManager -from Resource import Resource from Globals import Persistent, DTMLFile -from WriteLockInterface import WriteLockInterface -import OFS.SimpleItem +from OFS.CopySupport import CopyError +from zExceptions import MethodNotAllowed from zExceptions import Unauthorized, NotFound, Forbidden, BadRequest -from zExceptions import MethodNotAllowed + +import davcmds +from common import aq_base, tokenFinder, IfParser from common import isDavCollection from common import Locked, Conflict, PreconditionFailed, UnsupportedMediaType -from OFS.CopySupport import CopyError +from interfaces import IWriteLock +from Resource import Resource +from WriteLockInterface import WriteLockInterface + class NullResource(Persistent, Acquisition.Implicit, Resource): + """Null resources are used to handle HTTP method calls on objects which do not yet exist in the url namespace.""" @@ -94,7 +101,9 @@ parent = self.__parent__ ifhdr = REQUEST.get_header('If', '') - if WriteLockInterface.isImplementedBy(parent) and parent.wl_isLocked(): + if (IWriteLock.providedBy(parent) or + WriteLockInterface.isImplementedBy(parent)) and \ + parent.wl_isLocked(): if ifhdr: parent.dav__simpleifhandler(REQUEST, RESPONSE, col=1) else: @@ -172,7 +181,9 @@ raise Forbidden, 'Cannot create collection at this location.' ifhdr = REQUEST.get_header('If', '') - if WriteLockInterface.isImplementedBy(parent) and parent.wl_isLocked(): + if (IWriteLock.providedBy(parent) or + WriteLockInterface.isImplementedBy(parent)) and \ + parent.wl_isLocked(): if ifhdr: parent.dav__simpleifhandler(REQUEST, RESPONSE, col=1) else: @@ -202,7 +213,9 @@ name = self.__name__ parent = self.__parent__ - if WriteLockInterface.isImplementedBy(parent) and parent.wl_isLocked(): + if (IWriteLock.providedBy(parent) or + WriteLockInterface.isImplementedBy(parent)) and \ + parent.wl_isLocked(): if ifhdr: parent.dav__simpleifhandler(REQUEST, RESPONSE, col=1) else: @@ -234,7 +247,7 @@ else: # The command was succesful lock = locknull.wl_getLock(token) - RESPONSE.setStatus(200) + RESPONSE.setStatus(200) RESPONSE.setHeader('Content-Type', 'text/xml; charset="utf-8"') RESPONSE.setHeader('Lock-Token', 'opaquelocktoken:' + token) RESPONSE.setBody(lock.asXML()) @@ -369,7 +382,9 @@ # First we need to see if the parent of the locknull is locked, and # if the user owns that lock (checked by handling the information in # the If header). - if WriteLockInterface.isImplementedBy(parent) and parent.wl_isLocked(): + if (IWriteLock.providedBy(parent) or + WriteLockInterface.isImplementedBy(parent)) and \ + parent.wl_isLocked(): itrue = parent.dav__simpleifhandler(REQUEST, RESPONSE, 'PUT', col=1, url=parenturl, refresh=1) @@ -407,7 +422,8 @@ raise Forbidden, sys.exc_info()[1] # Put the locks on the new object - if not WriteLockInterface.isImplementedBy(ob): + if not (IWriteLock.providedBy(ob) or + WriteLockInterface.isImplementedBy(ob)): raise MethodNotAllowed, ( 'The target object type cannot be locked') for token, lock in locks: @@ -439,7 +455,9 @@ # If the parent object is locked, that information should be in the # if-header if the user owns a lock on the parent - if WriteLockInterface.isImplementedBy(parent) and parent.wl_isLocked(): + if (IWriteLock.providedBy(parent) or + WriteLockInterface.isImplementedBy(parent)) and \ + parent.wl_isLocked(): itrue = parent.dav__simpleifhandler(REQUEST, RESPONSE, 'MKCOL', col=1, url=parenturl, refresh=1) @@ -466,5 +484,4 @@ RESPONSE.setBody('') return RESPONSE - Globals.default__class_init__(LockNullResource) Property changes on: Zope/trunk/lib/python/webdav/NullResource.py ___________________________________________________________________ Name: cvs2svn:cvs-rev - 1.43 Name: svn:keywords + Id Modified: Zope/trunk/lib/python/webdav/Resource.py =================================================================== --- Zope/trunk/lib/python/webdav/Resource.py 2005-11-01 11:49:21 UTC (rev 39805) +++ Zope/trunk/lib/python/webdav/Resource.py 2005-11-01 12:55:46 UTC (rev 39806) @@ -15,8 +15,8 @@ $Id$ """ +import mimetypes import sys -import mimetypes from urllib import unquote import ExtensionClass @@ -35,6 +35,7 @@ from common import isDavCollection from common import Locked, Conflict, PreconditionFailed from interfaces import IDAVResource +from interfaces import IWriteLock from WriteLockInterface import WriteLockInterface @@ -233,8 +234,9 @@ # We're locked, and no if header was passed in, so # the client doesn't own a lock. raise Locked, 'Resource is locked.' - elif WriteLockInterface.isImplementedBy(parent) and \ - parent.wl_isLocked(): + elif (IWriteLock.providedBy(parent) or + WriteLockInterface.isImplementedBy(parent)) and \ + parent.wl_isLocked(): if ifhdr: parent.dav__simpleifhandler(REQUEST, RESPONSE, 'DELETE', col=1) else: @@ -361,8 +363,9 @@ if existing: # The destination itself exists, so we need to check its locks destob = aq_base(parent)._getOb(name) - if WriteLockInterface.isImplementedBy(destob) and \ - destob.wl_isLocked(): + if (IWriteLock.providedBy(destob) or + WriteLockInterface.isImplementedBy(destob)) and \ + destob.wl_isLocked(): if ifhdr: itrue = destob.dav__simpleifhandler( REQUEST, RESPONSE, 'COPY', refresh=1) @@ -370,8 +373,9 @@ raise PreconditonFailed else: raise Locked, 'Destination is locked.' - elif WriteLockInterface.isImplementedBy(parent) and \ - parent.wl_isLocked(): + elif (IWriteLock.providedBy(parent) or + WriteLockInterface.isImplementedBy(parent)) and \ + parent.wl_isLocked(): if ifhdr: parent.dav__simpleifhandler(REQUEST, RESPONSE, 'COPY', refresh=1) @@ -456,8 +460,9 @@ if existing: # The destination itself exists, so we need to check its locks destob = aq_base(parent)._getOb(name) - if WriteLockInterface.isImplementedBy(destob) and \ - destob.wl_isLocked(): + if (IWriteLock.providedBy(destob) or + WriteLockInterface.isImplementedBy(destob)) and \ + destob.wl_isLocked(): if ifhdr: itrue = destob.dav__simpleifhandler( REQUEST, RESPONSE, 'MOVE', url=dest, refresh=1) @@ -465,8 +470,9 @@ raise PreconditionFailed else: raise Locked, 'Destination is locked.' - elif WriteLockInterface.isImplementedBy(parent) and \ - parent.wl_isLocked(): + elif (IWriteLock.providedBy(parent) or + WriteLockInterface.isImplementedBy(parent)) and \ + parent.wl_isLocked(): # There's no existing object in the destination folder, so # we need to check the folders locks since we're changing its # member list Modified: Zope/trunk/lib/python/webdav/davcmds.py =================================================================== --- Zope/trunk/lib/python/webdav/davcmds.py 2005-11-01 11:49:21 UTC (rev 39805) +++ Zope/trunk/lib/python/webdav/davcmds.py 2005-11-01 12:55:46 UTC (rev 39806) @@ -7,51 +7,58 @@ # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE +# FOR A PARTICULAR PURPOSE. # ############################################################################## - """WebDAV xml request objects. $Id$ """ import sys -from common import absattr, aq_base, urlfix, urlbase -from OFS.PropertySheets import DAVProperties -from LockItem import LockItem -from WriteLockInterface import WriteLockInterface -from Acquisition import aq_parent -from xmltools import XmlParser from cStringIO import StringIO from urllib import quote + +import transaction from AccessControl import getSecurityManager +from Acquisition import aq_parent +from OFS.PropertySheets import DAVProperties +from ZConfig.url import urljoin from zExceptions import BadRequest, Forbidden + +from common import absattr, aq_base, urlfix, urlbase from common import isDavCollection from common import PreconditionFailed -from ZConfig.url import urljoin -import transaction +from interfaces import IWriteLock +from LockItem import LockItem +from WriteLockInterface import WriteLockInterface +from xmltools import XmlParser + def safe_quote(url, mark=r'%'): if url.find(mark) > -1: return url return quote(url) + class DAVProps(DAVProperties): """Emulate required DAV properties for objects which do not themselves support properties. This is mainly so that non-PropertyManagers can appear to support DAV PROPFIND requests.""" + def __init__(self, obj): self.__obj__=obj + def v_self(self): return self.__obj__ + p_self=v_self - class PropFind: """Model a PROPFIND request.""" + def __init__(self, request): self.request=request self.depth='infinity' @@ -175,9 +182,9 @@ return result.getvalue() - class PropPatch: """Model a PROPPATCH request.""" + def __init__(self, request): self.request=request self.values=[] @@ -295,11 +302,9 @@ return result - - - class Lock: """Model a LOCK request.""" + def __init__(self, request): self.request = request data = request.get('BODY', '') @@ -365,7 +370,8 @@ errmsg = "403 Forbidden" try: - if not WriteLockInterface.isImplementedBy(obj): + if not (IWriteLock.providedBy(obj) or + WriteLockInterface.isImplementedBy(obj)): if top: # This is the top level object in the apply, so we # do want an error @@ -429,7 +435,8 @@ url = url + '/' errmsg = None - islockable = WriteLockInterface.isImplementedBy(obj) + islockable = IWriteLock.providedBy(obj) or \ + WriteLockInterface.isImplementedBy(obj) if islockable and obj.wl_hasLock(token): method = getattr(obj, 'wl_delLock') @@ -465,7 +472,8 @@ if iscol: for ob in obj.objectValues(): if hasattr(ob, '__dav_resource__') and \ - WriteLockInterface.isImplementedBy(ob): + (IWriteLock.providedBy(ob) or + WriteLockInterface.isImplementedBy(ob)): uri = urljoin(url, absattr(ob.id)) self.apply(ob, token, uri, result, top=0) if not top: @@ -492,7 +500,8 @@ errmsg = None parent = aq_parent(obj) - islockable = WriteLockInterface.isImplementedBy(obj) + islockable = IWriteLock.providedBy(obj) or \ + WriteLockInterface.isImplementedBy(obj) if parent and (not user.has_permission('Delete objects', parent)): # User doesn't have permission to delete this object errmsg = "403 Forbidden" Property changes on: Zope/trunk/lib/python/webdav/davcmds.py ___________________________________________________________________ Name: cvs2svn:cvs-rev - 1.23 _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins