Mercurial > hg > orthanc-tests
comparison Tests/Toolbox.py @ 341:66a36befb208
extending Toolbox.DoPropFind()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 14 Oct 2020 19:55:26 +0200 |
parents | ec13ace43bde |
children | bf8369ea3ff1 |
comparison
equal
deleted
inserted
replaced
340:60775134a406 | 341:66a36befb208 |
---|---|
41 | 41 |
42 if (sys.version_info >= (3, 0)): | 42 if (sys.version_info >= (3, 0)): |
43 from urllib.parse import urlencode | 43 from urllib.parse import urlencode |
44 from io import StringIO | 44 from io import StringIO |
45 from io import BytesIO | 45 from io import BytesIO |
46 from urllib.parse import unquote | |
46 | 47 |
47 else: | 48 else: |
48 from urllib import urlencode | 49 from urllib import urlencode |
50 from urlparse import unquote | |
49 | 51 |
50 # http://stackoverflow.com/a/1313868/881731 | 52 # http://stackoverflow.com/a/1313868/881731 |
51 try: | 53 try: |
52 from cStringIO import StringIO | 54 from cStringIO import StringIO |
53 except: | 55 except: |
54 from StringIO import StringIO | 56 from StringIO import StringIO |
55 | 57 |
56 | 58 |
57 def _DecodeJson(s): | 59 def _DecodeJson(s): |
58 t = s | 60 t = s |
59 | 61 |
60 if (sys.version_info >= (3, 0)): | 62 if (sys.version_info >= (3, 0)): |
61 try: | 63 try: |
440 resp, content = http.request(orthanc['Url'] + uri, 'PROPFIND', headers = { 'Depth' : str(depth) }) | 442 resp, content = http.request(orthanc['Url'] + uri, 'PROPFIND', headers = { 'Depth' : str(depth) }) |
441 | 443 |
442 if not (resp.status in [ 207 ]): | 444 if not (resp.status in [ 207 ]): |
443 raise Exception(resp.status, resp) | 445 raise Exception(resp.status, resp) |
444 else: | 446 else: |
445 return minidom.parseString(content) | 447 xml = minidom.parseString(content) |
446 | 448 |
449 if (xml.documentElement.nodeName != 'D:multistatus' or | |
450 xml.documentElement.attributes['xmlns:D'].value != 'DAV:'): | |
451 raise Exception() | |
452 | |
453 result = {} | |
454 | |
455 for i in xml.documentElement.childNodes: | |
456 if i.nodeType == minidom.Node.ELEMENT_NODE: | |
457 if i.nodeName != 'D:response': | |
458 raise Exception() | |
459 href = None | |
460 prop = None | |
461 for j in i.childNodes: | |
462 if j.nodeType == minidom.Node.ELEMENT_NODE: | |
463 if j.nodeName == 'D:href': | |
464 if href == None: | |
465 href = unquote(j.firstChild.nodeValue) | |
466 else: | |
467 raise Exception() | |
468 elif j.nodeName == 'D:propstat': | |
469 for k in j.childNodes: | |
470 if k.nodeName == 'D:status': | |
471 if k.firstChild.nodeValue != 'HTTP/1.1 200 OK': | |
472 raise Exception() | |
473 elif k.nodeType == minidom.Node.ELEMENT_NODE: | |
474 if (k.nodeName != 'D:prop' or | |
475 prop != None): | |
476 raise Exception() | |
477 prop = k | |
478 else: | |
479 raise Exception() | |
480 if href == None or prop == None: | |
481 raise Exception() | |
482 result[href] = prop | |
483 elif i.nodeType != minidom.Node.TEXT_NODE: | |
484 raise Exception() | |
485 | |
486 return result |