Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default argument of prop as deep default #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions easywebdav/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})