Fixed problem when connection lost during request executing and nothing was happened, now it raises an exception.
This commit is contained in:
parent
378afe5890
commit
44ec8fcc66
4 changed files with 35 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
import os.path
|
||||
import shutil
|
||||
import unittest
|
||||
from io import BytesIO, StringIO
|
||||
from os import path
|
||||
from unittest import TestCase
|
||||
|
@ -188,3 +189,7 @@ class ClientTestCase(TestCase):
|
|||
os.mkdir(self.local_path_dir)
|
||||
if not path.exists(path=self.local_path_dir + os.sep + self.local_path_file):
|
||||
shutil.copy(src=self.local_path_file, dst=self.local_path_dir + os.sep + self.local_path_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import unittest
|
||||
from unittest import TestCase
|
||||
|
||||
from lxml.etree import ElementTree, Element
|
||||
|
@ -93,3 +94,7 @@ class ClientTestCase(TestCase):
|
|||
tree = ElementTree(Element('test'))
|
||||
result = utils.etree_to_string(tree)
|
||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<test/>')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -68,10 +68,11 @@ def wrap_connection_error(fn):
|
|||
try:
|
||||
res = fn(self, *args, **kw)
|
||||
except requests.ConnectionError:
|
||||
raise NotConnection(self.webdav.hostname)
|
||||
raise NoConnection(self.webdav.hostname)
|
||||
except requests.RequestException as re:
|
||||
raise ConnectionException(re)
|
||||
else:
|
||||
return res
|
||||
|
||||
return _wrapper
|
||||
|
||||
|
||||
|
@ -84,6 +85,9 @@ class Client(object):
|
|||
# Max size of file for uploading
|
||||
large_size = 2 * 1024 * 1024 * 1024
|
||||
|
||||
# request timeout in seconds
|
||||
timeout = 30
|
||||
|
||||
# HTTP headers for different actions
|
||||
http_header = {
|
||||
'list': ["Accept: */*", "Depth: 1"],
|
||||
|
@ -155,6 +159,7 @@ class Client(object):
|
|||
url=self.get_url(path),
|
||||
auth=(self.webdav.login, self.webdav.password),
|
||||
headers=self.get_headers(action, headers_ext),
|
||||
timeout=self.timeout,
|
||||
data=data
|
||||
)
|
||||
if response.status_code == 507:
|
||||
|
|
|
@ -71,7 +71,15 @@ class MethodNotSupported(WebDavException):
|
|||
return "Method {name} not supported for {server}".format(name=self.name, server=self.server)
|
||||
|
||||
|
||||
class NotConnection(WebDavException):
|
||||
class ConnectionException(WebDavException):
|
||||
def __init__(self, exception):
|
||||
self.exception = exception
|
||||
|
||||
def __str__(self):
|
||||
return self.exception.__str__()
|
||||
|
||||
|
||||
class NoConnection(WebDavException):
|
||||
def __init__(self, hostname):
|
||||
self.hostname = hostname
|
||||
|
||||
|
@ -79,6 +87,15 @@ class NotConnection(WebDavException):
|
|||
return "Not connection with {hostname}".format(hostname=self.hostname)
|
||||
|
||||
|
||||
# This exception left only for supporting original library interface.
|
||||
class NotConnection(WebDavException):
|
||||
def __init__(self, hostname):
|
||||
self.hostname = hostname
|
||||
|
||||
def __str__(self):
|
||||
return "No connection with {hostname}".format(hostname=self.hostname)
|
||||
|
||||
|
||||
class ResponseErrorCode(WebDavException):
|
||||
def __init__(self, url, code, message):
|
||||
self.url = url
|
||||
|
|
Loading…
Add table
Reference in a new issue