[Zope-Checkins] CVS: Zope/lib/python/webdav - Collection.py:1.26 EtagSupport.py:1.10 NullResource.py:1.40 Resource.py:1.58 client.py:1.21 common.py:1.18 davcmds.py:1.22

Tres Seaver cvs-admin at zope.org
Tue Nov 18 08:17:51 EST 2003


Update of /cvs-repository/Zope/lib/python/webdav
In directory cvs.zope.org:/tmp/cvs-serv30559/lib/python/webdav

Modified Files:
	Collection.py EtagSupport.py NullResource.py Resource.py 
	client.py common.py davcmds.py 
Log Message:
 - Merge tseaver-strexp_delenda-branch to the head.


=== Zope/lib/python/webdav/Collection.py 1.25 => 1.26 ===
--- Zope/lib/python/webdav/Collection.py:1.25	Tue Oct 21 10:49:48 2003
+++ Zope/lib/python/webdav/Collection.py	Tue Nov 18 08:17:20 2003
@@ -21,7 +21,8 @@
 from AccessControl import getSecurityManager
 from urllib import unquote
 from WriteLockInterface import WriteLockInterface
-
+from zExceptions import MethodNotAllowed, NotFound
+from webdav.common import Locked, PreconditionFailed
 
 class Collection(Resource):
     """The Collection class provides basic WebDAV support for
@@ -54,10 +55,10 @@
         if hasattr(self, 'index_html'):
             if hasattr(self.index_html, 'HEAD'):
                 return self.index_html.HEAD(REQUEST, RESPONSE)
-            raise 'Method Not Allowed', (
+            raise MethodNotAllowed, (
                   'Method not supported for this resource.'
                   )
-        raise 'Not Found', 'The requested resource does not exist.'
+        raise NotFound, 'The requested resource does not exist.'
 
     def PUT(self, REQUEST, RESPONSE):
         """The PUT method has no inherent meaning for collection
@@ -65,7 +66,7 @@
         to handle PUT requests. The default response to a PUT request
         for collections is 405 (Method Not Allowed)."""
         self.dav__init(REQUEST, RESPONSE)
-        raise 'Method Not Allowed', 'Method not supported for collections.'
+        raise MethodNotAllowed, 'Method not supported for collections.'
 
     def DELETE(self, REQUEST, RESPONSE):
         """Delete a collection resource. For collection resources, DELETE
@@ -92,12 +93,12 @@
             if ifhdr:
                 self.dav__simpleifhandler(REQUEST, RESPONSE, 'DELETE', col=1)
             else:
-                raise 'Locked'
+                raise Locked
         elif Lockable.wl_isLocked(parent):
             if ifhdr:
                 parent.dav__simpleifhandler(REQUEST, RESPONSE, 'DELETE', col=1)
             else:
-                raise 'Precondition Failed'
+                raise PreconditionFailed
         # Second level of lock\conflict checking (are any descendants locked,
         # or is the user not permitted to delete?).  This results in a
         # multistatus response


=== Zope/lib/python/webdav/EtagSupport.py 1.9 => 1.10 ===
--- Zope/lib/python/webdav/EtagSupport.py:1.9	Thu Sep 19 11:30:19 2002
+++ Zope/lib/python/webdav/EtagSupport.py	Tue Nov 18 08:17:20 2003
@@ -15,6 +15,7 @@
 
 
 import time, Interface, re
+from webdav.common import PreconditionFailed
 
 class EtagBaseInterface(Interface.Base):
     """\
@@ -116,7 +117,7 @@
             # 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 "Precondition Failed"
+            raise PreconditionFailed
         elif self.http__etag() in matchlist:
             return 1
 
@@ -129,10 +130,10 @@
             # be performed if the specified resource exists
             # (webdav.NullResource will want to do special behavior
             # here)
-            raise "Precondition Failed"
+            raise PreconditionFailed
         elif self.http__etag() in nonelist:
             # The opposite of if-match, the condition fails
             # IF the resources Etag is in the if-none-match list
-            raise "Precondition Failed"
+            raise PreconditionFailed
         elif self.http__etag() not in nonelist:
             return 1


=== Zope/lib/python/webdav/NullResource.py 1.39 => 1.40 ===
--- Zope/lib/python/webdav/NullResource.py:1.39	Thu Aug 29 10:33:29 2002
+++ Zope/lib/python/webdav/NullResource.py	Tue Nov 18 08:17:20 2003
@@ -24,8 +24,10 @@
 from Globals import Persistent, DTMLFile
 from WriteLockInterface import WriteLockInterface
 import OFS.SimpleItem
-from zExceptions import Unauthorized
+from zExceptions import Unauthorized, NotFound, Forbidden, BadRequest
+from zExceptions import MethodNotAllowed
 from common import isDavCollection
+from common import Locked, Conflict, PreconditionFailed, UnsupportedMediaType
 
 class NullResource(Persistent, Acquisition.Implicit, Resource):
     """Null resources are used to handle HTTP method calls on
@@ -52,13 +54,13 @@
         except: pass
         method=REQUEST.get('REQUEST_METHOD', 'GET')
         if method in ('PUT', 'MKCOL', 'LOCK'):
-            raise 'Conflict', 'Collection ancestors must already exist.'
-        raise 'Not Found', 'The requested resource was not found.'
+            raise Conflict, 'Collection ancestors must already exist.'
+        raise NotFound, 'The requested resource was not found.'
 
     def HEAD(self, REQUEST, RESPONSE):
         """Retrieve resource information without a response message body."""
         self.dav__init(REQUEST, RESPONSE)
-        raise 'Not Found', 'The requested resource does not exist.'
+        raise NotFound, 'The requested resource does not exist.'
 
     # Most methods return 404 (Not Found) for null resources.
     DELETE=TRACE=PROPFIND=PROPPATCH=COPY=MOVE=HEAD
@@ -94,10 +96,10 @@
             else:
                 # There was no If header at all, and our parent is locked,
                 # so we fail here
-                raise 'Locked'
+                raise Locked
         elif ifhdr:
             # There was an If header, but the parent is not locked
-            raise 'Precondition Failed'
+            raise PreconditionFailed
 
         body=REQUEST.get('BODY', '')
         typ=REQUEST.get_header('content-type', None)
@@ -116,7 +118,7 @@
         except Unauthorized:
             raise
         except:
-            raise 'Forbidden', sys.exc_info()[1]
+            raise Forbidden, sys.exc_info()[1]
 
         # Delegate actual PUT handling to the new object.
         ob.PUT(REQUEST, RESPONSE)
@@ -130,25 +132,25 @@
         """Create a new collection resource."""
         self.dav__init(REQUEST, RESPONSE)
         if REQUEST.get('BODY', ''):
-            raise 'Unsupported Media Type', 'Unknown request body.'
+            raise UnsupportedMediaType, 'Unknown request body.'
 
         name=self.__name__
         parent = self.__parent__
 
         if hasattr(aq_base(parent), name):
-            raise 'Method Not Allowed', 'The name %s is in use.' % name
+            raise MethodNotAllowed, 'The name %s is in use.' % name
         if not isDavCollection(parent):
-            raise 'Forbidden', 'Cannot create collection at this location.'
+            raise Forbidden, 'Cannot create collection at this location.'
 
         ifhdr = REQUEST.get_header('If', '')
         if WriteLockInterface.isImplementedBy(parent) and parent.wl_isLocked():
             if ifhdr:
                 parent.dav__simpleifhandler(REQUEST, RESPONSE, col=1)
             else:
-                raise 'Locked'
+                raise Locked
         elif ifhdr:
             # There was an If header, but the parent is not locked
-            raise 'Precondition Failed'
+            raise PreconditionFailed
 
         # Add hook for webdav/FTP MKCOL (Collector #2254) (needed for CMF)
 #       parent.manage_addFolder(name)
@@ -175,16 +177,16 @@
             if ifhdr:
                 parent.dav__simpleifhandler(REQUEST, RESPONSE, col=1)
             else:
-                raise 'Locked'
+                raise Locked
         elif ifhdr:
             # There was an If header, but the parent is not locked.
-            raise 'Precondition Failed'
+            raise PreconditionFailed
 
         # The logic involved in locking a null resource is simpler than
         # a regular resource, since we know we're not already locked,
         # and the lock isn't being refreshed.
         if not body:
-            raise 'Bad Request', 'No body was in the request'
+            raise BadRequest, 'No body was in the request'
 
         locknull = LockNullResource(name)
         parent._setObject(name, locknull)
@@ -268,7 +270,8 @@
             RESPONSE.setStatus(423)
         else:
             # There's no body, so this is likely to be a refresh request
-            if not ifhdr: raise 'Precondition Failed'
+            if not ifhdr:
+                raise PreconditionFailed
             taglist = IfParser(ifhdr)
             found = 0
             for tag in taglist:
@@ -298,8 +301,10 @@
         user = security.getUser()
         token = REQUEST.get_header('Lock-Token', '')
         url = REQUEST['URL']
-        if token: token = tokenFinder(token)
-        else: raise 'Bad Request', 'No lock token was submitted in the request'
+        if token:
+            token = tokenFinder(token)
+        else:
+            raise BadRequest, 'No lock token was submitted in the request'
 
         cmd = davcmds.Unlock()
         result = cmd.apply(self, token, url)
@@ -329,7 +334,8 @@
         # Since a Lock null resource is always locked by definition, all
         # operations done by an owner of the lock that affect the resource
         # MUST have the If header in the request
-        if not ifhdr: raise 'Precondition Failed', 'No If-header'
+        if not ifhdr:
+            raise PreconditionFailed, 'No If-header'
 
         # 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
@@ -338,12 +344,14 @@
             itrue = parent.dav__simpleifhandler(REQUEST, RESPONSE, 'PUT',
                                                 col=1, url=parenturl,
                                                 refresh=1)
-            if not itrue: raise 'Precondition Failed', (
+            if not itrue:
+                raise PreconditionFailed, (
                 'Condition failed against resources parent')
 
         # Now we need to check the If header against our own lock state
         itrue = self.dav__simpleifhandler(REQUEST, RESPONSE, 'PUT', refresh=1)
-        if not itrue: raise 'Precondition Failed', (
+        if not itrue:
+            raise PreconditionFailed, (
             'Condition failed against locknull resource')
 
         # All of the If header tests succeeded, now we need to remove ourselves
@@ -367,11 +375,11 @@
         except Unauthorized:
             raise
         except:
-            raise 'Forbidden', sys.exc_info()[1]
+            raise Forbidden, sys.exc_info()[1]
 
         # Put the locks on the new object
         if not WriteLockInterface.isImplementedBy(ob):
-            raise 'Method Not Allowed', (
+            raise MethodNotAllowed, (
                 'The target object type cannot be locked')
         for token, lock in locks:
             ob.wl_setLock(token, lock)
@@ -390,14 +398,15 @@
         object and transferring its locks to the newly created Folder """
         self.dav__init(REQUEST, RESPONSE)
         if REQUEST.get('BODY', ''):
-            raise 'Unsupported Media Type', 'Unknown request body.'
+            raise UnsupportedMediaType, 'Unknown request body.'
 
         name = self.__name__
         parent = self.aq_parent
         parenturl = parent.absolute_url()
         ifhdr = REQUEST.get_header('If', '')
 
-        if not ifhdr: raise 'Precondition Failed', 'No If-header'
+        if not ifhdr:
+            raise PreconditionFailed, 'No If-header'
 
         # If the parent object is locked, that information should be in the
         # if-header if the user owns a lock on the parent
@@ -405,11 +414,13 @@
             itrue = parent.dav__simpleifhandler(REQUEST, RESPONSE, 'MKCOL',
                                                 col=1, url=parenturl,
                                                 refresh=1)
-            if not itrue: raise 'Precondition Failed', (
+            if not itrue:
+                raise PreconditionFailed, (
                 'Condition failed against resources parent')
         # Now we need to check the If header against our own lock state
         itrue = self.dav__simpleifhandler(REQUEST,RESPONSE,'MKCOL',refresh=1)
-        if not itrue: raise 'Precondition Failed', (
+        if not itrue:
+            raise PreconditionFailed, (
             'Condition failed against locknull resource')
 
         # All of the If header tests succeeded, now we need to remove ourselves


=== Zope/lib/python/webdav/Resource.py 1.57 => 1.58 ===
--- Zope/lib/python/webdav/Resource.py:1.57	Thu Oct 23 10:16:13 2003
+++ Zope/lib/python/webdav/Resource.py	Tue Nov 18 08:17:20 2003
@@ -11,20 +11,32 @@
 #
 ##############################################################################
 
-"""WebDAV support - resource objects."""
+"""WebDAV support - resource objects.
 
-__version__='$Revision$'[11:-2]
+$Id$
+"""
 
-import sys, os,  mimetypes, davcmds, ExtensionClass, Lockable
-from common import absattr, aq_base, urlfix, rfc1123_date, tokenFinder, urlbase
-from common import IfParser
+import os
+import sys
+import mimetypes
+import time
 from urllib import quote, unquote
+
+import Globals
+import ExtensionClass
+from Acquisition import aq_base
 from AccessControl import getSecurityManager
-from WriteLockInterface import WriteLockInterface
-import Globals, time
 from ZPublisher.HTTPRangeSupport import HTTPRangeInterface
-from zExceptions import Unauthorized
+from zExceptions import Unauthorized, Forbidden
+from zExceptions import BadRequest, MethodNotAllowed 
+
+from WriteLockInterface import WriteLockInterface
+import Lockable
+from common import absattr, urlfix, rfc1123_date, tokenFinder, urlbase
+from common import IfParser
 from common import isDavCollection
+from common import Locked, Conflict, PreconditionFailed
+import davcmds
 
 class Resource(ExtensionClass.Base, Lockable.LockableItem):
     """The Resource mixin class provides basic WebDAV support for
@@ -92,7 +104,7 @@
                              col=0, url=None, refresh=0):
         ifhdr = request.get_header('If', None)
         if Lockable.wl_isLocked(self) and (not ifhdr):
-            raise "Locked", "Resource is locked."
+            raise Locked, "Resource is locked."
 
         if not ifhdr: return None
         if not Lockable.wl_isLocked(self): return None
@@ -136,7 +148,7 @@
                 found = 1; break
 
         if resourcetagged and (not found):
-            raise 'Precondition Failed', 'Condition failed.'
+            raise PreconditionFailed, 'Condition failed.'
         elif resourcetagged and found:
             return 1
         else:
@@ -181,7 +193,7 @@
         object-specific implementation. By default, PUT requests
         fail with a 405 (Method Not Allowed)."""
         self.dav__init(REQUEST, RESPONSE)
-        raise 'Method Not Allowed', 'Method not supported for this resource.'
+        raise MethodNotAllowed, 'Method not supported for this resource.'
 
     OPTIONS__roles__=None
     def OPTIONS(self, REQUEST, RESPONSE):
@@ -202,7 +214,7 @@
         is not often possible to reproduce the HTTP request verbatim
         from within the Zope environment."""
         self.dav__init(REQUEST, RESPONSE)
-        raise 'Method Not Allowed', 'Method not supported for this resource.'
+        raise MethodNotAllowed, 'Method not supported for this resource.'
 
     def DELETE(self, REQUEST, RESPONSE):
         """Delete a resource. For non-collection resources, DELETE may
@@ -219,7 +231,7 @@
             else:
                 # We're locked, and no if header was passed in, so
                 # the client doesn't own a lock.
-                raise 'Locked', 'Resource is locked.'
+                raise Locked, 'Resource is locked.'
         elif WriteLockInterface.isImplementedBy(parent) and \
              parent.wl_isLocked():
             if ifhdr:
@@ -227,7 +239,7 @@
             else:
                 # Our parent is locked, and no If header was passed in.
                 # When a parent is locked, members cannot be removed
-                raise 'Precondition Failed', 'Resource is locked, and no '\
+                raise PreconditionFailed, 'Resource is locked, and no '\
                       'condition was passed in.'
         # Either we're not locked, or a succesful lock token was submitted
         # so we can delete the lock now.
@@ -255,7 +267,7 @@
         """Set and/or remove properties defined on the resource."""
         self.dav__init(REQUEST, RESPONSE)
         if not hasattr(aq_base(self), 'propertysheets'):
-            raise 'Method Not Allowed', (
+            raise MethodNotAllowed, (
                   'Method not supported for this resource.')
         # Lock checking
         ifhdr = REQUEST.get_header('If', '')
@@ -263,7 +275,7 @@
             if ifhdr:
                 self.dav__simpleifhandler(REQUEST, RESPONSE, 'PROPPATCH')
             else:
-                raise 'Locked', 'Resource is locked.'
+                raise Locked, 'Resource is locked.'
 
         cmd=davcmds.PropPatch(REQUEST)
         result=cmd.apply(self)
@@ -276,7 +288,7 @@
         """Create a new collection resource. If called on an existing
         resource, MKCOL must fail with 405 (Method Not Allowed)."""
         self.dav__init(REQUEST, RESPONSE)
-        raise 'Method Not Allowed', 'The resource already exists.'
+        raise MethodNotAllowed, 'The resource already exists.'
 
     COPY__roles__=('Anonymous',)
     def COPY(self, REQUEST, RESPONSE):
@@ -288,48 +300,52 @@
         self.dav__init(REQUEST, RESPONSE)
         if not hasattr(aq_base(self), 'cb_isCopyable') or \
            not self.cb_isCopyable():
-            raise 'Method Not Allowed', 'This object may not be copied.'
+            raise MethodNotAllowed, 'This object may not be copied.'
 
         depth=REQUEST.get_header('Depth', 'infinity')
         if not depth in ('0', 'infinity'):
-            raise 'Bad Request', 'Invalid Depth header.'
+            raise BadRequest, 'Invalid Depth header.'
 
         dest=REQUEST.get_header('Destination', '')
         while dest and dest[-1]=='/':
             dest=dest[:-1]
         if not dest:
-            raise 'Bad Request', 'Invalid Destination header.'
+            raise BadRequest, 'Invalid Destination header.'
 
         try: path = REQUEST.physicalPathFromURL(dest)
         except ValueError:
-            raise 'Bad Request', 'Invalid Destination header'
+            raise BadRequest, 'Invalid Destination header'
 
         name = path.pop()
         parent_path = '/'.join(path)
 
         oflag=REQUEST.get_header('Overwrite', 'F').upper()
         if not oflag in ('T', 'F'):
-            raise 'Bad Request', 'Invalid Overwrite header.'
+            raise BadRequest, 'Invalid Overwrite header.'
 
         try: parent=self.restrictedTraverse(path)
         except ValueError:
-            raise 'Conflict', 'Attempt to copy to an unknown namespace.'
-        except 'Not Found':
-            raise 'Conflict', 'Object ancestors must already exist.'
+            raise Conflict, 'Attempt to copy to an unknown namespace.'
+        except NotFound:
+            raise Conflict, 'Object ancestors must already exist.'
         except:
             t, v, tb=sys.exc_info()
             raise t, v
         if hasattr(parent, '__null_resource__'):
-            raise 'Conflict', 'Object ancestors must already exist.'
+            raise Conflict, 'Object ancestors must already exist.'
         existing=hasattr(aq_base(parent), name)
         if existing and oflag=='F':
-            raise 'Precondition Failed', 'Destination resource exists.'
-        try: parent._checkId(name, allow_dup=1)
-        except: raise 'Forbidden', sys.exc_info()[1]
-        try: parent._verifyObjectPaste(self)
+            raise PreconditionFailed, 'Destination resource exists.'
+        try:
+            parent._checkId(name, allow_dup=1)
+        except:
+            raise Forbidden, sys.exc_info()[1]
+        try:
+            parent._verifyObjectPaste(self)
         except Unauthorized:
             raise
-        except: raise 'Forbidden', sys.exc_info()[1]
+        except:
+            raise Forbidden, sys.exc_info()[1]
 
         # Now check locks.  The If header on a copy only cares about the
         # lock on the destination, so we need to check out the destinations
@@ -343,16 +359,17 @@
                 if ifhdr:
                     itrue = destob.dav__simpleifhandler(
                         REQUEST, RESPONSE, 'COPY', refresh=1)
-                    if not itrue: raise 'Preconditon Failed'
+                    if not itrue:
+                        raise PreconditonFailed
                 else:
-                    raise 'Locked', 'Destination is locked.'
+                    raise Locked, 'Destination is locked.'
         elif WriteLockInterface.isImplementedBy(parent) and \
              parent.wl_isLocked():
             if ifhdr:
                 parent.dav__simpleifhandler(REQUEST, RESPONSE, 'COPY',
                                             refresh=1)
             else:
-                raise 'Locked', 'Destination is locked.'
+                raise Locked, 'Destination is locked.'
 
         ob=self._getCopy(parent)
         ob.manage_afterClone(ob)
@@ -385,13 +402,13 @@
         self.dav__validate(self, 'DELETE', REQUEST)
         if not hasattr(aq_base(self), 'cb_isMoveable') or \
            not self.cb_isMoveable():
-            raise 'Method Not Allowed', 'This object may not be moved.'
+            raise MethodNotAllowed, 'This object may not be moved.'
 
         dest=REQUEST.get_header('Destination', '')
 
         try: path = REQUEST.physicalPathFromURL(dest)
         except ValueError:
-            raise 'Bad Request', 'No destination given'
+            raise BadRequest, 'No destination given'
 
         flag=REQUEST.get_header('Overwrite', 'F')
         flag=flag.upper()
@@ -401,23 +418,27 @@
 
         try: parent = self.restrictedTraverse(path)
         except ValueError:
-            raise 'Conflict', 'Attempt to move to an unknown namespace.'
+            raise Conflict, 'Attempt to move to an unknown namespace.'
         except 'Not Found':
-            raise 'Conflict', 'The resource %s must exist.' % parent_path
+            raise Conflict, 'The resource %s must exist.' % parent_path
         except:
             t, v, tb=sys.exc_info()
             raise t, v
         if hasattr(parent, '__null_resource__'):
-            raise 'Conflict', 'The resource %s must exist.' % parent_path
+            raise Conflict, 'The resource %s must exist.' % parent_path
         existing=hasattr(aq_base(parent), name)
         if existing and flag=='F':
-            raise 'Precondition Failed', 'Resource %s exists.' % dest
-        try: parent._checkId(name, allow_dup=1)
+            raise PreconditionFailed, 'Resource %s exists.' % dest
+        try:
+            parent._checkId(name, allow_dup=1)
+        except:
+            raise Forbidden, sys.exc_info()[1]
+        try:
+            parent._verifyObjectPaste(self)
+        except Unauthorized:
+            raise
         except:
-            raise 'Forbidden', sys.exc_info()[1]
-        try: parent._verifyObjectPaste(self)
-        except Unauthorized: raise
-        except: raise 'Forbidden', sys.exc_info()[1]
+            raise Forbidden, sys.exc_info()[1]
 
         # Now check locks.  Since we're affecting the resource that we're
         # moving as well as the destination, we have to check both.
@@ -430,9 +451,10 @@
                 if ifhdr:
                     itrue = destob.dav__simpleifhandler(
                         REQUEST, RESPONSE, 'MOVE', url=dest, refresh=1)
-                    if not itrue: raise 'Precondition Failed'
+                    if not itrue:
+                        raise PreconditionFailed
                 else:
-                    raise 'Locked', 'Destination is locked.'
+                    raise Locked, 'Destination is locked.'
         elif WriteLockInterface.isImplementedBy(parent) and \
              parent.wl_isLocked():
             # There's no existing object in the destination folder, so
@@ -441,17 +463,19 @@
             if ifhdr:
                 itrue = parent.dav__simpleifhandler(REQUEST, RESPONSE, 'MOVE',
                                                     col=1, url=dest, refresh=1)
-                if not itrue: raise 'Precondition Failed', 'Condition failed.'
+                if not itrue:
+                    raise PreconditionFailed, 'Condition failed.'
             else:
-                raise 'Locked', 'Destination is locked.'
+                raise Locked, 'Destination is locked.'
         if Lockable.wl_isLocked(self):
             # Lastly, we check ourselves
             if ifhdr:
                 itrue = self.dav__simpleifhandler(REQUEST, RESPONSE, 'MOVE',
                                                   refresh=1)
-                if not itrue: raise 'Precondition Failed', 'Condition failed.'
+                if not itrue:
+                    raise PreconditionFailed, 'Condition failed.'
             else:
-                raise 'Precondition Failed', 'Source is locked and no '\
+                raise PreconditionFailed, 'Source is locked and no '\
                       'condition was passed in.'
 
         ob=aq_base(self._getCopy(parent))
@@ -507,7 +531,7 @@
         else:
             # There's no body, so this likely to be a refresh request
             if not ifhdr:
-                raise 'Precondition Failed', 'If Header Missing'
+                raise PreconditionFailed, 'If Header Missing'
             taglist = IfParser(ifhdr)
             found = 0
             for tag in taglist:


=== Zope/lib/python/webdav/client.py 1.20 => 1.21 ===
--- Zope/lib/python/webdav/client.py:1.20	Wed Aug 14 18:11:40 2002
+++ Zope/lib/python/webdav/client.py	Tue Nov 18 08:17:20 2003
@@ -13,7 +13,8 @@
 from urllib import quote
 
 
-
+class NotAvailable(Exception):
+    pass
 
 class HTTP(httplib.HTTP):
     # A revised version of the HTTP class that can do basic
@@ -124,7 +125,7 @@
             data=h.getfile().read()
             h.close()
         except:
-            raise 'NotAvailable', sys.exc_value
+            raise NotAvailable, sys.exc_value
         return http_response(ver, code, msg, hdrs, data)
 
     # HTTP methods


=== Zope/lib/python/webdav/common.py 1.17 => 1.18 ===
--- Zope/lib/python/webdav/common.py:1.17	Wed Aug 14 18:11:40 2002
+++ Zope/lib/python/webdav/common.py	Tue Nov 18 08:17:20 2003
@@ -22,6 +22,21 @@
 
 _randGen = random.Random(time.time())
 
+class WebDAVException(Exception):
+    pass
+
+class Locked(WebDAVException):
+    pass
+
+class PreconditionFailed(WebDAVException):
+    pass
+
+class Conflict(WebDAVException):
+    pass
+
+class UnsupportedMediaType(WebDAVException):
+    pass
+
 def absattr(attr):
     if callable(attr):
         return attr()


=== Zope/lib/python/webdav/davcmds.py 1.21 => 1.22 ===
--- Zope/lib/python/webdav/davcmds.py:1.21	Tue Oct 21 10:49:48 2003
+++ Zope/lib/python/webdav/davcmds.py	Tue Nov 18 08:17:20 2003
@@ -11,9 +11,10 @@
 #
 ##############################################################################
 
-"""WebDAV xml request objects."""
+"""WebDAV xml request objects.
 
-__version__='$Revision$'[11:-2]
+$Id$
+"""
 
 import sys, os
 from common import absattr, aq_base, urlfix, urlbase
@@ -25,7 +26,9 @@
 from cStringIO import StringIO
 from urllib import quote
 from AccessControl import getSecurityManager
+from zExceptions import BadRequest, Forbidden
 from common import isDavCollection
+from common import PreconditionFailed
 
 def safe_quote(url, mark=r'%'):
     if url.find(mark) > -1:
@@ -58,14 +61,18 @@
     def parse(self, request, dav='DAV:'):
         self.depth=request.get_header('Depth', 'infinity')
         if not (self.depth in ('0','1','infinity')):
-            raise 'Bad Request', 'Invalid Depth header.'
+            raise BadRequest, 'Invalid Depth header.'
         body=request.get('BODY', '')
         self.allprop=(not len(body))
-        if not body: return
-        try:    root=XmlParser().parse(body)
-        except: raise 'Bad Request', sys.exc_info()[1]
+        if not body:
+            return
+        try:
+            root=XmlParser().parse(body)
+        except:
+            raise BadRequest, sys.exc_info()[1]
         e=root.elements('propfind', ns=dav)
-        if not e: raise 'Bad Request', 'Invalid xml request.'
+        if not e:
+            raise BadRequest, 'Invalid xml request.'
         e=e[0]
         if e.elements('allprop', ns=dav):
             self.allprop=1
@@ -74,13 +81,14 @@
             self.propname=1
             return
         prop=e.elements('prop', ns=dav)
-        if not prop: raise 'Bad Request', 'Invalid xml request.'
+        if not prop:
+            raise BadRequest, 'Invalid xml request.'
         prop=prop[0]
         for val in prop.elements():
             self.propnames.append((val.name(), val.namespace()))
         if (not self.allprop) and (not self.propname) and \
            (not self.propnames):
-            raise 'Bad Request', 'Invalid xml request.'
+            raise BadRequest, 'Invalid xml request.'
         return
 
     def apply(self, obj, url=None, depth=0, result=None, top=1):
@@ -126,7 +134,8 @@
                     code='404 Not Found'
                     if not rdict.has_key(code):
                         rdict[code]=[prop]
-                    else: rdict[code].append(prop)
+                    else:
+                        rdict[code].append(prop)
             keys=rdict.keys()
             keys.sort()
             for key in keys:
@@ -138,22 +147,27 @@
                              '  <d:status>HTTP/1.1 %s</d:status>\n' \
                              '</d:propstat>\n' % key
                              )
-        else: raise 'Bad Request', 'Invalid request'
+        else:
+            raise BadRequest, 'Invalid request'
         result.write('</d:response>\n')
         if depth in ('1', 'infinity') and iscol:
             for ob in obj.listDAVObjects():
                 if hasattr(ob,"meta_type"):
-                    if ob.meta_type=="Broken Because Product is Gone": continue
+                    if ob.meta_type=="Broken Because Product is Gone":
+                        continue
                 dflag=hasattr(ob, '_p_changed') and (ob._p_changed == None)
                 if hasattr(ob, '__locknull_resource__'):
                     # Do nothing, a null resource shouldn't show up to DAV
-                    if dflag: ob._p_deactivate()
+                    if dflag:
+                        ob._p_deactivate()
                 elif hasattr(ob, '__dav_resource__'):
                     uri=os.path.join(url, absattr(ob.id))
                     depth=depth=='infinity' and depth or 0
                     self.apply(ob, uri, depth, result, top=0)
-                    if dflag: ob._p_deactivate()
-        if not top: return result
+                    if dflag:
+                        ob._p_deactivate()
+        if not top:
+            return result
         result.write('</d:multistatus>')
 
         return result.getvalue()
@@ -169,16 +183,20 @@
 
     def parse(self, request, dav='DAV:'):
         body=request.get('BODY', '')
-        try:    root=XmlParser().parse(body)
-        except: raise 'Bad Request', sys.exc_info()[1]
+        try:
+            root=XmlParser().parse(body)
+        except:
+            raise BadRequest, sys.exc_info()[1]
         vals=self.values
         e=root.elements('propertyupdate', ns=dav)
-        if not e: raise 'Bad Request', 'Invalid xml request.'
+        if not e:
+            raise BadRequest, 'Invalid xml request.'
         e=e[0]
         for ob in e.elements():
             if ob.name()=='set' and ob.namespace()==dav:
                 proptag=ob.elements('prop', ns=dav)
-                if not proptag: raise 'Bad Request', 'Invalid xml request.'
+                if not proptag:
+                    raise BadRequest, 'Invalid xml request.'
                 proptag=proptag[0]
                 for prop in proptag.elements():
                     # We have to ensure that all tag attrs (including
@@ -202,7 +220,8 @@
                         vals.append(item)
             if ob.name()=='remove' and ob.namespace()==dav:
                 proptag=ob.elements('prop', ns=dav)
-                if not proptag: raise 'Bad Request', 'Invalid xml request.'
+                if not proptag:
+                    raise BadRequest, 'Invalid xml request.'
                 proptag=proptag[0]
                 for prop in proptag.elements():
                     item=(prop.name(), prop.namespace())
@@ -229,12 +248,14 @@
                     propset=propsets.get(ns)
                 propdict=propset._propdict()
                 if propset.hasProperty(name):
-                    try: propset._updateProperty(name, val, meta=md)
+                    try:
+                        propset._updateProperty(name, val, meta=md)
                     except:
                         errors.append(str(sys.exc_info()[1]))
                         status='409 Conflict'
                 else:
-                    try: propset._setProperty(name, val, meta=md)
+                    try:
+                        propset._setProperty(name, val, meta=md)
                     except:
                         errors.append(str(sys.exc_info()[1]))
                         status='409 Conflict'
@@ -246,11 +267,13 @@
                     # according to RFC 2518
                     status='200 OK'
                 else:
-                    try: propset._delProperty(name)
+                    try:
+                        propset._delProperty(name)
                     except:
                         errors.append('%s cannot be deleted.' % name)
                         status='409 Conflict'
-            if result != '200 OK': abort=1
+            if result != '200 OK':
+                abort = 1
             result.write('<d:propstat xmlns:n="%s">\n' \
                          '  <d:prop>\n' \
                          '  <n:%s/>\n' \
@@ -264,7 +287,8 @@
                      '</d:response>\n' \
                      '</d:multistatus>' % errmsg)
         result=result.getvalue()
-        if not errors: return result
+        if not errors:
+            return result
         # This is lame, but I cant find a way to keep ZPublisher
         # from sticking a traceback into my xml response :(
         get_transaction().abort()
@@ -325,14 +349,16 @@
             url = urlfix(self.request['URL'], 'LOCK')
             url = urlbase(url)
         iscol = isDavCollection(obj)
-        if iscol and url[-1] != '/': url = url + '/'
+        if iscol and url[-1] != '/':
+            url = url + '/'
         errmsg = None
         lock = None
 
         try:
             lock = LockItem(creator, self.owner, depth, self.timeout,
                             self.type, self.scope, token)
-            if token is None: token = lock.getLockToken()
+            if token is None:
+                token = lock.getLockToken()
 
         except ValueError, valerrors:
             errmsg = "412 Precondition Failed"
@@ -381,7 +407,8 @@
                     uri = os.path.join(url, absattr(ob.id))
                     self.apply(ob, creator, depth, token, result,
                                uri, top=0)
-        if not top: return token, result
+        if not top:
+            return token, result
         if result.getvalue():
             # One or more subitems probably failed, so close the multistatus
             # element and clear out all succesful locks
@@ -399,7 +426,8 @@
             url = urlfix(url, 'UNLOCK')
             url = urlbase(url)
         iscol = isDavCollection(obj)
-        if iscol and url[-1] != '/': url = url + '/'
+        if iscol and url[-1] != '/':
+            url = url + '/'
         errmsg = None
 
         islockable = WriteLockInterface.isImplementedBy(obj)
@@ -407,7 +435,8 @@
         if islockable and obj.wl_hasLock(token):
             method = getattr(obj, 'wl_delLock')
             vld = getSecurityManager().validate(None,obj,'wl_delLock',method)
-            if vld: obj.wl_delLock(token)
+            if vld:
+                obj.wl_delLock(token)
             else:
                 errmsg = "403 Forbidden"
         elif not islockable:
@@ -415,13 +444,16 @@
             # to a top level object.  Otherwise, we're descending a tree
             # which may contain many objects that don't implement locking,
             # so we just want to avoid them
-            if top: errmsg = "405 Method Not Allowed"
+            if top:
+                errmsg = "405 Method Not Allowed"
 
         if errmsg:
             if top and (not iscol):
                 # We don't need to raise multistatus errors
-                if errmsg[:3] == '403': raise "Forbidden"
-                else: raise "Precondition Failed"
+                if errmsg[:3] == '403':
+                    raise Forbidden
+                else:
+                    raise PreconditionFailed
             elif not result.getvalue():
                 # We haven't had any errors yet, so our result is empty
                 # and we need to set up the XML header
@@ -437,7 +469,8 @@
                    WriteLockInterface.isImplementedBy(ob):
                     uri = os.path.join(url, absattr(ob.id))
                     self.apply(ob, token, uri, result, top=0)
-        if not top: return result
+        if not top:
+            return result
         if result.getvalue():
             # One or more subitems probably failed, so close the multistatus
             # element and clear out all succesful unlocks
@@ -490,8 +523,10 @@
                 if hasattr(ob, '__dav_resource__'):
                     uri = os.path.join(url, absattr(ob.id))
                     self.apply(ob, token, user, uri, result, top=0)
-                    if dflag: ob._p_deactivate()
-        if not top: return result
+                    if dflag:
+                        ob._p_deactivate()
+        if not top:
+            return result
         if result.getvalue():
             # One or more subitems can't be delted, so close the multistatus
             # element




More information about the Zope-Checkins mailing list