diff --git a/easywebdav/client.py b/easywebdav/client.py index 4003198..9c2a689 100644 --- a/easywebdav/client.py +++ b/easywebdav/client.py @@ -31,7 +31,7 @@ def codestr(code): def prop(elem, name, default=None): child = elem.find('.//{DAV:}' + name) - return default if child is None else child.text + return default if child is None or child.text is None else child.text def elem2file(elem): @@ -150,7 +150,7 @@ def delete(self, path): self._send('DELETE', path, 204) def upload(self, local_path_or_fileobj, remote_path): - if isinstance(local_path_or_fileobj, basestring): + if isinstance(local_path_or_fileobj, str): with open(local_path_or_fileobj, 'rb') as f: self._upload(f, remote_path) else: @@ -161,7 +161,7 @@ def _upload(self, fileobj, remote_path): def download(self, remote_path, local_path_or_fileobj): response = self._send('GET', remote_path, 200, stream=True) - if isinstance(local_path_or_fileobj, basestring): + if isinstance(local_path_or_fileobj, str): with open(local_path_or_fileobj, 'wb') as f: self._download(f, response) else: diff --git a/tests/tests.py b/tests/tests.py index 173f9a6..d8d9eb1 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -151,3 +151,13 @@ def test__upload_stream(self): sio.seek(0) self.client.upload(sio, 'file') self._assert_file('file', self.content) + + def test__ls(self): + self._create_dir('one', 'two') + path = self._local_file(self.content) + self.client.upload(path, 'file') + list = self.client.ls() + self.assertSetEqual(set(map( + lambda x : x.replace('http://localhost:28080/', ''), + {entry.name for entry in list})), + {'.', 'one', 'two', 'file'})