Merge pull request #3 from a1ezzz/path_search_fix

webdav3/client.py: WebDavXmlUtils.extract_response_for_path method no…
This commit is contained in:
Evgeny Ezhov 2018-05-07 11:11:17 +03:00 committed by GitHub
commit 794d9248f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,9 +16,10 @@ from webdav3.exceptions import *
from webdav3.urn import Urn
try:
from urllib.parse import unquote
from urllib.parse import unquote, urlsplit
except ImportError:
from urllib import unquote
from urlparse import urlsplit
__version__ = "0.2"
log = logging.getLogger(__name__)
@ -961,20 +962,20 @@ class WebDavXmlUtils:
try:
tree = etree.fromstring(content)
responses = tree.findall("{DAV:}response")
def normalization_fn(p):
result = (sub, '/{2,}', '/')
return result if result[-1] != Urn.separate else result[:-1]
normalized_path = normalization_fn(path)
for resp in responses:
href = resp.findtext("{DAV:}href")
urn = unquote(href)
if path[-1] == Urn.separate:
# remove / from path to compare with urn
# e.g. /path = /path
if not path[:-1] == urn:
continue
else:
path_with_sep = "{path}{sep}".format(path=path, sep=Urn.separate)
if not path == urn and not path_with_sep == urn:
continue
return resp
urn = unquote(urlsplit(href).path)
if normalized_path == normalization_fn(urn):
return resp
raise RemoteResourceNotFound(path)
except etree.XMLSyntaxError:
raise MethodNotSupported(name="is_dir", server=hostname)