webdav3/client.py: Client.list method fix
This commit is contained in:
parent
370d35e72f
commit
4f1d1ec869
2 changed files with 18 additions and 13 deletions
|
@ -246,8 +246,8 @@ class Client(object):
|
||||||
response = self.execute_request(action='list', path=directory_urn.quote())
|
response = self.execute_request(action='list', path=directory_urn.quote())
|
||||||
urns = WebDavXmlUtils.parse_get_list_response(response.content)
|
urns = WebDavXmlUtils.parse_get_list_response(response.content)
|
||||||
|
|
||||||
path = self.get_full_path(directory_urn)
|
path = Urn.normalize_path(self.get_full_path(directory_urn))
|
||||||
return [urn.filename() for urn in urns if urn.path() != path and urn.path() != path[:-1]]
|
return [urn.filename() for urn in urns if Urn.compare_path(path, urn.path()) is False]
|
||||||
|
|
||||||
@wrap_connection_error
|
@wrap_connection_error
|
||||||
def free(self):
|
def free(self):
|
||||||
|
@ -814,7 +814,7 @@ class WebDavXmlUtils:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
tree = etree.fromstring(content)
|
tree = etree.fromstring(content)
|
||||||
hrees = [unquote(hree.text) for hree in tree.findall(".//{DAV:}href")]
|
hrees = [Urn.separate + unquote(urlsplit(hree.text).path) for hree in tree.findall(".//{DAV:}href")]
|
||||||
return [Urn(hree) for hree in hrees]
|
return [Urn(hree) for hree in hrees]
|
||||||
except etree.XMLSyntaxError:
|
except etree.XMLSyntaxError:
|
||||||
return list()
|
return list()
|
||||||
|
@ -963,18 +963,12 @@ class WebDavXmlUtils:
|
||||||
tree = etree.fromstring(content)
|
tree = etree.fromstring(content)
|
||||||
responses = tree.findall("{DAV:}response")
|
responses = tree.findall("{DAV:}response")
|
||||||
|
|
||||||
def normalization_fn(p):
|
n_path = Urn.normalize_path(path)
|
||||||
result = (sub, '/{2,}', '/')
|
|
||||||
return result if result[-1] != Urn.separate else result[:-1]
|
|
||||||
|
|
||||||
normalized_path = normalization_fn(path)
|
|
||||||
|
|
||||||
for resp in responses:
|
for resp in responses:
|
||||||
href = resp.findtext("{DAV:}href")
|
href = resp.findtext("{DAV:}href")
|
||||||
|
|
||||||
urn = unquote(urlsplit(href).path)
|
if Urn.compare_path(n_path, href) is True:
|
||||||
|
|
||||||
if normalized_path == normalization_fn(urn):
|
|
||||||
return resp
|
return resp
|
||||||
raise RemoteResourceNotFound(path)
|
raise RemoteResourceNotFound(path)
|
||||||
except etree.XMLSyntaxError:
|
except etree.XMLSyntaxError:
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
try:
|
try:
|
||||||
from urllib.parse import unquote, quote
|
from urllib.parse import unquote, quote, urlsplit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib import unquote, quote
|
from urllib import unquote, quote
|
||||||
|
from urlparse import urlsplit
|
||||||
|
|
||||||
from re import sub
|
from re import sub
|
||||||
|
|
||||||
|
@ -53,4 +54,14 @@ class Urn(object):
|
||||||
return self._path.count(Urn.separate, 0, -1)
|
return self._path.count(Urn.separate, 0, -1)
|
||||||
|
|
||||||
def is_dir(self):
|
def is_dir(self):
|
||||||
return self._path[-1] == Urn.separate
|
return self._path[-1] == Urn.separate
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def normalize_path(path):
|
||||||
|
result = sub('/{2,}', '/', path)
|
||||||
|
return result if len(result) < 1 or result[-1] != Urn.separate else result[:-1]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def compare_path(path_a, href):
|
||||||
|
unqouted_path = Urn.separate + unquote(urlsplit(href).path)
|
||||||
|
return Urn.normalize_path(path_a) == Urn.normalize_path(unqouted_path)
|
||||||
|
|
Loading…
Add table
Reference in a new issue