From fc6e185c247324ce7904b827e000e6e20bef0c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 15 Jul 2015 15:21:24 +0200 Subject: [PATCH] allow optional HEADERS when uploading files this allows one to override a given mime-type. e.g. using header={'content-type': 'application/pgp-signature'} allows one to upload a plain-text signature file with the proper mimetype. this is important if some WebDAV servers handle files differently based on the mimetype (e.g. plone) --- easywebdav/client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/easywebdav/client.py b/easywebdav/client.py index 4003198..467cab8 100644 --- a/easywebdav/client.py +++ b/easywebdav/client.py @@ -149,15 +149,15 @@ def rmdir(self, path, safe=False): def delete(self, path): self._send('DELETE', path, 204) - def upload(self, local_path_or_fileobj, remote_path): + def upload(self, local_path_or_fileobj, remote_path, headers=None): if isinstance(local_path_or_fileobj, basestring): with open(local_path_or_fileobj, 'rb') as f: - self._upload(f, remote_path) + self._upload(f, remote_path, headers) else: - self._upload(local_path_or_fileobj, remote_path) + self._upload(local_path_or_fileobj, remote_path, headers) - def _upload(self, fileobj, remote_path): - self._send('PUT', remote_path, (200, 201, 204), data=fileobj) + def _upload(self, fileobj, remote_path, headers): + self._send('PUT', remote_path, (200, 201, 204), data=fileobj, headers=headers) def download(self, remote_path, local_path_or_fileobj): response = self._send('GET', remote_path, 200, stream=True)