Skip to content

Commit 4fa99eb

Browse files
authored
Merge pull request #11 from cesterlizi/master
pycurl speed & verbose options
2 parents 76f53a1 + 94ffac8 commit 4fa99eb

File tree

6 files changed

+55
-41
lines changed

6 files changed

+55
-41
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pyc
2+
/**/*.pyc

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ options = {
8989
client = wc.Client(options)
9090
```
9191

92+
Other options for pycurl
93+
94+
```python
95+
options = {
96+
'recv_speed' : 3000000,
97+
'send_speed' : 3000000,
98+
'verbose' :True
99+
}
100+
```
101+
102+
recv_speed: rate limit data download speed in Bytes per second. Defaults to unlimited speed.
103+
send_speed: rate limit data upload speed in Bytes per second. Defaults to unlimited speed.
104+
verbose: set verbose mode on/off.
105+
92106
**Synchronous methods**
93107

94108
```python

README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ is defined as follows:
9191
}
9292
client = wc.Client(options)
9393
94+
Other options for pycurl
95+
96+
.. code:: python
97+
98+
options = {
99+
'recv_speed' : 3000000,
100+
'send_speed' : 3000000,
101+
'verbose' :True
102+
}
103+
104+
| *recv_speed: rate limit data download speed in Bytes per second. Defaults to unlimited speed.*
105+
| *send_speed: rate limit data upload speed in Bytes per second. Defaults to unlimited speed.*
106+
| *verbose: set verbose mode on/off.*
107+
|
108+
94109
**Synchronous methods**
95110

96111
.. code:: python

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from setuptools.command.test import test as TestCommand
88
from setuptools.command.install import install as InstallCommand
99

10-
version = "1.0.7"
10+
version = "1.0.8"
1111
requirements = "libxml2-dev libxslt-dev python-dev libcurl4-openssl-dev python-pycurl"
1212

1313
class Install(InstallCommand):

webdav/client.py

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
except ImportError:
1717
from urllib import unquote
1818

19-
__version__ = "1.0.7"
19+
__version__ = "1.0.8"
2020

2121

2222
def listdir(directory):
@@ -71,7 +71,7 @@ class Client(object):
7171
'move': ["Accept: */*"],
7272
'mkdir': ["Accept: */*", "Connection: Keep-Alive"],
7373
'clean': ["Accept: */*", "Connection: Keep-Alive"],
74-
'check': ["Accept: */*", "Depth: 0"],
74+
'check': ["Accept: */*"],
7575
'info': ["Accept: */*", "Depth: 1"],
7676
'get_metadata': ["Accept: */*", "Depth: 1", "Content-Type: application/x-www-form-urlencoded"],
7777
'set_metadata': ["Accept: */*", "Depth: 1", "Content-Type: application/x-www-form-urlencoded"]
@@ -98,7 +98,7 @@ def get_header(self, method):
9898
'move': "MOVE",
9999
'mkdir': "MKCOL",
100100
'clean': "DELETE",
101-
'check': "PROPFIND",
101+
'check': "HEAD",
102102
'list': "PROPFIND",
103103
'free': "PROPFIND",
104104
'info': "PROPFIND",
@@ -164,6 +164,15 @@ def Request(self, options=None):
164164
if self.webdav.key_path:
165165
self.default_options['SSLKEY'] = self.webdav.key_path
166166

167+
if self.webdav.recv_speed:
168+
self.default_options['MAX_RECV_SPEED_LARGE'] = self.webdav.recv_speed
169+
170+
if self.webdav.send_speed:
171+
self.default_options['MAX_SEND_SPEED_LARGE'] = self.webdav.send_speed
172+
173+
if self.webdav.verbose:
174+
self.default_options['VERBOSE'] = self.webdav.verbose
175+
167176
if self.default_options:
168177
add_options(curl, self.default_options)
169178

@@ -266,52 +275,29 @@ def data():
266275

267276
def check(self, remote_path=root):
268277

269-
def parse(response, path):
270-
271-
try:
272-
response_str = response.getvalue()
273-
tree = etree.fromstring(response_str)
274-
275-
resps = tree.findall("{DAV:}response")
276-
277-
for resp in resps:
278-
href = resp.findtext("{DAV:}href")
279-
urn = unquote(href)
280-
281-
if path.endswith(Urn.separate):
282-
if path == urn or path[:-1] == urn:
283-
return True
284-
else:
285-
if path == urn:
286-
return True
287-
288-
return False
289-
290-
except etree.XMLSyntaxError:
291-
return False
292-
293278
try:
294279
urn = Urn(remote_path)
295-
parent_urn = Urn(urn.parent())
296280
response = BytesIO()
297281

298-
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': parent_urn.quote()}
282+
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
299283
options = {
300284
'URL': "{hostname}{root}{path}".format(**url),
301-
'CUSTOMREQUEST': Client.requests['info'],
302-
'HTTPHEADER': self.get_header('info'),
285+
'CUSTOMREQUEST': Client.requests['check'],
286+
'HTTPHEADER': self.get_header('check'),
303287
'WRITEDATA': response,
304-
'NOBODY': 0
288+
'NOBODY': 1
305289
}
306290

307291
request = self.Request(options=options)
308292

309293
request.perform()
294+
code = request.getinfo(pycurl.HTTP_CODE)
310295
request.close()
311296

312-
path = "{root}{path}".format(root=self.webdav.root, path=urn.path())
313-
314-
return parse(response, path)
297+
if int(code) == 200:
298+
return True
299+
300+
return False
315301

316302
except pycurl.error:
317303
raise NotConnection(self.webdav.hostname)
@@ -514,9 +500,6 @@ def upload_file(self, remote_path, local_path, progress=None):
514500
if os.path.isdir(local_path):
515501
raise OptionNotValid(name="local_path", value=local_path)
516502

517-
if not os.path.exists(local_path):
518-
raise LocalResourceNotFound(local_path)
519-
520503
if not self.check(urn.parent()):
521504
raise RemoteParentNotFound(urn.path())
522505

webdav/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class WebDAVSettings(ConnectionSettings):
2121

2222
ns = "webdav:"
2323
prefix = "webdav_"
24-
keys = {'hostname', 'login', 'password', 'token', 'root', 'cert_path', 'key_path'}
24+
keys = {'hostname', 'login', 'password', 'token', 'root', 'cert_path', 'key_path', 'recv_speed', 'send_speed', 'verbose'}
2525

2626
def __init__(self, options):
2727

@@ -78,4 +78,4 @@ def is_valid(self):
7878

7979
if self.login or self.password:
8080
if not self.hostname:
81-
raise OptionNotValid(name="hostname", value=self.hostname, ns=self.ns)
81+
raise OptionNotValid(name="hostname", value=self.hostname, ns=self.ns)

0 commit comments

Comments
 (0)