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 os.path
|
||||||
import shutil
|
import shutil
|
||||||
|
import unittest
|
||||||
from io import BytesIO, StringIO
|
from io import BytesIO, StringIO
|
||||||
from os import path
|
from os import path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
@ -188,3 +189,7 @@ class ClientTestCase(TestCase):
|
||||||
os.mkdir(self.local_path_dir)
|
os.mkdir(self.local_path_dir)
|
||||||
if not path.exists(path=self.local_path_dir + os.sep + self.local_path_file):
|
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)
|
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 unittest import TestCase
|
||||||
|
|
||||||
from lxml.etree import ElementTree, Element
|
from lxml.etree import ElementTree, Element
|
||||||
|
@ -93,3 +94,7 @@ class ClientTestCase(TestCase):
|
||||||
tree = ElementTree(Element('test'))
|
tree = ElementTree(Element('test'))
|
||||||
result = utils.etree_to_string(tree)
|
result = utils.etree_to_string(tree)
|
||||||
self.assertEquals(result, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<test/>')
|
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:
|
try:
|
||||||
res = fn(self, *args, **kw)
|
res = fn(self, *args, **kw)
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
raise NotConnection(self.webdav.hostname)
|
raise NoConnection(self.webdav.hostname)
|
||||||
|
except requests.RequestException as re:
|
||||||
|
raise ConnectionException(re)
|
||||||
else:
|
else:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
return _wrapper
|
return _wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,6 +85,9 @@ class Client(object):
|
||||||
# Max size of file for uploading
|
# Max size of file for uploading
|
||||||
large_size = 2 * 1024 * 1024 * 1024
|
large_size = 2 * 1024 * 1024 * 1024
|
||||||
|
|
||||||
|
# request timeout in seconds
|
||||||
|
timeout = 30
|
||||||
|
|
||||||
# HTTP headers for different actions
|
# HTTP headers for different actions
|
||||||
http_header = {
|
http_header = {
|
||||||
'list': ["Accept: */*", "Depth: 1"],
|
'list': ["Accept: */*", "Depth: 1"],
|
||||||
|
@ -155,6 +159,7 @@ class Client(object):
|
||||||
url=self.get_url(path),
|
url=self.get_url(path),
|
||||||
auth=(self.webdav.login, self.webdav.password),
|
auth=(self.webdav.login, self.webdav.password),
|
||||||
headers=self.get_headers(action, headers_ext),
|
headers=self.get_headers(action, headers_ext),
|
||||||
|
timeout=self.timeout,
|
||||||
data=data
|
data=data
|
||||||
)
|
)
|
||||||
if response.status_code == 507:
|
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)
|
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):
|
def __init__(self, hostname):
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
|
|
||||||
|
@ -79,6 +87,15 @@ class NotConnection(WebDavException):
|
||||||
return "Not connection with {hostname}".format(hostname=self.hostname)
|
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):
|
class ResponseErrorCode(WebDavException):
|
||||||
def __init__(self, url, code, message):
|
def __init__(self, url, code, message):
|
||||||
self.url = url
|
self.url = url
|
||||||
|
|
Loading…
Add table
Reference in a new issue