From 2e6284af1b29cb350a49021160c8c3adae0a4c83 Mon Sep 17 00:00:00 2001
From: Jorge
Date: Mon, 30 Sep 2019 19:54:06 +0100
Subject: [PATCH 1/4] [Jorge] Updated to add venv/.idea/build
---
.gitignore | 3 +++
1 file changed, 3 insertions(+)
diff --git a/.gitignore b/.gitignore
index bf2fda7..31720d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,6 @@
.project
.pydevproject
/.settings/
+venv
+.idea
+build
From 8491fdec4c34c6ff615a0e54cdac23562c3f182b Mon Sep 17 00:00:00 2001
From: Jorge
Date: Mon, 30 Sep 2019 19:54:25 +0100
Subject: [PATCH 2/4] [Jorge] Switch to use python sessions rather than
requests
---
README.rst | 17 +++++++++++++++++
webdav3/client.py | 19 ++++++++-----------
webdav3/connection.py | 28 ----------------------------
3 files changed, 25 insertions(+), 39 deletions(-)
diff --git a/README.rst b/README.rst
index e0e2f31..10648c5 100644
--- a/README.rst
+++ b/README.rst
@@ -8,6 +8,23 @@ webdavclient3
Based on https://github.com/designerror/webdav-client-python
But uses `requests` instead of `PyCURL`
+Sample Usage
+____________
+
+>>> from webdav3.client
+>>> options = {
+... webdav_hostname :
+... webdav_login :
+... webdav_password :
+... }
+>>> client = Client(options)
+>>> client.verify = False # To not check SSL certificates (Default = True)
+>>> client.session.proxies(...) # To set proxy directly into the session (Optional)
+>>> client.session.auth(...) # To set proxy auth directly into the session (Optional)
+>>> client.execute_request("mkdir", )
+
+
+
Release Notes
=============
diff --git a/webdav3/client.py b/webdav3/client.py
index 82b26d6..b471dbb 100644
--- a/webdav3/client.py
+++ b/webdav3/client.py
@@ -89,6 +89,9 @@ class Client(object):
# controls whether to verify the server's TLS certificate or not
verify = True
+ # Sets the session for subsequent requests
+ session = requests.Session()
+
# HTTP headers for different actions
http_header = {
'list': ["Accept: */*", "Depth: 1"],
@@ -155,7 +158,7 @@ class Client(object):
the specified action.
:return: HTTP response of request.
"""
- response = requests.request(
+ response = self.session.request(
method=Client.requests[action],
url=self.get_url(path),
auth=(self.webdav.login, self.webdav.password),
@@ -197,7 +200,7 @@ class Client(object):
def __init__(self, options):
"""Constructor of WebDAV client
- :param options: the dictionary of connection options to WebDAV can include proxy server options.
+ :param options: the dictionary of connection options to WebDAV.
WebDev settings:
`webdav_hostname`: url for WebDAV server should contain protocol and ip address or domain name.
Example: `https://webdav.server.com`.
@@ -212,25 +215,19 @@ class Client(object):
`webdav_send_speed`: (optional) rate limit data upload speed in Bytes per second.
Defaults to unlimited speed.
`webdav_verbose`: (optional) set verbose mode on.off. By default verbose mode is off.
- Proxy settings (optional):
- `proxy_hostname`: url to proxy server should contain protocol and ip address or domain name and if needed
- port. Example: `https://proxy.server.com:8383`.
- `proxy_login`: login name for proxy server.
- `proxy_password`: password for proxy server.
+
"""
webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
- proxy_options = get_options(option_type=ProxySettings, from_options=options)
self.webdav = WebDAVSettings(webdav_options)
- self.proxy = ProxySettings(proxy_options)
self.default_options = {}
def valid(self):
- """Validates of WebDAV and proxy settings.
+ """Validates of WebDAV settings.
:return: True in case settings are valid and False otherwise.
"""
- return True if self.webdav.valid() and self.proxy.valid() else False
+ return True if self.webdav.valid() else False
@wrap_connection_error
def list(self, remote_path=root):
diff --git a/webdav3/connection.py b/webdav3/connection.py
index c781797..50becc6 100644
--- a/webdav3/connection.py
+++ b/webdav3/connection.py
@@ -66,31 +66,3 @@ class WebDAVSettings(ConnectionSettings):
if not self.token and not self.login:
raise OptionNotValid(name="login", value=self.login, ns=self.ns)
-
-
-class ProxySettings(ConnectionSettings):
- ns = "proxy:"
- prefix = "proxy_"
- keys = {'hostname', 'login', 'password'}
-
- hostname = None
- login = None
- password = None
-
- def __init__(self, options):
-
- self.options = dict()
-
- for key in self.keys:
- value = options.get(key, '')
- self.options[key] = value
- self.__dict__[key] = value
-
- def is_valid(self):
-
- if self.password and not self.login:
- raise OptionNotValid(name="login", value=self.login, ns=self.ns)
-
- if self.login or self.password:
- if not self.hostname:
- raise OptionNotValid(name="hostname", value=self.hostname, ns=self.ns)
From 3632c2a1e0b40a51839767d533248757ba46bfbf Mon Sep 17 00:00:00 2001
From: Jorge
Date: Mon, 30 Sep 2019 20:41:01 +0100
Subject: [PATCH 3/4] [Jorge] Updated to run a GET with proxy auth as
overridden in subs request
---
webdav3/client.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/webdav3/client.py b/webdav3/client.py
index b471dbb..9d5b55d 100644
--- a/webdav3/client.py
+++ b/webdav3/client.py
@@ -158,6 +158,8 @@ class Client(object):
the specified action.
:return: HTTP response of request.
"""
+ if self.session.auth:
+ self.session.request(method="GET", url=self.webdav.hostname) # (Re)Authenticates against the proxy
response = self.session.request(
method=Client.requests[action],
url=self.get_url(path),
From af85e056bdf0fc73ee8608fd14e418fa8e79922e Mon Sep 17 00:00:00 2001
From: Jorge
Date: Mon, 30 Sep 2019 20:50:14 +0100
Subject: [PATCH 4/4] [Jorge] Updated to add verify to workaround request
---
webdav3/client.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webdav3/client.py b/webdav3/client.py
index 9d5b55d..b62e860 100644
--- a/webdav3/client.py
+++ b/webdav3/client.py
@@ -159,7 +159,7 @@ class Client(object):
:return: HTTP response of request.
"""
if self.session.auth:
- self.session.request(method="GET", url=self.webdav.hostname) # (Re)Authenticates against the proxy
+ self.session.request(method="GET", url=self.webdav.hostname, verify=self.verify) # (Re)Authenticates against the proxy
response = self.session.request(
method=Client.requests[action],
url=self.get_url(path),