mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
[Python] Add support for request timeout (#4173)
* [Python] Add support for request timeout * Update python petstore api * [Python] Add test for request timeout
This commit is contained in:
parent
f6a02f4339
commit
876669cd31
@ -99,6 +99,7 @@ class {{classname}}(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -213,6 +214,7 @@ class {{classname}}(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
@ -96,7 +96,8 @@ class ApiClient(object):
|
|||||||
path_params=None, query_params=None, header_params=None,
|
path_params=None, query_params=None, header_params=None,
|
||||||
body=None, post_params=None, files=None,
|
body=None, post_params=None, files=None,
|
||||||
response_type=None, auth_settings=None, callback=None,
|
response_type=None, auth_settings=None, callback=None,
|
||||||
_return_http_data_only=None, collection_formats=None, _preload_content=True):
|
_return_http_data_only=None, collection_formats=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
|
|
||||||
# header parameters
|
# header parameters
|
||||||
header_params = header_params or {}
|
header_params = header_params or {}
|
||||||
@ -144,7 +145,9 @@ class ApiClient(object):
|
|||||||
response_data = self.request(method, url,
|
response_data = self.request(method, url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=header_params,
|
headers=header_params,
|
||||||
post_params=post_params, body=body, _preload_content=_preload_content)
|
post_params=post_params, body=body,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout)
|
||||||
|
|
||||||
self.last_response = response_data
|
self.last_response = response_data
|
||||||
|
|
||||||
@ -279,7 +282,8 @@ class ApiClient(object):
|
|||||||
path_params=None, query_params=None, header_params=None,
|
path_params=None, query_params=None, header_params=None,
|
||||||
body=None, post_params=None, files=None,
|
body=None, post_params=None, files=None,
|
||||||
response_type=None, auth_settings=None, callback=None,
|
response_type=None, auth_settings=None, callback=None,
|
||||||
_return_http_data_only=None, collection_formats=None, _preload_content=True):
|
_return_http_data_only=None, collection_formats=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
"""
|
"""
|
||||||
Makes the HTTP request (synchronous) and return the deserialized data.
|
Makes the HTTP request (synchronous) and return the deserialized data.
|
||||||
To make an async request, define a function for callback.
|
To make an async request, define a function for callback.
|
||||||
@ -303,21 +307,23 @@ class ApiClient(object):
|
|||||||
:param _return_http_data_only: response data without head status code and headers
|
:param _return_http_data_only: response data without head status code and headers
|
||||||
:param collection_formats: dict of collection formats for path, query,
|
:param collection_formats: dict of collection formats for path, query,
|
||||||
header, and post parameters.
|
header, and post parameters.
|
||||||
|
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
||||||
|
reading/decoding response data. Default is True.
|
||||||
|
:param _request_timeout: timeout setting for this request. If one number provided, it will be total request
|
||||||
|
timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
||||||
:return:
|
:return:
|
||||||
If provide parameter callback,
|
If provide parameter callback,
|
||||||
the request will be called asynchronously.
|
the request will be called asynchronously.
|
||||||
The method will return the request thread.
|
The method will return the request thread.
|
||||||
If parameter callback is None,
|
If parameter callback is None,
|
||||||
then the method will return the response directly.
|
then the method will return the response directly.
|
||||||
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
|
||||||
reading/decoding response data. Default is True.
|
|
||||||
"""
|
"""
|
||||||
if callback is None:
|
if callback is None:
|
||||||
return self.__call_api(resource_path, method,
|
return self.__call_api(resource_path, method,
|
||||||
path_params, query_params, header_params,
|
path_params, query_params, header_params,
|
||||||
body, post_params, files,
|
body, post_params, files,
|
||||||
response_type, auth_settings, callback,
|
response_type, auth_settings, callback,
|
||||||
_return_http_data_only, collection_formats, _preload_content)
|
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
|
||||||
else:
|
else:
|
||||||
thread = threading.Thread(target=self.__call_api,
|
thread = threading.Thread(target=self.__call_api,
|
||||||
args=(resource_path, method,
|
args=(resource_path, method,
|
||||||
@ -326,12 +332,12 @@ class ApiClient(object):
|
|||||||
post_params, files,
|
post_params, files,
|
||||||
response_type, auth_settings,
|
response_type, auth_settings,
|
||||||
callback, _return_http_data_only,
|
callback, _return_http_data_only,
|
||||||
collection_formats, _preload_content))
|
collection_formats, _preload_content, _request_timeout))
|
||||||
thread.start()
|
thread.start()
|
||||||
return thread
|
return thread
|
||||||
|
|
||||||
def request(self, method, url, query_params=None, headers=None,
|
def request(self, method, url, query_params=None, headers=None,
|
||||||
post_params=None, body=None, _preload_content=True):
|
post_params=None, body=None, _preload_content=True, _request_timeout=None):
|
||||||
"""
|
"""
|
||||||
Makes the HTTP request using RESTClient.
|
Makes the HTTP request using RESTClient.
|
||||||
"""
|
"""
|
||||||
@ -339,11 +345,13 @@ class ApiClient(object):
|
|||||||
return self.rest_client.GET(url,
|
return self.rest_client.GET(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif method == "HEAD":
|
elif method == "HEAD":
|
||||||
return self.rest_client.HEAD(url,
|
return self.rest_client.HEAD(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif method == "OPTIONS":
|
elif method == "OPTIONS":
|
||||||
return self.rest_client.OPTIONS(url,
|
return self.rest_client.OPTIONS(url,
|
||||||
@ -351,6 +359,7 @@ class ApiClient(object):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "POST":
|
elif method == "POST":
|
||||||
return self.rest_client.POST(url,
|
return self.rest_client.POST(url,
|
||||||
@ -358,6 +367,7 @@ class ApiClient(object):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "PUT":
|
elif method == "PUT":
|
||||||
return self.rest_client.PUT(url,
|
return self.rest_client.PUT(url,
|
||||||
@ -365,6 +375,7 @@ class ApiClient(object):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "PATCH":
|
elif method == "PATCH":
|
||||||
return self.rest_client.PATCH(url,
|
return self.rest_client.PATCH(url,
|
||||||
@ -372,12 +383,14 @@ class ApiClient(object):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "DELETE":
|
elif method == "DELETE":
|
||||||
return self.rest_client.DELETE(url,
|
return self.rest_client.DELETE(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
@ -85,7 +85,7 @@ class RESTClientObject(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def request(self, method, url, query_params=None, headers=None,
|
def request(self, method, url, query_params=None, headers=None,
|
||||||
body=None, post_params=None, _preload_content=True):
|
body=None, post_params=None, _preload_content=True, _request_timeout=None):
|
||||||
"""
|
"""
|
||||||
:param method: http request method
|
:param method: http request method
|
||||||
:param url: http request url
|
:param url: http request url
|
||||||
@ -97,6 +97,8 @@ class RESTClientObject(object):
|
|||||||
and `multipart/form-data`
|
and `multipart/form-data`
|
||||||
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
||||||
reading/decoding response data. Default is True.
|
reading/decoding response data. Default is True.
|
||||||
|
:param _request_timeout: timeout setting for this request. If one number provided, it will be total request
|
||||||
|
timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
||||||
"""
|
"""
|
||||||
method = method.upper()
|
method = method.upper()
|
||||||
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS']
|
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS']
|
||||||
@ -109,6 +111,13 @@ class RESTClientObject(object):
|
|||||||
post_params = post_params or {}
|
post_params = post_params or {}
|
||||||
headers = headers or {}
|
headers = headers or {}
|
||||||
|
|
||||||
|
timeout = None
|
||||||
|
if _request_timeout:
|
||||||
|
if isinstance(_request_timeout, (int, ) if PY3 else (int, long)):
|
||||||
|
timeout = urllib3.Timeout(total=_request_timeout)
|
||||||
|
elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
|
||||||
|
timeout = urllib3.Timeout(connect=_request_timeout[0], read=_request_timeout[1])
|
||||||
|
|
||||||
if 'Content-Type' not in headers:
|
if 'Content-Type' not in headers:
|
||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
|
|
||||||
@ -124,12 +133,14 @@ class RESTClientObject(object):
|
|||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
body=request_body,
|
body=request_body,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
fields=post_params,
|
fields=post_params,
|
||||||
encode_multipart=False,
|
encode_multipart=False,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif headers['Content-Type'] == 'multipart/form-data':
|
elif headers['Content-Type'] == 'multipart/form-data':
|
||||||
# must del headers['Content-Type'], or the correct Content-Type
|
# must del headers['Content-Type'], or the correct Content-Type
|
||||||
@ -139,6 +150,7 @@ class RESTClientObject(object):
|
|||||||
fields=post_params,
|
fields=post_params,
|
||||||
encode_multipart=True,
|
encode_multipart=True,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
# Pass a `string` parameter directly in the body to support
|
# Pass a `string` parameter directly in the body to support
|
||||||
# other content types than Json when `body` argument is provided
|
# other content types than Json when `body` argument is provided
|
||||||
@ -148,6 +160,7 @@ class RESTClientObject(object):
|
|||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
body=request_body,
|
body=request_body,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
else:
|
else:
|
||||||
# Cannot generate the request from given parameters
|
# Cannot generate the request from given parameters
|
||||||
@ -159,6 +172,7 @@ class RESTClientObject(object):
|
|||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
fields=query_params,
|
fields=query_params,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
except urllib3.exceptions.SSLError as e:
|
except urllib3.exceptions.SSLError as e:
|
||||||
msg = "{0}\n{1}".format(type(e).__name__, str(e))
|
msg = "{0}\n{1}".format(type(e).__name__, str(e))
|
||||||
@ -180,55 +194,66 @@ class RESTClientObject(object):
|
|||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def GET(self, url, headers=None, query_params=None, _preload_content=True):
|
def GET(self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None):
|
||||||
return self.request("GET", url,
|
return self.request("GET", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
query_params=query_params)
|
query_params=query_params)
|
||||||
|
|
||||||
def HEAD(self, url, headers=None, query_params=None, _preload_content=True):
|
def HEAD(self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None):
|
||||||
return self.request("HEAD", url,
|
return self.request("HEAD", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
query_params=query_params)
|
query_params=query_params)
|
||||||
|
|
||||||
def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True):
|
def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("OPTIONS", url,
|
return self.request("OPTIONS", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def DELETE(self, url, headers=None, query_params=None, body=None, _preload_content=True):
|
def DELETE(self, url, headers=None, query_params=None, body=None, _preload_content=True, _request_timeout=None):
|
||||||
return self.request("DELETE", url,
|
return self.request("DELETE", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def POST(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True):
|
def POST(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("POST", url,
|
return self.request("POST", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def PUT(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True):
|
def PUT(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("PUT", url,
|
return self.request("PUT", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def PATCH(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True):
|
def PATCH(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("PATCH", url,
|
return self.request("PATCH", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,7 +96,8 @@ class ApiClient(object):
|
|||||||
path_params=None, query_params=None, header_params=None,
|
path_params=None, query_params=None, header_params=None,
|
||||||
body=None, post_params=None, files=None,
|
body=None, post_params=None, files=None,
|
||||||
response_type=None, auth_settings=None, callback=None,
|
response_type=None, auth_settings=None, callback=None,
|
||||||
_return_http_data_only=None, collection_formats=None, _preload_content=True):
|
_return_http_data_only=None, collection_formats=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
|
|
||||||
# header parameters
|
# header parameters
|
||||||
header_params = header_params or {}
|
header_params = header_params or {}
|
||||||
@ -144,7 +145,9 @@ class ApiClient(object):
|
|||||||
response_data = self.request(method, url,
|
response_data = self.request(method, url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=header_params,
|
headers=header_params,
|
||||||
post_params=post_params, body=body, _preload_content=_preload_content)
|
post_params=post_params, body=body,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout)
|
||||||
|
|
||||||
self.last_response = response_data
|
self.last_response = response_data
|
||||||
|
|
||||||
@ -279,7 +282,8 @@ class ApiClient(object):
|
|||||||
path_params=None, query_params=None, header_params=None,
|
path_params=None, query_params=None, header_params=None,
|
||||||
body=None, post_params=None, files=None,
|
body=None, post_params=None, files=None,
|
||||||
response_type=None, auth_settings=None, callback=None,
|
response_type=None, auth_settings=None, callback=None,
|
||||||
_return_http_data_only=None, collection_formats=None, _preload_content=True):
|
_return_http_data_only=None, collection_formats=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
"""
|
"""
|
||||||
Makes the HTTP request (synchronous) and return the deserialized data.
|
Makes the HTTP request (synchronous) and return the deserialized data.
|
||||||
To make an async request, define a function for callback.
|
To make an async request, define a function for callback.
|
||||||
@ -303,21 +307,23 @@ class ApiClient(object):
|
|||||||
:param _return_http_data_only: response data without head status code and headers
|
:param _return_http_data_only: response data without head status code and headers
|
||||||
:param collection_formats: dict of collection formats for path, query,
|
:param collection_formats: dict of collection formats for path, query,
|
||||||
header, and post parameters.
|
header, and post parameters.
|
||||||
|
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
||||||
|
reading/decoding response data. Default is True.
|
||||||
|
:param _request_timeout: timeout setting for this request. If one number provided, it will be total request
|
||||||
|
timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
||||||
:return:
|
:return:
|
||||||
If provide parameter callback,
|
If provide parameter callback,
|
||||||
the request will be called asynchronously.
|
the request will be called asynchronously.
|
||||||
The method will return the request thread.
|
The method will return the request thread.
|
||||||
If parameter callback is None,
|
If parameter callback is None,
|
||||||
then the method will return the response directly.
|
then the method will return the response directly.
|
||||||
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
|
||||||
reading/decoding response data. Default is True.
|
|
||||||
"""
|
"""
|
||||||
if callback is None:
|
if callback is None:
|
||||||
return self.__call_api(resource_path, method,
|
return self.__call_api(resource_path, method,
|
||||||
path_params, query_params, header_params,
|
path_params, query_params, header_params,
|
||||||
body, post_params, files,
|
body, post_params, files,
|
||||||
response_type, auth_settings, callback,
|
response_type, auth_settings, callback,
|
||||||
_return_http_data_only, collection_formats, _preload_content)
|
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
|
||||||
else:
|
else:
|
||||||
thread = threading.Thread(target=self.__call_api,
|
thread = threading.Thread(target=self.__call_api,
|
||||||
args=(resource_path, method,
|
args=(resource_path, method,
|
||||||
@ -326,12 +332,12 @@ class ApiClient(object):
|
|||||||
post_params, files,
|
post_params, files,
|
||||||
response_type, auth_settings,
|
response_type, auth_settings,
|
||||||
callback, _return_http_data_only,
|
callback, _return_http_data_only,
|
||||||
collection_formats, _preload_content))
|
collection_formats, _preload_content, _request_timeout))
|
||||||
thread.start()
|
thread.start()
|
||||||
return thread
|
return thread
|
||||||
|
|
||||||
def request(self, method, url, query_params=None, headers=None,
|
def request(self, method, url, query_params=None, headers=None,
|
||||||
post_params=None, body=None, _preload_content=True):
|
post_params=None, body=None, _preload_content=True, _request_timeout=None):
|
||||||
"""
|
"""
|
||||||
Makes the HTTP request using RESTClient.
|
Makes the HTTP request using RESTClient.
|
||||||
"""
|
"""
|
||||||
@ -339,11 +345,13 @@ class ApiClient(object):
|
|||||||
return self.rest_client.GET(url,
|
return self.rest_client.GET(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif method == "HEAD":
|
elif method == "HEAD":
|
||||||
return self.rest_client.HEAD(url,
|
return self.rest_client.HEAD(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif method == "OPTIONS":
|
elif method == "OPTIONS":
|
||||||
return self.rest_client.OPTIONS(url,
|
return self.rest_client.OPTIONS(url,
|
||||||
@ -351,6 +359,7 @@ class ApiClient(object):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "POST":
|
elif method == "POST":
|
||||||
return self.rest_client.POST(url,
|
return self.rest_client.POST(url,
|
||||||
@ -358,6 +367,7 @@ class ApiClient(object):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "PUT":
|
elif method == "PUT":
|
||||||
return self.rest_client.PUT(url,
|
return self.rest_client.PUT(url,
|
||||||
@ -365,6 +375,7 @@ class ApiClient(object):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "PATCH":
|
elif method == "PATCH":
|
||||||
return self.rest_client.PATCH(url,
|
return self.rest_client.PATCH(url,
|
||||||
@ -372,12 +383,14 @@ class ApiClient(object):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "DELETE":
|
elif method == "DELETE":
|
||||||
return self.rest_client.DELETE(url,
|
return self.rest_client.DELETE(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
@ -103,6 +103,7 @@ class FakeApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -159,6 +160,7 @@ class FakeApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, **kwargs):
|
def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, **kwargs):
|
||||||
@ -239,6 +241,7 @@ class FakeApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -356,6 +359,7 @@ class FakeApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def test_enum_parameters(self, **kwargs):
|
def test_enum_parameters(self, **kwargs):
|
||||||
@ -424,6 +428,7 @@ class FakeApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -494,4 +499,5 @@ class FakeApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
@ -103,6 +103,7 @@ class PetApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -159,6 +160,7 @@ class PetApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def delete_pet(self, pet_id, **kwargs):
|
def delete_pet(self, pet_id, **kwargs):
|
||||||
@ -215,6 +217,7 @@ class PetApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -273,6 +276,7 @@ class PetApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def find_pets_by_status(self, status, **kwargs):
|
def find_pets_by_status(self, status, **kwargs):
|
||||||
@ -327,6 +331,7 @@ class PetApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -384,6 +389,7 @@ class PetApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def find_pets_by_tags(self, tags, **kwargs):
|
def find_pets_by_tags(self, tags, **kwargs):
|
||||||
@ -438,6 +444,7 @@ class PetApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -495,6 +502,7 @@ class PetApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def get_pet_by_id(self, pet_id, **kwargs):
|
def get_pet_by_id(self, pet_id, **kwargs):
|
||||||
@ -549,6 +557,7 @@ class PetApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -605,6 +614,7 @@ class PetApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def update_pet(self, body, **kwargs):
|
def update_pet(self, body, **kwargs):
|
||||||
@ -659,6 +669,7 @@ class PetApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -715,6 +726,7 @@ class PetApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def update_pet_with_form(self, pet_id, **kwargs):
|
def update_pet_with_form(self, pet_id, **kwargs):
|
||||||
@ -773,6 +785,7 @@ class PetApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -833,6 +846,7 @@ class PetApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def upload_file(self, pet_id, **kwargs):
|
def upload_file(self, pet_id, **kwargs):
|
||||||
@ -891,6 +905,7 @@ class PetApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -951,4 +966,5 @@ class PetApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
@ -103,6 +103,7 @@ class StoreApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -161,6 +162,7 @@ class StoreApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def get_inventory(self, **kwargs):
|
def get_inventory(self, **kwargs):
|
||||||
@ -213,6 +215,7 @@ class StoreApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -264,6 +267,7 @@ class StoreApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def get_order_by_id(self, order_id, **kwargs):
|
def get_order_by_id(self, order_id, **kwargs):
|
||||||
@ -318,6 +322,7 @@ class StoreApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -378,6 +383,7 @@ class StoreApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def place_order(self, body, **kwargs):
|
def place_order(self, body, **kwargs):
|
||||||
@ -432,6 +438,7 @@ class StoreApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -488,4 +495,5 @@ class StoreApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
@ -103,6 +103,7 @@ class UserApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -159,6 +160,7 @@ class UserApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def create_users_with_array_input(self, body, **kwargs):
|
def create_users_with_array_input(self, body, **kwargs):
|
||||||
@ -213,6 +215,7 @@ class UserApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -269,6 +272,7 @@ class UserApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def create_users_with_list_input(self, body, **kwargs):
|
def create_users_with_list_input(self, body, **kwargs):
|
||||||
@ -323,6 +327,7 @@ class UserApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -379,6 +384,7 @@ class UserApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def delete_user(self, username, **kwargs):
|
def delete_user(self, username, **kwargs):
|
||||||
@ -433,6 +439,7 @@ class UserApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -489,6 +496,7 @@ class UserApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def get_user_by_name(self, username, **kwargs):
|
def get_user_by_name(self, username, **kwargs):
|
||||||
@ -543,6 +551,7 @@ class UserApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -599,6 +608,7 @@ class UserApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def login_user(self, username, password, **kwargs):
|
def login_user(self, username, password, **kwargs):
|
||||||
@ -655,6 +665,7 @@ class UserApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -716,6 +727,7 @@ class UserApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def logout_user(self, **kwargs):
|
def logout_user(self, **kwargs):
|
||||||
@ -768,6 +780,7 @@ class UserApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -819,6 +832,7 @@ class UserApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
|
||||||
def update_user(self, username, body, **kwargs):
|
def update_user(self, username, body, **kwargs):
|
||||||
@ -875,6 +889,7 @@ class UserApi(object):
|
|||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
all_params.append('_preload_content')
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -936,4 +951,5 @@ class UserApi(object):
|
|||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
_preload_content=params.get('_preload_content', True),
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
collection_formats=collection_formats)
|
collection_formats=collection_formats)
|
||||||
|
@ -105,7 +105,7 @@ class RESTClientObject(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def request(self, method, url, query_params=None, headers=None,
|
def request(self, method, url, query_params=None, headers=None,
|
||||||
body=None, post_params=None, _preload_content=True):
|
body=None, post_params=None, _preload_content=True, _request_timeout=None):
|
||||||
"""
|
"""
|
||||||
:param method: http request method
|
:param method: http request method
|
||||||
:param url: http request url
|
:param url: http request url
|
||||||
@ -117,6 +117,8 @@ class RESTClientObject(object):
|
|||||||
and `multipart/form-data`
|
and `multipart/form-data`
|
||||||
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
||||||
reading/decoding response data. Default is True.
|
reading/decoding response data. Default is True.
|
||||||
|
:param _request_timeout: timeout setting for this request. If one number provided, it will be total request
|
||||||
|
timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
||||||
"""
|
"""
|
||||||
method = method.upper()
|
method = method.upper()
|
||||||
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS']
|
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS']
|
||||||
@ -129,6 +131,13 @@ class RESTClientObject(object):
|
|||||||
post_params = post_params or {}
|
post_params = post_params or {}
|
||||||
headers = headers or {}
|
headers = headers or {}
|
||||||
|
|
||||||
|
timeout = None
|
||||||
|
if _request_timeout:
|
||||||
|
if isinstance(_request_timeout, (int, ) if PY3 else (int, long)):
|
||||||
|
timeout = urllib3.Timeout(total=_request_timeout)
|
||||||
|
elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
|
||||||
|
timeout = urllib3.Timeout(connect=_request_timeout[0], read=_request_timeout[1])
|
||||||
|
|
||||||
if 'Content-Type' not in headers:
|
if 'Content-Type' not in headers:
|
||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
|
|
||||||
@ -144,12 +153,14 @@ class RESTClientObject(object):
|
|||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
body=request_body,
|
body=request_body,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
fields=post_params,
|
fields=post_params,
|
||||||
encode_multipart=False,
|
encode_multipart=False,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif headers['Content-Type'] == 'multipart/form-data':
|
elif headers['Content-Type'] == 'multipart/form-data':
|
||||||
# must del headers['Content-Type'], or the correct Content-Type
|
# must del headers['Content-Type'], or the correct Content-Type
|
||||||
@ -159,6 +170,7 @@ class RESTClientObject(object):
|
|||||||
fields=post_params,
|
fields=post_params,
|
||||||
encode_multipart=True,
|
encode_multipart=True,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
# Pass a `string` parameter directly in the body to support
|
# Pass a `string` parameter directly in the body to support
|
||||||
# other content types than Json when `body` argument is provided
|
# other content types than Json when `body` argument is provided
|
||||||
@ -168,6 +180,7 @@ class RESTClientObject(object):
|
|||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
body=request_body,
|
body=request_body,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
else:
|
else:
|
||||||
# Cannot generate the request from given parameters
|
# Cannot generate the request from given parameters
|
||||||
@ -179,6 +192,7 @@ class RESTClientObject(object):
|
|||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
fields=query_params,
|
fields=query_params,
|
||||||
preload_content=_preload_content,
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
except urllib3.exceptions.SSLError as e:
|
except urllib3.exceptions.SSLError as e:
|
||||||
msg = "{0}\n{1}".format(type(e).__name__, str(e))
|
msg = "{0}\n{1}".format(type(e).__name__, str(e))
|
||||||
@ -200,55 +214,66 @@ class RESTClientObject(object):
|
|||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def GET(self, url, headers=None, query_params=None, _preload_content=True):
|
def GET(self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None):
|
||||||
return self.request("GET", url,
|
return self.request("GET", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
query_params=query_params)
|
query_params=query_params)
|
||||||
|
|
||||||
def HEAD(self, url, headers=None, query_params=None, _preload_content=True):
|
def HEAD(self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None):
|
||||||
return self.request("HEAD", url,
|
return self.request("HEAD", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
query_params=query_params)
|
query_params=query_params)
|
||||||
|
|
||||||
def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True):
|
def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("OPTIONS", url,
|
return self.request("OPTIONS", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def DELETE(self, url, headers=None, query_params=None, body=None, _preload_content=True):
|
def DELETE(self, url, headers=None, query_params=None, body=None, _preload_content=True, _request_timeout=None):
|
||||||
return self.request("DELETE", url,
|
return self.request("DELETE", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def POST(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True):
|
def POST(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("POST", url,
|
return self.request("POST", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def PUT(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True):
|
def PUT(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("PUT", url,
|
return self.request("PUT", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def PATCH(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True):
|
def PATCH(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("PATCH", url,
|
return self.request("PATCH", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
_preload_content=_preload_content,
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,8 +15,38 @@ from petstore_api.rest import ApiException
|
|||||||
|
|
||||||
from .util import id_gen
|
from .util import id_gen
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
import urllib3
|
||||||
|
|
||||||
HOST = 'http://petstore.swagger.io/v2'
|
HOST = 'http://petstore.swagger.io/v2'
|
||||||
|
|
||||||
|
|
||||||
|
class TimeoutWithEqual(urllib3.Timeout):
|
||||||
|
def __init__(self, *arg, **kwargs):
|
||||||
|
super(TimeoutWithEqual, self).__init__(*arg, **kwargs)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self._read == other._read and self._connect == other._connect and self.total == other.total
|
||||||
|
|
||||||
|
|
||||||
|
class MockPoolManager(object):
|
||||||
|
def __init__(self, tc):
|
||||||
|
self._tc = tc
|
||||||
|
self._reqs = []
|
||||||
|
|
||||||
|
def expect_request(self, *args, **kwargs):
|
||||||
|
self._reqs.append((args, kwargs))
|
||||||
|
|
||||||
|
def request(self, *args, **kwargs):
|
||||||
|
self._tc.assertTrue(len(self._reqs)>0)
|
||||||
|
r = self._reqs.pop(0)
|
||||||
|
self._tc.maxDiff = None
|
||||||
|
self._tc.assertEqual(r[0], args)
|
||||||
|
self._tc.assertEqual(r[1], kwargs)
|
||||||
|
return urllib3.HTTPResponse(status=200, body=b'test')
|
||||||
|
|
||||||
|
|
||||||
class PetApiTests(unittest.TestCase):
|
class PetApiTests(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -65,6 +95,28 @@ class PetApiTests(unittest.TestCase):
|
|||||||
resp.close()
|
resp.close()
|
||||||
resp.release_conn()
|
resp.release_conn()
|
||||||
|
|
||||||
|
def test_timeout(self):
|
||||||
|
mock_pool = MockPoolManager(self)
|
||||||
|
self.api_client.rest_client.pool_manager = mock_pool
|
||||||
|
|
||||||
|
mock_pool.expect_request('POST', 'http://petstore.swagger.io/v2/pet',
|
||||||
|
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
||||||
|
headers={'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'User-Agent': 'Swagger-Codegen/1.0.0/python'},
|
||||||
|
preload_content=True, timeout=TimeoutWithEqual(total=5))
|
||||||
|
mock_pool.expect_request('POST', 'http://petstore.swagger.io/v2/pet',
|
||||||
|
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
|
||||||
|
headers={'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'User-Agent': 'Swagger-Codegen/1.0.0/python'},
|
||||||
|
preload_content=True, timeout=TimeoutWithEqual(connect=1, read=2))
|
||||||
|
|
||||||
|
self.pet_api.add_pet(body=self.pet, _request_timeout=5)
|
||||||
|
self.pet_api.add_pet(body=self.pet, _request_timeout=(1, 2))
|
||||||
|
|
||||||
def test_create_api_instance(self):
|
def test_create_api_instance(self):
|
||||||
pet_api = petstore_api.PetApi()
|
pet_api = petstore_api.PetApi()
|
||||||
pet_api2 = petstore_api.PetApi()
|
pet_api2 = petstore_api.PetApi()
|
||||||
|
Loading…
Reference in New Issue
Block a user