Skip to content
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*.pyc
/**/*.pyc
.idea/
tests/__pycache__/
tests/webdav/__pycache__/
webdavclient.egg-info/
29 changes: 22 additions & 7 deletions webdav/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def Request(self, options=None):

if self.webdav.verbose:
self.default_options['VERBOSE'] = self.webdav.verbose

if self.default_options:
add_options(curl, self.default_options)

Expand Down Expand Up @@ -296,7 +296,7 @@ def check(self, remote_path=root):

if int(code) == 200:
return True

return False

except pycurl.error:
Expand Down Expand Up @@ -425,15 +425,24 @@ def download_async(self, remote_path, local_path, callback=None):
target = (lambda: self.download_sync(local_path=local_path, remote_path=remote_path, callback=callback))
threading.Thread(target=target).start()

def upload_from(self, buff, remote_path):
def upload_from(self, buff, remote_path, check_path=True):
'''
Upload file from local buffer
:param buff: instance of BytesIO
:param remote_path: some path on remote WebDAV server.
:param check_path: you can switch off to check parent's directory if your WebDAV server
allows to create intermediate directories sort of nginx:
https://nginx.ru/en/docs/http/ngx_http_dav_module.html#create_full_put_path
:return:
'''

try:
urn = Urn(remote_path)

if urn.is_dir():
raise OptionNotValid(name="remote_path", value=remote_path)

if not self.check(urn.parent()):
if check_path not self.check(urn.parent()):
raise RemoteParentNotFound(urn.path())

url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
Expand Down Expand Up @@ -486,7 +495,13 @@ def upload_directory(self, remote_path, local_path, progress=None):
_local_path = os.path.join(local_path, resource_name)
self.upload(local_path=_local_path, remote_path=_remote_path, progress=progress)

def upload_file(self, remote_path, local_path, progress=None):
def upload_file(self, remote_path, local_path, progress=None, check_path=True):
'''
:param check_path: you can switch off to check parent's directory if your WebDAV server
allows to create intermediate directories sort of nginx:
https://nginx.ru/en/docs/http/ngx_http_dav_module.html#create_full_put_path
:return:
'''

try:
if not os.path.exists(local_path):
Expand All @@ -500,7 +515,7 @@ def upload_file(self, remote_path, local_path, progress=None):
if os.path.isdir(local_path):
raise OptionNotValid(name="local_path", value=local_path)

if not self.check(urn.parent()):
if check_path not self.check(urn.parent()):
raise RemoteParentNotFound(urn.path())

with open(local_path, "rb") as local_file:
Expand Down Expand Up @@ -870,7 +885,7 @@ def parse(response, path):
def resource(self, remote_path):

urn = Urn(remote_path)
return Resource(self, urn.path())
return Resource(self, urn)

def get_property(self, remote_path, option):

Expand Down