Commit d0685ae5 authored by 's avatar

Misc bug fixes

parent 8557dcb7
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""WebDAV support - resource objects.""" """WebDAV support - resource objects."""
__version__='$Revision: 1.13 $'[11:-2] __version__='$Revision: 1.14 $'[11:-2]
import sys, os, string, mimetypes, xmlcmds import sys, os, string, mimetypes, xmlcmds
from common import absattr, aq_base, urlfix, rfc1123_date from common import absattr, aq_base, urlfix, rfc1123_date
...@@ -185,8 +185,7 @@ class Resource: ...@@ -185,8 +185,7 @@ class Resource:
def PROPFIND(self, REQUEST, RESPONSE): def PROPFIND(self, REQUEST, RESPONSE):
"""Retrieve properties defined on the resource.""" """Retrieve properties defined on the resource."""
self.dav__init(REQUEST, RESPONSE) self.dav__init(REQUEST, RESPONSE)
try: cmd=xmlcmds.PropFind(REQUEST) cmd=xmlcmds.PropFind(REQUEST)
except: raise 'Bad Request', 'Invalid xml request.'
result=cmd.apply(self) result=cmd.apply(self)
RESPONSE.setStatus(207) RESPONSE.setStatus(207)
RESPONSE.setHeader('Content-Type', 'text/xml; charset="utf-8"') RESPONSE.setHeader('Content-Type', 'text/xml; charset="utf-8"')
...@@ -200,8 +199,7 @@ class Resource: ...@@ -200,8 +199,7 @@ class Resource:
raise 'Method Not Allowed', ( raise 'Method Not Allowed', (
'Method not supported for this resource.') 'Method not supported for this resource.')
# TODO: add lock checking here # TODO: add lock checking here
try: cmd=xmlcmds.PropPatch(REQUEST) cmd=xmlcmds.PropPatch(REQUEST)
except: raise 'Bad Request', 'Invalid xml request.'
result=cmd.apply(self) result=cmd.apply(self)
RESPONSE.setStatus(207) RESPONSE.setStatus(207)
RESPONSE.setHeader('Content-Type', 'text/xml; charset="utf-8"') RESPONSE.setHeader('Content-Type', 'text/xml; charset="utf-8"')
...@@ -225,14 +223,16 @@ class Resource: ...@@ -225,14 +223,16 @@ class Resource:
not self.cb_isCopyable(): not self.cb_isCopyable():
raise 'Method Not Allowed', 'This object may not be copied.' raise 'Method Not Allowed', 'This object may not be copied.'
depth=REQUEST.get_header('Depth', 'infinity') depth=REQUEST.get_header('Depth', 'infinity')
if not depth in ('0', 'infinity'):
raise 'Bad Request', 'Invalid Depth header.'
dest=REQUEST.get_header('Destination', '') dest=REQUEST.get_header('Destination', '')
while dest and dest[-1]=='/': while dest and dest[-1]=='/':
dest=dest[:-1] dest=dest[:-1]
if not dest: if not dest:
raise 'Bad Request', 'No destination given' raise 'Bad Request', 'Invalid Destination header.'
flag=REQUEST.get_header('Overwrite', 'F') oflag=string.upper(REQUEST.get_header('Overwrite', 'F'))
flag=string.upper(flag) if not oflag in ('T', 'F'):
body=REQUEST.get('BODY', '') raise 'Bad Request', 'Invalid Overwrite header.'
path, name=os.path.split(dest) path, name=os.path.split(dest)
try: parent=REQUEST.resolve_url(path) try: parent=REQUEST.resolve_url(path)
except ValueError: except ValueError:
...@@ -243,8 +243,8 @@ class Resource: ...@@ -243,8 +243,8 @@ class Resource:
if hasattr(parent, '__dav_null__'): if hasattr(parent, '__dav_null__'):
raise 'Conflict', 'Object ancestors must already exist.' raise 'Conflict', 'Object ancestors must already exist.'
existing=hasattr(aq_base(parent), name) existing=hasattr(aq_base(parent), name)
if existing and flag=='F': if existing and oflag=='F':
raise 'Precondition Failed', 'Resource %s exists.' % dest raise 'Precondition Failed', 'Destination resource exists.'
try: parent._checkId(name, allow_dup=1) try: parent._checkId(name, allow_dup=1)
except: raise 'Forbidden', sys.exc_value except: raise 'Forbidden', sys.exc_value
try: parent._verifyObjectPaste(self, REQUEST) try: parent._verifyObjectPaste(self, REQUEST)
...@@ -253,6 +253,13 @@ class Resource: ...@@ -253,6 +253,13 @@ class Resource:
except: raise 'Forbidden', sys.exc_value except: raise 'Forbidden', sys.exc_value
ob=self._getCopy(parent) ob=self._getCopy(parent)
ob._setId(name) ob._setId(name)
if depth=='0' and hasattr(ob, '__dav_collection__'):
for id in ob.objectIds():
ob._delObject(id)
if existing:
object=getattr(parent, name)
obj.dav__validate(object, 'DELETE', request)
parent._delObject(name)
parent._setObject(name, ob) parent._setObject(name, ob)
ob=ob.__of__(parent) ob=ob.__of__(parent)
ob._postCopy(parent, op=0) ob._postCopy(parent, op=0)
...@@ -304,8 +311,7 @@ class Resource: ...@@ -304,8 +311,7 @@ class Resource:
if existing: if existing:
object=getattr(parent, name) object=getattr(parent, name)
self.dav__validate(object, 'DELETE', REQUEST) self.dav__validate(object, 'DELETE', REQUEST)
parent._delObject(name) parent._delObject(name)
parent._setObject(name, ob) parent._setObject(name, ob)
ob=ob.__of__(parent) ob=ob.__of__(parent)
ob._postCopy(parent, op=1) ob._postCopy(parent, op=1)
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""WebDAV xml request objects.""" """WebDAV xml request objects."""
__version__='$Revision: 1.14 $'[11:-2] __version__='$Revision: 1.15 $'[11:-2]
import sys, os, string import sys, os, string
from common import absattr, aq_base, urlfix from common import absattr, aq_base, urlfix
...@@ -108,26 +108,38 @@ class PropFind: ...@@ -108,26 +108,38 @@ class PropFind:
"""Model a PROPFIND request.""" """Model a PROPFIND request."""
def __init__(self, request): def __init__(self, request):
self.request=request self.request=request
data=request.get('BODY', '') self.depth='infinity'
self.depth=request.get_header('Depth', 'infinity') self.allprop=0
self.allprop=(not len(data))
self.propname=0 self.propname=0
self.propnames=[] self.propnames=[]
self.parse(data) self.parse(request)
def parse(self, data, dav='DAV:'): def parse(self, request, dav='DAV:'):
if not data: return self.depth=request.get_header('Depth', 'infinity')
root=XmlParser().parse(data) if not (self.depth in ('0','1','infinity')):
e=root.elements('propfind', ns=dav)[0] raise 'Bad Request', '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_value
e=root.elements('propfind', ns=dav)
if not e: raise 'Bad Request', 'Invalid xml request.'
e=e[0]
if e.elements('allprop', ns=dav): if e.elements('allprop', ns=dav):
self.allprop=1 self.allprop=1
return return
if e.elements('propname', ns=dav): if e.elements('propname', ns=dav):
self.propname=1 self.propname=1
return return
prop=e.elements('prop', ns=dav)[0] prop=e.elements('prop', ns=dav)
if not prop: raise 'Bad Request', 'Invalid xml request.'
prop=prop[0]
for val in prop.elements(): for val in prop.elements():
self.propnames.append((val.name(), val.namespace())) 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.'
return return
def apply(self, obj, url=None, depth=0, result=None, top=1): def apply(self, obj, url=None, depth=0, result=None, top=1):
...@@ -196,17 +208,22 @@ class PropPatch: ...@@ -196,17 +208,22 @@ class PropPatch:
"""Model a PROPPATCH request.""" """Model a PROPPATCH request."""
def __init__(self, request): def __init__(self, request):
self.request=request self.request=request
data=request.get('BODY', '')
self.values=[] self.values=[]
self.parse(data) self.parse(request)
def parse(self, data, dav='DAV:'): def parse(self, request, dav='DAV:'):
root=XmlParser().parse(data) body=request.get('BODY', '')
try: root=XmlParser().parse(body)
except: raise 'Bad Request', sys.exc_value
vals=self.values vals=self.values
e=root.elements('propertyupdate', ns=dav)[0] e=root.elements('propertyupdate', ns=dav)
if not e: raise 'Bad Request', 'Invalid xml request.'
e=e[0]
for ob in e.elements(): for ob in e.elements():
if ob.name()=='set' and ob.namespace()==dav: if ob.name()=='set' and ob.namespace()==dav:
proptag=ob.elements('prop', ns=dav)[0] proptag=ob.elements('prop', ns=dav)
if not proptag: raise 'Bad Request', 'Invalid xml request.'
proptag=proptag[0]
for prop in proptag.elements(): for prop in proptag.elements():
# We have to ensure that all tag attrs (including # We have to ensure that all tag attrs (including
# an xmlns attr for all xml namespaces used by the # an xmlns attr for all xml namespaces used by the
...@@ -227,9 +244,10 @@ class PropPatch: ...@@ -227,9 +244,10 @@ class PropPatch:
md={'__xml_attrs__':attrs} md={'__xml_attrs__':attrs}
item=(name, ns, prop.strval(), md) item=(name, ns, prop.strval(), md)
vals.append(item) vals.append(item)
if ob.name()=='remove' and ob.namespace()==dav: if ob.name()=='remove' and ob.namespace()==dav:
proptag=ob.elements('prop', ns=dav)[0] proptag=ob.elements('prop', ns=dav)
if not proptag: raise 'Bad Request', 'Invalid xml request.'
proptag=proptag[0]
for prop in proptag.elements(): for prop in proptag.elements():
item=(prop.name(), prop.namespace()) item=(prop.name(), prop.namespace())
vals.append(item) vals.append(item)
...@@ -299,6 +317,7 @@ class PropPatch: ...@@ -299,6 +317,7 @@ class PropPatch:
class Lock: class Lock:
"""Model a LOCK request.""" """Model a LOCK request."""
def __init__(self, request): def __init__(self, request):
......
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