From dc617d43aa0b08e98c8aaab7e546b22b23e9d78a Mon Sep 17 00:00:00 2001
From: Jorge
Date: Mon, 30 Sep 2019 19:54:06 +0100
Subject: [PATCH 1/5] [Jorge] Updated to add venv/.idea/build
---
.gitignore | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 2af286f..c22e3c6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,5 +6,6 @@
.project
.pydevproject
/.settings/
-.idea/
venv/
+.idea/
+build
From 5a01cbf823c0270f4fd7f3f3c5e8f711a100a81a Mon Sep 17 00:00:00 2001
From: Jorge
Date: Mon, 30 Sep 2019 19:54:25 +0100
Subject: [PATCH 2/5] [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 959f34b..2bb59e8 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
=============
**Version 0.13 – TBD**
diff --git a/webdav3/client.py b/webdav3/client.py
index 5a8324a..ef90a75 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 0f0721554b7eb3c3ecb524249da8110aab0e302b Mon Sep 17 00:00:00 2001
From: Jorge
Date: Mon, 30 Sep 2019 20:41:01 +0100
Subject: [PATCH 3/5] [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 ef90a75..45372fc 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 75a4241201ba4394bd6e19da1882e55702d6670a Mon Sep 17 00:00:00 2001
From: Jorge
Date: Mon, 30 Sep 2019 20:50:14 +0100
Subject: [PATCH 4/5] [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 45372fc..d923bd1 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),
From 7e409f1f1c02b212c71383d4fc02630ef7baf1d6 Mon Sep 17 00:00:00 2001
From: Evgeny Ezhov
Date: Sun, 13 Oct 2019 17:54:45 +0300
Subject: [PATCH 5/5] Update git ignore
---
README.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.rst b/README.rst
index 2bb59e8..6e68a1e 100644
--- a/README.rst
+++ b/README.rst
@@ -29,6 +29,7 @@ Release Notes
=============
**Version 0.13 – TBD**
* Main version of Python is updated up to 3.7
+ * Switch to use python sessions rather than requests by https://github.com/delrey1
**Version 0.12 - 21.06.2019**
* Added depth argument in copy method in client.py by https://github.com/JesperHakansson