From 1fb79c36be572f2b8240b32d4571982b1791948a Mon Sep 17 00:00:00 2001 From: Emil 'Skeen' Madsen Date: Tue, 26 Nov 2019 12:05:33 +0100 Subject: [PATCH] Stripping suburl from paths in extract_response_for_path (#15) When accessing a server on a suburl, such as an Alfresco WebDav: http://172.17.0.8:8080/alfresco/webdav The file paths processed by extract_response_for_path, specifically href contains the suburl as a prefix, for instance: /alfresco/webdav/Sites/ rather than just Sites/. I am not sure if this is a specific problem with Alfresco WebDav, or a common issue. Either way, the provided code fixes this issue by removing the suburl from paths, if it exists. --- webdav3/client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/webdav3/client.py b/webdav3/client.py index 82b26d6..0a4b308 100644 --- a/webdav3/client.py +++ b/webdav3/client.py @@ -16,10 +16,10 @@ from webdav3.exceptions import * from webdav3.urn import Urn try: - from urllib.parse import unquote, urlsplit + from urllib.parse import unquote, urlsplit, urlparse except ImportError: from urllib import unquote - from urlparse import urlsplit + from urlparse import urlsplit, urlparse __version__ = "0.2" log = logging.getLogger(__name__) @@ -959,10 +959,10 @@ class WebDavXmlUtils: :param hostname: the server hostname. :return: XML object of response for the remote resource defined by path. """ + prefix = urlparse(hostname).path try: tree = etree.fromstring(content) responses = tree.findall("{DAV:}response") - n_path = Urn.normalize_path(path) for resp in responses: @@ -970,6 +970,9 @@ class WebDavXmlUtils: if Urn.compare_path(n_path, href) is True: return resp + href_without_prefix = href[len(prefix):] if href.startswith(prefix) else href + if Urn.compare_path(n_path, href_without_prefix) is True: + return resp raise RemoteResourceNotFound(path) except etree.XMLSyntaxError: raise MethodNotSupported(name="is_dir", server=hostname)