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:
parent
da46592c6f
commit
1fb79c36be
1 changed files with 6 additions and 3 deletions
|
@ -16,10 +16,10 @@ from webdav3.exceptions import *
|
||||||
from webdav3.urn import Urn
|
from webdav3.urn import Urn
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from urllib.parse import unquote, urlsplit
|
from urllib.parse import unquote, urlsplit, urlparse
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib import unquote
|
from urllib import unquote
|
||||||
from urlparse import urlsplit
|
from urlparse import urlsplit, urlparse
|
||||||
|
|
||||||
__version__ = "0.2"
|
__version__ = "0.2"
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -959,10 +959,10 @@ class WebDavXmlUtils:
|
||||||
:param hostname: the server hostname.
|
:param hostname: the server hostname.
|
||||||
:return: XML object of response for the remote resource defined by path.
|
:return: XML object of response for the remote resource defined by path.
|
||||||
"""
|
"""
|
||||||
|
prefix = urlparse(hostname).path
|
||||||
try:
|
try:
|
||||||
tree = etree.fromstring(content)
|
tree = etree.fromstring(content)
|
||||||
responses = tree.findall("{DAV:}response")
|
responses = tree.findall("{DAV:}response")
|
||||||
|
|
||||||
n_path = Urn.normalize_path(path)
|
n_path = Urn.normalize_path(path)
|
||||||
|
|
||||||
for resp in responses:
|
for resp in responses:
|
||||||
|
@ -970,6 +970,9 @@ class WebDavXmlUtils:
|
||||||
|
|
||||||
if Urn.compare_path(n_path, href) is True:
|
if Urn.compare_path(n_path, href) is True:
|
||||||
return resp
|
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)
|
raise RemoteResourceNotFound(path)
|
||||||
except etree.XMLSyntaxError:
|
except etree.XMLSyntaxError:
|
||||||
raise MethodNotSupported(name="is_dir", server=hostname)
|
raise MethodNotSupported(name="is_dir", server=hostname)
|
||||||
|
|
Loading…
Add table
Reference in a new issue