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.
This commit is contained in:
Emil 'Skeen' Madsen 2019-11-26 12:05:33 +01:00 committed by Evgeny Ezhov
parent da46592c6f
commit 1fb79c36be

View file

@ -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)