From 3c757dac1359e2b58b57e2da892c700655ab5e6d Mon Sep 17 00:00:00 2001 From: Chris Vigelius Date: Thu, 11 May 2017 09:37:08 +0200 Subject: [PATCH 1/2] compatibility patch for use with https://github.com/perry-mitchell/webdav-client --- djangodav/base/resources.py | 2 +- djangodav/views/views.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/djangodav/base/resources.py b/djangodav/base/resources.py index 32b816b..66e1be2 100644 --- a/djangodav/base/resources.py +++ b/djangodav/base/resources.py @@ -70,7 +70,7 @@ def get_descendants(self, depth=1, include_self=True): # If depth is less than 0, then it started out as -1. # We need to keep recursing until we hit 0, or forever # in case of infinity. - if depth != 0: + if depth != 0 and self.is_collection: for child in self.get_children(): for desc in child.get_descendants(depth=depth-1, include_self=True): yield desc diff --git a/djangodav/views/views.py b/djangodav/views/views.py index 7cc46ca..9592467 100644 --- a/djangodav/views/views.py +++ b/djangodav/views/views.py @@ -53,14 +53,17 @@ def dispatch(self, request, path, *args, **kwargs): meta = request.META.get self.xbody = kwargs['xbody'] = None - if (request.method.lower() != 'put' - and "/xml" in meta('CONTENT_TYPE', '') - and meta('CONTENT_LENGTH', 0) != '' - and int(meta('CONTENT_LENGTH', 0)) > 0): - self.xbody = kwargs['xbody'] = etree.XPathDocumentEvaluator( - etree.parse(request, etree.XMLParser(ns_clean=True)), - namespaces=WEBDAV_NSMAP - ) + try: + if (request.method.lower() != 'put' + # and "/xml" in meta('CONTENT_TYPE', '') + and meta('CONTENT_LENGTH', 0) != '' + and int(meta('CONTENT_LENGTH', 0)) > 0): + self.xbody = kwargs['xbody'] = etree.XPathDocumentEvaluator( + etree.parse(request, etree.XMLParser(ns_clean=True)), + namespaces=WEBDAV_NSMAP + ) + except etree.ParseError: + return HttpResponseBadRequest("invalid XML in body") if request.method.upper() in self._allowed_methods(): handler = getattr(self, request.method.lower(), self.http_method_not_allowed) From 9f82341d4ac0685f271033a2507a4255ba6c37e9 Mon Sep 17 00:00:00 2001 From: Chris Vigelius Date: Thu, 11 May 2017 11:01:29 +0200 Subject: [PATCH 2/2] fix unittest --- djangodav/base/tests/tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/djangodav/base/tests/tests.py b/djangodav/base/tests/tests.py index c4ab8eb..bea6e0f 100644 --- a/djangodav/base/tests/tests.py +++ b/djangodav/base/tests/tests.py @@ -40,6 +40,7 @@ def test_get_path_collection(self): def test_get_path_object(self): self.assertEqual(self.resource.get_path(), '/path/to/name') + @patch('djangodav.base.resources.BaseDavResource.is_collection', True) @patch('djangodav.base.resources.BaseDavResource.get_children', Mock(return_value=[])) def test_get_descendants(self): self.assertEqual(list(self.resource.get_descendants(depth=1, include_self=True)), [self.resource])