Override methods for customizing communication with WebDAV servers.
Fix #31 and #30
This commit is contained in:
parent
95bea2182c
commit
336db8ae19
5 changed files with 31 additions and 8 deletions
23
README.md
23
README.md
|
@ -33,12 +33,12 @@ client.execute_request("mkdir", 'directory_name')
|
|||
Webdav API
|
||||
==========
|
||||
|
||||
Webdav API is a set of webdav methods of work with cloud storage. This set includes the following methods:
|
||||
Webdav API is a set of webdav actions of work with cloud storage. This set includes the following actions:
|
||||
`check`, `free`, `info`, `list`, `mkdir`, `clean`, `copy`, `move`, `download`, `upload`, `publish` and `unpublish`.
|
||||
|
||||
**Configuring the client**
|
||||
|
||||
Required keys for configuring client connection with WevDAV-server are webdav\_hostname and webdav\_login, webdav\_password.
|
||||
Required keys for configuring client connection with WevDAV-server are `webdav_hostname` and `webdav_login`, `webdav_password`.
|
||||
|
||||
```python
|
||||
from webdav3.client import Client
|
||||
|
@ -51,6 +51,25 @@ options = {
|
|||
client = Client(options)
|
||||
```
|
||||
|
||||
If your server does not support `HEAD` method or there are other reasons to override default WebDAV methods for actions use a dictionary option `webdav_override_methods`.
|
||||
The key should be in the following list: `check`, `free`, `info`, `list`, `mkdir`, `clean`, `copy`, `move`, `download`, `upload`,
|
||||
`publish` and `unpublish`. The value should a string name of WebDAV method, for example `GET`.
|
||||
|
||||
```python
|
||||
from webdav3.client import Client
|
||||
|
||||
options = {
|
||||
'webdav_hostname': "https://webdav.server.ru",
|
||||
'webdav_login': "login",
|
||||
'webdav_password': "password",
|
||||
'webdav_override_methods': {
|
||||
'check': 'GET'
|
||||
}
|
||||
|
||||
}
|
||||
client = Client(options)
|
||||
```
|
||||
|
||||
When a proxy server you need to specify settings to connect through it.
|
||||
|
||||
```python
|
||||
|
|
|
@ -21,7 +21,10 @@ class BaseClientTestCase(unittest.TestCase):
|
|||
options = {
|
||||
'webdav_hostname': 'http://localhost:8585',
|
||||
'webdav_login': 'alice',
|
||||
'webdav_password': 'secret1234'
|
||||
'webdav_password': 'secret1234',
|
||||
'webdav_override_methods': {
|
||||
'check': 'GET'
|
||||
}
|
||||
}
|
||||
|
||||
# options = {
|
||||
|
|
|
@ -224,6 +224,9 @@ class ClientTestCase(BaseClientTestCase):
|
|||
def test_valid(self):
|
||||
self.assertTrue(self.client.valid())
|
||||
|
||||
def test_check_is_overridden(self):
|
||||
self.assertEqual('GET', self.client.requests['check'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -153,10 +153,7 @@ class Client(object):
|
|||
webdav_options = get_options(option_type=WebDAVSettings, from_options=options)
|
||||
|
||||
self.webdav = WebDAVSettings(webdav_options)
|
||||
response = self.execute_request('options', '')
|
||||
self.supported_methods = response.headers.get('Allow')
|
||||
if 'HEAD' not in self.supported_methods:
|
||||
self.requests['check'] = 'GET'
|
||||
self.requests.update(self.webdav.override_methods)
|
||||
self.default_options = {}
|
||||
|
||||
def get_headers(self, action, headers_ext=None):
|
||||
|
|
|
@ -25,7 +25,7 @@ class WebDAVSettings(ConnectionSettings):
|
|||
ns = "webdav:"
|
||||
prefix = "webdav_"
|
||||
keys = {'hostname', 'login', 'password', 'token', 'root', 'cert_path', 'key_path', 'recv_speed', 'send_speed',
|
||||
'verbose', 'disable_check'}
|
||||
'verbose', 'disable_check', 'override_methods'}
|
||||
|
||||
hostname = None
|
||||
login = None
|
||||
|
@ -38,6 +38,7 @@ class WebDAVSettings(ConnectionSettings):
|
|||
send_speed = None
|
||||
verbose = None
|
||||
disable_check = False
|
||||
override_methods = {}
|
||||
|
||||
def __init__(self, options):
|
||||
self.options = dict()
|
||||
|
|
Loading…
Add table
Reference in a new issue