# HG changeset patch # User Sebastien Jodogne # Date 1602698126 -7200 # Node ID 66a36befb208e8dca433f2d5d8776fac84f54057 # Parent 60775134a4065cfa8922f1764551491d56f9b61c extending Toolbox.DoPropFind() diff -r 60775134a406 -r 66a36befb208 Tests/Tests.py --- a/Tests/Tests.py Wed Oct 14 17:57:38 2020 +0200 +++ b/Tests/Tests.py Wed Oct 14 19:55:26 2020 +0200 @@ -6018,9 +6018,12 @@ self.assertRaises(Exception, lambda: DoPropFind(_REMOTE, '/webdav/', 2)) xml = DoPropFind(_REMOTE, '/webdav/', 1) + pprint.pprint(xml.keys()) + print(xml['/webdav/'].toprettyxml()) + #print(xml.toprettyxml()) - for i in xml.getElementsByTagName('D:response'): - print(i.getElementsByTagName('D:href')[0].childNodes[0].data) + #for i in xml.getElementsByTagName('D:response'): + # print(i.getElementsByTagName('D:href')[0].childNodes[0].data) # print(i.getElementsByTagName('D:prop')[0].toprettyxml()) diff -r 60775134a406 -r 66a36befb208 Tests/Toolbox.py --- a/Tests/Toolbox.py Wed Oct 14 17:57:38 2020 +0200 +++ b/Tests/Toolbox.py Wed Oct 14 19:55:26 2020 +0200 @@ -43,9 +43,11 @@ from urllib.parse import urlencode from io import StringIO from io import BytesIO + from urllib.parse import unquote else: from urllib import urlencode + from urlparse import unquote # http://stackoverflow.com/a/1313868/881731 try: @@ -53,7 +55,7 @@ except: from StringIO import StringIO - + def _DecodeJson(s): t = s @@ -442,5 +444,43 @@ if not (resp.status in [ 207 ]): raise Exception(resp.status, resp) else: - return minidom.parseString(content) + xml = minidom.parseString(content) + + if (xml.documentElement.nodeName != 'D:multistatus' or + xml.documentElement.attributes['xmlns:D'].value != 'DAV:'): + raise Exception() + result = {} + + for i in xml.documentElement.childNodes: + if i.nodeType == minidom.Node.ELEMENT_NODE: + if i.nodeName != 'D:response': + raise Exception() + href = None + prop = None + for j in i.childNodes: + if j.nodeType == minidom.Node.ELEMENT_NODE: + if j.nodeName == 'D:href': + if href == None: + href = unquote(j.firstChild.nodeValue) + else: + raise Exception() + elif j.nodeName == 'D:propstat': + for k in j.childNodes: + if k.nodeName == 'D:status': + if k.firstChild.nodeValue != 'HTTP/1.1 200 OK': + raise Exception() + elif k.nodeType == minidom.Node.ELEMENT_NODE: + if (k.nodeName != 'D:prop' or + prop != None): + raise Exception() + prop = k + else: + raise Exception() + if href == None or prop == None: + raise Exception() + result[href] = prop + elif i.nodeType != minidom.Node.TEXT_NODE: + raise Exception() + + return result