forked from loafle/openapi-generator-original
better code format for python cilent (#12251)
This commit is contained in:
parent
37905e8bfa
commit
e0d8d0f5d6
@ -173,7 +173,7 @@ class ApiClient(object):
|
|||||||
post_params.extend(self.files_parameters(files))
|
post_params.extend(self.files_parameters(files))
|
||||||
if header_params['Content-Type'].startswith("multipart"):
|
if header_params['Content-Type'].startswith("multipart"):
|
||||||
post_params = self.parameters_to_multipart(post_params,
|
post_params = self.parameters_to_multipart(post_params,
|
||||||
(dict) )
|
(dict))
|
||||||
|
|
||||||
# body
|
# body
|
||||||
if body:
|
if body:
|
||||||
@ -260,13 +260,14 @@ class ApiClient(object):
|
|||||||
if collection_types is None:
|
if collection_types is None:
|
||||||
collection_types = (dict)
|
collection_types = (dict)
|
||||||
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
||||||
if isinstance(v, collection_types): # v is instance of collection_type, formatting as application/json
|
if isinstance(
|
||||||
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
v, collection_types): # v is instance of collection_type, formatting as application/json
|
||||||
field = RequestField(k, v)
|
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
||||||
field.make_multipart(content_type="application/json; charset=utf-8")
|
field = RequestField(k, v)
|
||||||
new_params.append(field)
|
field.make_multipart(content_type="application/json; charset=utf-8")
|
||||||
|
new_params.append(field)
|
||||||
else:
|
else:
|
||||||
new_params.append((k, v))
|
new_params.append((k, v))
|
||||||
return new_params
|
return new_params
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -285,8 +286,10 @@ class ApiClient(object):
|
|||||||
"""
|
"""
|
||||||
if isinstance(obj, (ModelNormal, ModelComposed)):
|
if isinstance(obj, (ModelNormal, ModelComposed)):
|
||||||
return {
|
return {
|
||||||
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
|
key: cls.sanitize_for_serialization(val) for key,
|
||||||
}
|
val in model_to_dict(
|
||||||
|
obj,
|
||||||
|
serialize=True).items()}
|
||||||
elif isinstance(obj, io.IOBase):
|
elif isinstance(obj, io.IOBase):
|
||||||
return cls.get_file_data_and_close_file(obj)
|
return cls.get_file_data_and_close_file(obj)
|
||||||
elif isinstance(obj, (str, int, float, none_type, bool)):
|
elif isinstance(obj, (str, int, float, none_type, bool)):
|
||||||
@ -299,7 +302,9 @@ class ApiClient(object):
|
|||||||
return [cls.sanitize_for_serialization(item) for item in obj]
|
return [cls.sanitize_for_serialization(item) for item in obj]
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
||||||
raise ApiValueError('Unable to prepare type {} for serialization'.format(obj.__class__.__name__))
|
raise ApiValueError(
|
||||||
|
'Unable to prepare type {} for serialization'.format(
|
||||||
|
obj.__class__.__name__))
|
||||||
|
|
||||||
def deserialize(self, response, response_type, _check_type):
|
def deserialize(self, response, response_type, _check_type):
|
||||||
"""Deserializes response into an object.
|
"""Deserializes response into an object.
|
||||||
@ -543,7 +548,9 @@ class ApiClient(object):
|
|||||||
file_instance.close()
|
file_instance.close()
|
||||||
return file_data
|
return file_data
|
||||||
|
|
||||||
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
|
def files_parameters(self,
|
||||||
|
files: typing.Optional[typing.Dict[str,
|
||||||
|
typing.List[io.IOBase]]] = None):
|
||||||
"""Builds form parameters.
|
"""Builds form parameters.
|
||||||
|
|
||||||
:param files: None or a dict with key=param_name and
|
:param files: None or a dict with key=param_name and
|
||||||
@ -634,13 +641,15 @@ class ApiClient(object):
|
|||||||
|
|
||||||
if request_auths:
|
if request_auths:
|
||||||
for auth_setting in request_auths:
|
for auth_setting in request_auths:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
return
|
return
|
||||||
|
|
||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
|
|
||||||
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
||||||
if auth_setting['in'] == 'cookie':
|
if auth_setting['in'] == 'cookie':
|
||||||
@ -654,7 +663,7 @@ class ApiClient(object):
|
|||||||
# that are calculated dynamically.
|
# that are calculated dynamically.
|
||||||
signing_info = self.configuration.signing_info
|
signing_info = self.configuration.signing_info
|
||||||
auth_headers = signing_info.get_http_signature_headers(
|
auth_headers = signing_info.get_http_signature_headers(
|
||||||
resource_path, method, headers, body, queries)
|
resource_path, method, headers, body, queries)
|
||||||
headers.update(auth_headers)
|
headers.update(auth_headers)
|
||||||
{{/hasHttpSignatureMethods}}
|
{{/hasHttpSignatureMethods}}
|
||||||
elif auth_setting['in'] == 'query':
|
elif auth_setting['in'] == 'query':
|
||||||
|
@ -569,9 +569,9 @@ conf = {{{packageName}}}.Configuration(
|
|||||||
]
|
]
|
||||||
{{/-last}}
|
{{/-last}}
|
||||||
{{/enumValues}}
|
{{/enumValues}}
|
||||||
}{{^-last}},{{/-last}}
|
}{{^-last}},{{/-last}}
|
||||||
{{#-last}}
|
{{#-last}}
|
||||||
}
|
}
|
||||||
{{/-last}}
|
{{/-last}}
|
||||||
{{/variables}}
|
{{/variables}}
|
||||||
}{{^-last}},{{/-last}}
|
}{{^-last}},{{/-last}}
|
||||||
|
@ -66,7 +66,8 @@ class RESTClientObject(object):
|
|||||||
maxsize = 4
|
maxsize = 4
|
||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''):
|
if configuration.proxy and not should_bypass_proxies(
|
||||||
|
configuration.host, no_proxy=configuration.no_proxy or ''):
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
maxsize=maxsize,
|
maxsize=maxsize,
|
||||||
@ -139,7 +140,8 @@ class RESTClientObject(object):
|
|||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
if query_params:
|
if query_params:
|
||||||
url += '?' + urlencode(query_params)
|
url += '?' + urlencode(query_params)
|
||||||
if ('Content-Type' not in headers) or (re.search('json', headers['Content-Type'], re.IGNORECASE)):
|
if ('Content-Type' not in headers) or (re.search('json',
|
||||||
|
headers['Content-Type'], re.IGNORECASE)):
|
||||||
request_body = None
|
request_body = None
|
||||||
if body is not None:
|
if body is not None:
|
||||||
request_body = json.dumps(body)
|
request_body = json.dumps(body)
|
||||||
@ -286,6 +288,8 @@ class RESTClientObject(object):
|
|||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
# end of class RESTClientObject
|
# end of class RESTClientObject
|
||||||
|
|
||||||
|
|
||||||
def is_ipv4(target):
|
def is_ipv4(target):
|
||||||
""" Test if IPv4 address or not
|
""" Test if IPv4 address or not
|
||||||
"""
|
"""
|
||||||
@ -295,6 +299,7 @@ def is_ipv4(target):
|
|||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def in_ipv4net(target, net):
|
def in_ipv4net(target, net):
|
||||||
""" Test if target belongs to given IPv4 network
|
""" Test if target belongs to given IPv4 network
|
||||||
"""
|
"""
|
||||||
@ -309,6 +314,7 @@ def in_ipv4net(target, net):
|
|||||||
except ipaddress.NetmaskValueError:
|
except ipaddress.NetmaskValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def should_bypass_proxies(url, no_proxy=None):
|
def should_bypass_proxies(url, no_proxy=None):
|
||||||
""" Yet another requests.should_bypass_proxies
|
""" Yet another requests.should_bypass_proxies
|
||||||
Test if proxies should not be used for a particular url.
|
Test if proxies should not be used for a particular url.
|
||||||
@ -321,12 +327,12 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# special cases
|
# special cases
|
||||||
if no_proxy in [None , '']:
|
if no_proxy in [None, '']:
|
||||||
return False
|
return False
|
||||||
if no_proxy == '*':
|
if no_proxy == '*':
|
||||||
return True
|
return True
|
||||||
|
|
||||||
no_proxy = no_proxy.lower().replace(' ','');
|
no_proxy = no_proxy.lower().replace(' ', '');
|
||||||
entries = (
|
entries = (
|
||||||
host for host in no_proxy.split(',') if host
|
host for host in no_proxy.split(',') if host
|
||||||
)
|
)
|
||||||
@ -335,4 +341,4 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
for item in entries:
|
for item in entries:
|
||||||
if in_ipv4net(parsed.hostname, item):
|
if in_ipv4net(parsed.hostname, item):
|
||||||
return True
|
return True
|
||||||
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} )
|
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy})
|
||||||
|
@ -175,7 +175,7 @@ class ApiClient(object):
|
|||||||
post_params.extend(self.files_parameters(files))
|
post_params.extend(self.files_parameters(files))
|
||||||
if header_params['Content-Type'].startswith("multipart"):
|
if header_params['Content-Type'].startswith("multipart"):
|
||||||
post_params = self.parameters_to_multipart(post_params,
|
post_params = self.parameters_to_multipart(post_params,
|
||||||
(dict) )
|
(dict))
|
||||||
|
|
||||||
# body
|
# body
|
||||||
if body:
|
if body:
|
||||||
@ -248,13 +248,14 @@ class ApiClient(object):
|
|||||||
if collection_types is None:
|
if collection_types is None:
|
||||||
collection_types = (dict)
|
collection_types = (dict)
|
||||||
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
||||||
if isinstance(v, collection_types): # v is instance of collection_type, formatting as application/json
|
if isinstance(
|
||||||
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
v, collection_types): # v is instance of collection_type, formatting as application/json
|
||||||
field = RequestField(k, v)
|
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
||||||
field.make_multipart(content_type="application/json; charset=utf-8")
|
field = RequestField(k, v)
|
||||||
new_params.append(field)
|
field.make_multipart(content_type="application/json; charset=utf-8")
|
||||||
|
new_params.append(field)
|
||||||
else:
|
else:
|
||||||
new_params.append((k, v))
|
new_params.append((k, v))
|
||||||
return new_params
|
return new_params
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -273,8 +274,10 @@ class ApiClient(object):
|
|||||||
"""
|
"""
|
||||||
if isinstance(obj, (ModelNormal, ModelComposed)):
|
if isinstance(obj, (ModelNormal, ModelComposed)):
|
||||||
return {
|
return {
|
||||||
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
|
key: cls.sanitize_for_serialization(val) for key,
|
||||||
}
|
val in model_to_dict(
|
||||||
|
obj,
|
||||||
|
serialize=True).items()}
|
||||||
elif isinstance(obj, io.IOBase):
|
elif isinstance(obj, io.IOBase):
|
||||||
return cls.get_file_data_and_close_file(obj)
|
return cls.get_file_data_and_close_file(obj)
|
||||||
elif isinstance(obj, (str, int, float, none_type, bool)):
|
elif isinstance(obj, (str, int, float, none_type, bool)):
|
||||||
@ -287,7 +290,9 @@ class ApiClient(object):
|
|||||||
return [cls.sanitize_for_serialization(item) for item in obj]
|
return [cls.sanitize_for_serialization(item) for item in obj]
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
||||||
raise ApiValueError('Unable to prepare type {} for serialization'.format(obj.__class__.__name__))
|
raise ApiValueError(
|
||||||
|
'Unable to prepare type {} for serialization'.format(
|
||||||
|
obj.__class__.__name__))
|
||||||
|
|
||||||
def deserialize(self, response, response_type, _check_type):
|
def deserialize(self, response, response_type, _check_type):
|
||||||
"""Deserializes response into an object.
|
"""Deserializes response into an object.
|
||||||
@ -531,7 +536,9 @@ class ApiClient(object):
|
|||||||
file_instance.close()
|
file_instance.close()
|
||||||
return file_data
|
return file_data
|
||||||
|
|
||||||
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
|
def files_parameters(self,
|
||||||
|
files: typing.Optional[typing.Dict[str,
|
||||||
|
typing.List[io.IOBase]]] = None):
|
||||||
"""Builds form parameters.
|
"""Builds form parameters.
|
||||||
|
|
||||||
:param files: None or a dict with key=param_name and
|
:param files: None or a dict with key=param_name and
|
||||||
@ -622,13 +629,15 @@ class ApiClient(object):
|
|||||||
|
|
||||||
if request_auths:
|
if request_auths:
|
||||||
for auth_setting in request_auths:
|
for auth_setting in request_auths:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
return
|
return
|
||||||
|
|
||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
|
|
||||||
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
||||||
if auth_setting['in'] == 'cookie':
|
if auth_setting['in'] == 'cookie':
|
||||||
|
@ -74,7 +74,8 @@ class RESTClientObject(object):
|
|||||||
maxsize = 4
|
maxsize = 4
|
||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''):
|
if configuration.proxy and not should_bypass_proxies(
|
||||||
|
configuration.host, no_proxy=configuration.no_proxy or ''):
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
maxsize=maxsize,
|
maxsize=maxsize,
|
||||||
@ -147,7 +148,8 @@ class RESTClientObject(object):
|
|||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
if query_params:
|
if query_params:
|
||||||
url += '?' + urlencode(query_params)
|
url += '?' + urlencode(query_params)
|
||||||
if ('Content-Type' not in headers) or (re.search('json', headers['Content-Type'], re.IGNORECASE)):
|
if ('Content-Type' not in headers) or (re.search('json',
|
||||||
|
headers['Content-Type'], re.IGNORECASE)):
|
||||||
request_body = None
|
request_body = None
|
||||||
if body is not None:
|
if body is not None:
|
||||||
request_body = json.dumps(body)
|
request_body = json.dumps(body)
|
||||||
@ -294,6 +296,8 @@ class RESTClientObject(object):
|
|||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
# end of class RESTClientObject
|
# end of class RESTClientObject
|
||||||
|
|
||||||
|
|
||||||
def is_ipv4(target):
|
def is_ipv4(target):
|
||||||
""" Test if IPv4 address or not
|
""" Test if IPv4 address or not
|
||||||
"""
|
"""
|
||||||
@ -303,6 +307,7 @@ def is_ipv4(target):
|
|||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def in_ipv4net(target, net):
|
def in_ipv4net(target, net):
|
||||||
""" Test if target belongs to given IPv4 network
|
""" Test if target belongs to given IPv4 network
|
||||||
"""
|
"""
|
||||||
@ -317,6 +322,7 @@ def in_ipv4net(target, net):
|
|||||||
except ipaddress.NetmaskValueError:
|
except ipaddress.NetmaskValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def should_bypass_proxies(url, no_proxy=None):
|
def should_bypass_proxies(url, no_proxy=None):
|
||||||
""" Yet another requests.should_bypass_proxies
|
""" Yet another requests.should_bypass_proxies
|
||||||
Test if proxies should not be used for a particular url.
|
Test if proxies should not be used for a particular url.
|
||||||
@ -329,12 +335,12 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# special cases
|
# special cases
|
||||||
if no_proxy in [None , '']:
|
if no_proxy in [None, '']:
|
||||||
return False
|
return False
|
||||||
if no_proxy == '*':
|
if no_proxy == '*':
|
||||||
return True
|
return True
|
||||||
|
|
||||||
no_proxy = no_proxy.lower().replace(' ','');
|
no_proxy = no_proxy.lower().replace(' ', '');
|
||||||
entries = (
|
entries = (
|
||||||
host for host in no_proxy.split(',') if host
|
host for host in no_proxy.split(',') if host
|
||||||
)
|
)
|
||||||
@ -343,4 +349,4 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
for item in entries:
|
for item in entries:
|
||||||
if in_ipv4net(parsed.hostname, item):
|
if in_ipv4net(parsed.hostname, item):
|
||||||
return True
|
return True
|
||||||
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} )
|
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy})
|
||||||
|
@ -175,7 +175,7 @@ class ApiClient(object):
|
|||||||
post_params.extend(self.files_parameters(files))
|
post_params.extend(self.files_parameters(files))
|
||||||
if header_params['Content-Type'].startswith("multipart"):
|
if header_params['Content-Type'].startswith("multipart"):
|
||||||
post_params = self.parameters_to_multipart(post_params,
|
post_params = self.parameters_to_multipart(post_params,
|
||||||
(dict) )
|
(dict))
|
||||||
|
|
||||||
# body
|
# body
|
||||||
if body:
|
if body:
|
||||||
@ -248,13 +248,14 @@ class ApiClient(object):
|
|||||||
if collection_types is None:
|
if collection_types is None:
|
||||||
collection_types = (dict)
|
collection_types = (dict)
|
||||||
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
||||||
if isinstance(v, collection_types): # v is instance of collection_type, formatting as application/json
|
if isinstance(
|
||||||
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
v, collection_types): # v is instance of collection_type, formatting as application/json
|
||||||
field = RequestField(k, v)
|
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
||||||
field.make_multipart(content_type="application/json; charset=utf-8")
|
field = RequestField(k, v)
|
||||||
new_params.append(field)
|
field.make_multipart(content_type="application/json; charset=utf-8")
|
||||||
|
new_params.append(field)
|
||||||
else:
|
else:
|
||||||
new_params.append((k, v))
|
new_params.append((k, v))
|
||||||
return new_params
|
return new_params
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -273,8 +274,10 @@ class ApiClient(object):
|
|||||||
"""
|
"""
|
||||||
if isinstance(obj, (ModelNormal, ModelComposed)):
|
if isinstance(obj, (ModelNormal, ModelComposed)):
|
||||||
return {
|
return {
|
||||||
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
|
key: cls.sanitize_for_serialization(val) for key,
|
||||||
}
|
val in model_to_dict(
|
||||||
|
obj,
|
||||||
|
serialize=True).items()}
|
||||||
elif isinstance(obj, io.IOBase):
|
elif isinstance(obj, io.IOBase):
|
||||||
return cls.get_file_data_and_close_file(obj)
|
return cls.get_file_data_and_close_file(obj)
|
||||||
elif isinstance(obj, (str, int, float, none_type, bool)):
|
elif isinstance(obj, (str, int, float, none_type, bool)):
|
||||||
@ -287,7 +290,9 @@ class ApiClient(object):
|
|||||||
return [cls.sanitize_for_serialization(item) for item in obj]
|
return [cls.sanitize_for_serialization(item) for item in obj]
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
||||||
raise ApiValueError('Unable to prepare type {} for serialization'.format(obj.__class__.__name__))
|
raise ApiValueError(
|
||||||
|
'Unable to prepare type {} for serialization'.format(
|
||||||
|
obj.__class__.__name__))
|
||||||
|
|
||||||
def deserialize(self, response, response_type, _check_type):
|
def deserialize(self, response, response_type, _check_type):
|
||||||
"""Deserializes response into an object.
|
"""Deserializes response into an object.
|
||||||
@ -531,7 +536,9 @@ class ApiClient(object):
|
|||||||
file_instance.close()
|
file_instance.close()
|
||||||
return file_data
|
return file_data
|
||||||
|
|
||||||
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
|
def files_parameters(self,
|
||||||
|
files: typing.Optional[typing.Dict[str,
|
||||||
|
typing.List[io.IOBase]]] = None):
|
||||||
"""Builds form parameters.
|
"""Builds form parameters.
|
||||||
|
|
||||||
:param files: None or a dict with key=param_name and
|
:param files: None or a dict with key=param_name and
|
||||||
@ -622,13 +629,15 @@ class ApiClient(object):
|
|||||||
|
|
||||||
if request_auths:
|
if request_auths:
|
||||||
for auth_setting in request_auths:
|
for auth_setting in request_auths:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
return
|
return
|
||||||
|
|
||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
|
|
||||||
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
||||||
if auth_setting['in'] == 'cookie':
|
if auth_setting['in'] == 'cookie':
|
||||||
|
@ -74,7 +74,8 @@ class RESTClientObject(object):
|
|||||||
maxsize = 4
|
maxsize = 4
|
||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''):
|
if configuration.proxy and not should_bypass_proxies(
|
||||||
|
configuration.host, no_proxy=configuration.no_proxy or ''):
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
maxsize=maxsize,
|
maxsize=maxsize,
|
||||||
@ -147,7 +148,8 @@ class RESTClientObject(object):
|
|||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
if query_params:
|
if query_params:
|
||||||
url += '?' + urlencode(query_params)
|
url += '?' + urlencode(query_params)
|
||||||
if ('Content-Type' not in headers) or (re.search('json', headers['Content-Type'], re.IGNORECASE)):
|
if ('Content-Type' not in headers) or (re.search('json',
|
||||||
|
headers['Content-Type'], re.IGNORECASE)):
|
||||||
request_body = None
|
request_body = None
|
||||||
if body is not None:
|
if body is not None:
|
||||||
request_body = json.dumps(body)
|
request_body = json.dumps(body)
|
||||||
@ -294,6 +296,8 @@ class RESTClientObject(object):
|
|||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
# end of class RESTClientObject
|
# end of class RESTClientObject
|
||||||
|
|
||||||
|
|
||||||
def is_ipv4(target):
|
def is_ipv4(target):
|
||||||
""" Test if IPv4 address or not
|
""" Test if IPv4 address or not
|
||||||
"""
|
"""
|
||||||
@ -303,6 +307,7 @@ def is_ipv4(target):
|
|||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def in_ipv4net(target, net):
|
def in_ipv4net(target, net):
|
||||||
""" Test if target belongs to given IPv4 network
|
""" Test if target belongs to given IPv4 network
|
||||||
"""
|
"""
|
||||||
@ -317,6 +322,7 @@ def in_ipv4net(target, net):
|
|||||||
except ipaddress.NetmaskValueError:
|
except ipaddress.NetmaskValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def should_bypass_proxies(url, no_proxy=None):
|
def should_bypass_proxies(url, no_proxy=None):
|
||||||
""" Yet another requests.should_bypass_proxies
|
""" Yet another requests.should_bypass_proxies
|
||||||
Test if proxies should not be used for a particular url.
|
Test if proxies should not be used for a particular url.
|
||||||
@ -329,12 +335,12 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# special cases
|
# special cases
|
||||||
if no_proxy in [None , '']:
|
if no_proxy in [None, '']:
|
||||||
return False
|
return False
|
||||||
if no_proxy == '*':
|
if no_proxy == '*':
|
||||||
return True
|
return True
|
||||||
|
|
||||||
no_proxy = no_proxy.lower().replace(' ','');
|
no_proxy = no_proxy.lower().replace(' ', '');
|
||||||
entries = (
|
entries = (
|
||||||
host for host in no_proxy.split(',') if host
|
host for host in no_proxy.split(',') if host
|
||||||
)
|
)
|
||||||
@ -343,4 +349,4 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
for item in entries:
|
for item in entries:
|
||||||
if in_ipv4net(parsed.hostname, item):
|
if in_ipv4net(parsed.hostname, item):
|
||||||
return True
|
return True
|
||||||
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} )
|
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy})
|
||||||
|
@ -175,7 +175,7 @@ class ApiClient(object):
|
|||||||
post_params.extend(self.files_parameters(files))
|
post_params.extend(self.files_parameters(files))
|
||||||
if header_params['Content-Type'].startswith("multipart"):
|
if header_params['Content-Type'].startswith("multipart"):
|
||||||
post_params = self.parameters_to_multipart(post_params,
|
post_params = self.parameters_to_multipart(post_params,
|
||||||
(dict) )
|
(dict))
|
||||||
|
|
||||||
# body
|
# body
|
||||||
if body:
|
if body:
|
||||||
@ -248,13 +248,14 @@ class ApiClient(object):
|
|||||||
if collection_types is None:
|
if collection_types is None:
|
||||||
collection_types = (dict)
|
collection_types = (dict)
|
||||||
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
||||||
if isinstance(v, collection_types): # v is instance of collection_type, formatting as application/json
|
if isinstance(
|
||||||
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
v, collection_types): # v is instance of collection_type, formatting as application/json
|
||||||
field = RequestField(k, v)
|
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
||||||
field.make_multipart(content_type="application/json; charset=utf-8")
|
field = RequestField(k, v)
|
||||||
new_params.append(field)
|
field.make_multipart(content_type="application/json; charset=utf-8")
|
||||||
|
new_params.append(field)
|
||||||
else:
|
else:
|
||||||
new_params.append((k, v))
|
new_params.append((k, v))
|
||||||
return new_params
|
return new_params
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -273,8 +274,10 @@ class ApiClient(object):
|
|||||||
"""
|
"""
|
||||||
if isinstance(obj, (ModelNormal, ModelComposed)):
|
if isinstance(obj, (ModelNormal, ModelComposed)):
|
||||||
return {
|
return {
|
||||||
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
|
key: cls.sanitize_for_serialization(val) for key,
|
||||||
}
|
val in model_to_dict(
|
||||||
|
obj,
|
||||||
|
serialize=True).items()}
|
||||||
elif isinstance(obj, io.IOBase):
|
elif isinstance(obj, io.IOBase):
|
||||||
return cls.get_file_data_and_close_file(obj)
|
return cls.get_file_data_and_close_file(obj)
|
||||||
elif isinstance(obj, (str, int, float, none_type, bool)):
|
elif isinstance(obj, (str, int, float, none_type, bool)):
|
||||||
@ -287,7 +290,9 @@ class ApiClient(object):
|
|||||||
return [cls.sanitize_for_serialization(item) for item in obj]
|
return [cls.sanitize_for_serialization(item) for item in obj]
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
||||||
raise ApiValueError('Unable to prepare type {} for serialization'.format(obj.__class__.__name__))
|
raise ApiValueError(
|
||||||
|
'Unable to prepare type {} for serialization'.format(
|
||||||
|
obj.__class__.__name__))
|
||||||
|
|
||||||
def deserialize(self, response, response_type, _check_type):
|
def deserialize(self, response, response_type, _check_type):
|
||||||
"""Deserializes response into an object.
|
"""Deserializes response into an object.
|
||||||
@ -531,7 +536,9 @@ class ApiClient(object):
|
|||||||
file_instance.close()
|
file_instance.close()
|
||||||
return file_data
|
return file_data
|
||||||
|
|
||||||
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
|
def files_parameters(self,
|
||||||
|
files: typing.Optional[typing.Dict[str,
|
||||||
|
typing.List[io.IOBase]]] = None):
|
||||||
"""Builds form parameters.
|
"""Builds form parameters.
|
||||||
|
|
||||||
:param files: None or a dict with key=param_name and
|
:param files: None or a dict with key=param_name and
|
||||||
@ -622,13 +629,15 @@ class ApiClient(object):
|
|||||||
|
|
||||||
if request_auths:
|
if request_auths:
|
||||||
for auth_setting in request_auths:
|
for auth_setting in request_auths:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
return
|
return
|
||||||
|
|
||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
|
|
||||||
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
||||||
if auth_setting['in'] == 'cookie':
|
if auth_setting['in'] == 'cookie':
|
||||||
|
@ -440,7 +440,7 @@ conf = x_auth_id_alias.Configuration(
|
|||||||
"qa-petstore",
|
"qa-petstore",
|
||||||
"dev-petstore"
|
"dev-petstore"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'port': {
|
'port': {
|
||||||
'description': "No description provided",
|
'description': "No description provided",
|
||||||
'default_value': "80",
|
'default_value': "80",
|
||||||
@ -448,8 +448,8 @@ conf = x_auth_id_alias.Configuration(
|
|||||||
"80",
|
"80",
|
||||||
"8080"
|
"8080"
|
||||||
]
|
]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'url': "https://localhost:8080/{version}",
|
'url': "https://localhost:8080/{version}",
|
||||||
@ -462,8 +462,8 @@ conf = x_auth_id_alias.Configuration(
|
|||||||
"v1",
|
"v1",
|
||||||
"v2"
|
"v2"
|
||||||
]
|
]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ class RESTClientObject(object):
|
|||||||
maxsize = 4
|
maxsize = 4
|
||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''):
|
if configuration.proxy and not should_bypass_proxies(
|
||||||
|
configuration.host, no_proxy=configuration.no_proxy or ''):
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
maxsize=maxsize,
|
maxsize=maxsize,
|
||||||
@ -147,7 +148,8 @@ class RESTClientObject(object):
|
|||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
if query_params:
|
if query_params:
|
||||||
url += '?' + urlencode(query_params)
|
url += '?' + urlencode(query_params)
|
||||||
if ('Content-Type' not in headers) or (re.search('json', headers['Content-Type'], re.IGNORECASE)):
|
if ('Content-Type' not in headers) or (re.search('json',
|
||||||
|
headers['Content-Type'], re.IGNORECASE)):
|
||||||
request_body = None
|
request_body = None
|
||||||
if body is not None:
|
if body is not None:
|
||||||
request_body = json.dumps(body)
|
request_body = json.dumps(body)
|
||||||
@ -294,6 +296,8 @@ class RESTClientObject(object):
|
|||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
# end of class RESTClientObject
|
# end of class RESTClientObject
|
||||||
|
|
||||||
|
|
||||||
def is_ipv4(target):
|
def is_ipv4(target):
|
||||||
""" Test if IPv4 address or not
|
""" Test if IPv4 address or not
|
||||||
"""
|
"""
|
||||||
@ -303,6 +307,7 @@ def is_ipv4(target):
|
|||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def in_ipv4net(target, net):
|
def in_ipv4net(target, net):
|
||||||
""" Test if target belongs to given IPv4 network
|
""" Test if target belongs to given IPv4 network
|
||||||
"""
|
"""
|
||||||
@ -317,6 +322,7 @@ def in_ipv4net(target, net):
|
|||||||
except ipaddress.NetmaskValueError:
|
except ipaddress.NetmaskValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def should_bypass_proxies(url, no_proxy=None):
|
def should_bypass_proxies(url, no_proxy=None):
|
||||||
""" Yet another requests.should_bypass_proxies
|
""" Yet another requests.should_bypass_proxies
|
||||||
Test if proxies should not be used for a particular url.
|
Test if proxies should not be used for a particular url.
|
||||||
@ -329,12 +335,12 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# special cases
|
# special cases
|
||||||
if no_proxy in [None , '']:
|
if no_proxy in [None, '']:
|
||||||
return False
|
return False
|
||||||
if no_proxy == '*':
|
if no_proxy == '*':
|
||||||
return True
|
return True
|
||||||
|
|
||||||
no_proxy = no_proxy.lower().replace(' ','');
|
no_proxy = no_proxy.lower().replace(' ', '');
|
||||||
entries = (
|
entries = (
|
||||||
host for host in no_proxy.split(',') if host
|
host for host in no_proxy.split(',') if host
|
||||||
)
|
)
|
||||||
@ -343,4 +349,4 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
for item in entries:
|
for item in entries:
|
||||||
if in_ipv4net(parsed.hostname, item):
|
if in_ipv4net(parsed.hostname, item):
|
||||||
return True
|
return True
|
||||||
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} )
|
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy})
|
||||||
|
@ -175,7 +175,7 @@ class ApiClient(object):
|
|||||||
post_params.extend(self.files_parameters(files))
|
post_params.extend(self.files_parameters(files))
|
||||||
if header_params['Content-Type'].startswith("multipart"):
|
if header_params['Content-Type'].startswith("multipart"):
|
||||||
post_params = self.parameters_to_multipart(post_params,
|
post_params = self.parameters_to_multipart(post_params,
|
||||||
(dict) )
|
(dict))
|
||||||
|
|
||||||
# body
|
# body
|
||||||
if body:
|
if body:
|
||||||
@ -248,13 +248,14 @@ class ApiClient(object):
|
|||||||
if collection_types is None:
|
if collection_types is None:
|
||||||
collection_types = (dict)
|
collection_types = (dict)
|
||||||
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
||||||
if isinstance(v, collection_types): # v is instance of collection_type, formatting as application/json
|
if isinstance(
|
||||||
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
v, collection_types): # v is instance of collection_type, formatting as application/json
|
||||||
field = RequestField(k, v)
|
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
||||||
field.make_multipart(content_type="application/json; charset=utf-8")
|
field = RequestField(k, v)
|
||||||
new_params.append(field)
|
field.make_multipart(content_type="application/json; charset=utf-8")
|
||||||
|
new_params.append(field)
|
||||||
else:
|
else:
|
||||||
new_params.append((k, v))
|
new_params.append((k, v))
|
||||||
return new_params
|
return new_params
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -273,8 +274,10 @@ class ApiClient(object):
|
|||||||
"""
|
"""
|
||||||
if isinstance(obj, (ModelNormal, ModelComposed)):
|
if isinstance(obj, (ModelNormal, ModelComposed)):
|
||||||
return {
|
return {
|
||||||
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
|
key: cls.sanitize_for_serialization(val) for key,
|
||||||
}
|
val in model_to_dict(
|
||||||
|
obj,
|
||||||
|
serialize=True).items()}
|
||||||
elif isinstance(obj, io.IOBase):
|
elif isinstance(obj, io.IOBase):
|
||||||
return cls.get_file_data_and_close_file(obj)
|
return cls.get_file_data_and_close_file(obj)
|
||||||
elif isinstance(obj, (str, int, float, none_type, bool)):
|
elif isinstance(obj, (str, int, float, none_type, bool)):
|
||||||
@ -287,7 +290,9 @@ class ApiClient(object):
|
|||||||
return [cls.sanitize_for_serialization(item) for item in obj]
|
return [cls.sanitize_for_serialization(item) for item in obj]
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
||||||
raise ApiValueError('Unable to prepare type {} for serialization'.format(obj.__class__.__name__))
|
raise ApiValueError(
|
||||||
|
'Unable to prepare type {} for serialization'.format(
|
||||||
|
obj.__class__.__name__))
|
||||||
|
|
||||||
def deserialize(self, response, response_type, _check_type):
|
def deserialize(self, response, response_type, _check_type):
|
||||||
"""Deserializes response into an object.
|
"""Deserializes response into an object.
|
||||||
@ -531,7 +536,9 @@ class ApiClient(object):
|
|||||||
file_instance.close()
|
file_instance.close()
|
||||||
return file_data
|
return file_data
|
||||||
|
|
||||||
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
|
def files_parameters(self,
|
||||||
|
files: typing.Optional[typing.Dict[str,
|
||||||
|
typing.List[io.IOBase]]] = None):
|
||||||
"""Builds form parameters.
|
"""Builds form parameters.
|
||||||
|
|
||||||
:param files: None or a dict with key=param_name and
|
:param files: None or a dict with key=param_name and
|
||||||
@ -622,13 +629,15 @@ class ApiClient(object):
|
|||||||
|
|
||||||
if request_auths:
|
if request_auths:
|
||||||
for auth_setting in request_auths:
|
for auth_setting in request_auths:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
return
|
return
|
||||||
|
|
||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
|
|
||||||
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
||||||
if auth_setting['in'] == 'cookie':
|
if auth_setting['in'] == 'cookie':
|
||||||
|
@ -401,7 +401,7 @@ class Configuration(object):
|
|||||||
"qa-petstore",
|
"qa-petstore",
|
||||||
"dev-petstore"
|
"dev-petstore"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'port': {
|
'port': {
|
||||||
'description': "No description provided",
|
'description': "No description provided",
|
||||||
'default_value': "80",
|
'default_value': "80",
|
||||||
@ -409,8 +409,8 @@ class Configuration(object):
|
|||||||
"80",
|
"80",
|
||||||
"8080"
|
"8080"
|
||||||
]
|
]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'url': "https://localhost:8080/{version}",
|
'url': "https://localhost:8080/{version}",
|
||||||
@ -424,8 +424,8 @@ class Configuration(object):
|
|||||||
"v2",
|
"v2",
|
||||||
"v3"
|
"v3"
|
||||||
]
|
]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ class RESTClientObject(object):
|
|||||||
maxsize = 4
|
maxsize = 4
|
||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''):
|
if configuration.proxy and not should_bypass_proxies(
|
||||||
|
configuration.host, no_proxy=configuration.no_proxy or ''):
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
maxsize=maxsize,
|
maxsize=maxsize,
|
||||||
@ -147,7 +148,8 @@ class RESTClientObject(object):
|
|||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
if query_params:
|
if query_params:
|
||||||
url += '?' + urlencode(query_params)
|
url += '?' + urlencode(query_params)
|
||||||
if ('Content-Type' not in headers) or (re.search('json', headers['Content-Type'], re.IGNORECASE)):
|
if ('Content-Type' not in headers) or (re.search('json',
|
||||||
|
headers['Content-Type'], re.IGNORECASE)):
|
||||||
request_body = None
|
request_body = None
|
||||||
if body is not None:
|
if body is not None:
|
||||||
request_body = json.dumps(body)
|
request_body = json.dumps(body)
|
||||||
@ -294,6 +296,8 @@ class RESTClientObject(object):
|
|||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
# end of class RESTClientObject
|
# end of class RESTClientObject
|
||||||
|
|
||||||
|
|
||||||
def is_ipv4(target):
|
def is_ipv4(target):
|
||||||
""" Test if IPv4 address or not
|
""" Test if IPv4 address or not
|
||||||
"""
|
"""
|
||||||
@ -303,6 +307,7 @@ def is_ipv4(target):
|
|||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def in_ipv4net(target, net):
|
def in_ipv4net(target, net):
|
||||||
""" Test if target belongs to given IPv4 network
|
""" Test if target belongs to given IPv4 network
|
||||||
"""
|
"""
|
||||||
@ -317,6 +322,7 @@ def in_ipv4net(target, net):
|
|||||||
except ipaddress.NetmaskValueError:
|
except ipaddress.NetmaskValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def should_bypass_proxies(url, no_proxy=None):
|
def should_bypass_proxies(url, no_proxy=None):
|
||||||
""" Yet another requests.should_bypass_proxies
|
""" Yet another requests.should_bypass_proxies
|
||||||
Test if proxies should not be used for a particular url.
|
Test if proxies should not be used for a particular url.
|
||||||
@ -329,12 +335,12 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# special cases
|
# special cases
|
||||||
if no_proxy in [None , '']:
|
if no_proxy in [None, '']:
|
||||||
return False
|
return False
|
||||||
if no_proxy == '*':
|
if no_proxy == '*':
|
||||||
return True
|
return True
|
||||||
|
|
||||||
no_proxy = no_proxy.lower().replace(' ','');
|
no_proxy = no_proxy.lower().replace(' ', '');
|
||||||
entries = (
|
entries = (
|
||||||
host for host in no_proxy.split(',') if host
|
host for host in no_proxy.split(',') if host
|
||||||
)
|
)
|
||||||
@ -343,4 +349,4 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
for item in entries:
|
for item in entries:
|
||||||
if in_ipv4net(parsed.hostname, item):
|
if in_ipv4net(parsed.hostname, item):
|
||||||
return True
|
return True
|
||||||
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} )
|
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy})
|
||||||
|
@ -175,7 +175,7 @@ class ApiClient(object):
|
|||||||
post_params.extend(self.files_parameters(files))
|
post_params.extend(self.files_parameters(files))
|
||||||
if header_params['Content-Type'].startswith("multipart"):
|
if header_params['Content-Type'].startswith("multipart"):
|
||||||
post_params = self.parameters_to_multipart(post_params,
|
post_params = self.parameters_to_multipart(post_params,
|
||||||
(dict) )
|
(dict))
|
||||||
|
|
||||||
# body
|
# body
|
||||||
if body:
|
if body:
|
||||||
@ -248,13 +248,14 @@ class ApiClient(object):
|
|||||||
if collection_types is None:
|
if collection_types is None:
|
||||||
collection_types = (dict)
|
collection_types = (dict)
|
||||||
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
|
||||||
if isinstance(v, collection_types): # v is instance of collection_type, formatting as application/json
|
if isinstance(
|
||||||
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
v, collection_types): # v is instance of collection_type, formatting as application/json
|
||||||
field = RequestField(k, v)
|
v = json.dumps(v, ensure_ascii=False).encode("utf-8")
|
||||||
field.make_multipart(content_type="application/json; charset=utf-8")
|
field = RequestField(k, v)
|
||||||
new_params.append(field)
|
field.make_multipart(content_type="application/json; charset=utf-8")
|
||||||
|
new_params.append(field)
|
||||||
else:
|
else:
|
||||||
new_params.append((k, v))
|
new_params.append((k, v))
|
||||||
return new_params
|
return new_params
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -273,8 +274,10 @@ class ApiClient(object):
|
|||||||
"""
|
"""
|
||||||
if isinstance(obj, (ModelNormal, ModelComposed)):
|
if isinstance(obj, (ModelNormal, ModelComposed)):
|
||||||
return {
|
return {
|
||||||
key: cls.sanitize_for_serialization(val) for key, val in model_to_dict(obj, serialize=True).items()
|
key: cls.sanitize_for_serialization(val) for key,
|
||||||
}
|
val in model_to_dict(
|
||||||
|
obj,
|
||||||
|
serialize=True).items()}
|
||||||
elif isinstance(obj, io.IOBase):
|
elif isinstance(obj, io.IOBase):
|
||||||
return cls.get_file_data_and_close_file(obj)
|
return cls.get_file_data_and_close_file(obj)
|
||||||
elif isinstance(obj, (str, int, float, none_type, bool)):
|
elif isinstance(obj, (str, int, float, none_type, bool)):
|
||||||
@ -287,7 +290,9 @@ class ApiClient(object):
|
|||||||
return [cls.sanitize_for_serialization(item) for item in obj]
|
return [cls.sanitize_for_serialization(item) for item in obj]
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
return {key: cls.sanitize_for_serialization(val) for key, val in obj.items()}
|
||||||
raise ApiValueError('Unable to prepare type {} for serialization'.format(obj.__class__.__name__))
|
raise ApiValueError(
|
||||||
|
'Unable to prepare type {} for serialization'.format(
|
||||||
|
obj.__class__.__name__))
|
||||||
|
|
||||||
def deserialize(self, response, response_type, _check_type):
|
def deserialize(self, response, response_type, _check_type):
|
||||||
"""Deserializes response into an object.
|
"""Deserializes response into an object.
|
||||||
@ -531,7 +536,9 @@ class ApiClient(object):
|
|||||||
file_instance.close()
|
file_instance.close()
|
||||||
return file_data
|
return file_data
|
||||||
|
|
||||||
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
|
def files_parameters(self,
|
||||||
|
files: typing.Optional[typing.Dict[str,
|
||||||
|
typing.List[io.IOBase]]] = None):
|
||||||
"""Builds form parameters.
|
"""Builds form parameters.
|
||||||
|
|
||||||
:param files: None or a dict with key=param_name and
|
:param files: None or a dict with key=param_name and
|
||||||
@ -622,13 +629,15 @@ class ApiClient(object):
|
|||||||
|
|
||||||
if request_auths:
|
if request_auths:
|
||||||
for auth_setting in request_auths:
|
for auth_setting in request_auths:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
return
|
return
|
||||||
|
|
||||||
for auth in auth_settings:
|
for auth in auth_settings:
|
||||||
auth_setting = self.configuration.auth_settings().get(auth)
|
auth_setting = self.configuration.auth_settings().get(auth)
|
||||||
if auth_setting:
|
if auth_setting:
|
||||||
self._apply_auth_params(headers, queries, resource_path, method, body, auth_setting)
|
self._apply_auth_params(
|
||||||
|
headers, queries, resource_path, method, body, auth_setting)
|
||||||
|
|
||||||
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
def _apply_auth_params(self, headers, queries, resource_path, method, body, auth_setting):
|
||||||
if auth_setting['in'] == 'cookie':
|
if auth_setting['in'] == 'cookie':
|
||||||
@ -641,7 +650,7 @@ class ApiClient(object):
|
|||||||
# that are calculated dynamically.
|
# that are calculated dynamically.
|
||||||
signing_info = self.configuration.signing_info
|
signing_info = self.configuration.signing_info
|
||||||
auth_headers = signing_info.get_http_signature_headers(
|
auth_headers = signing_info.get_http_signature_headers(
|
||||||
resource_path, method, headers, body, queries)
|
resource_path, method, headers, body, queries)
|
||||||
headers.update(auth_headers)
|
headers.update(auth_headers)
|
||||||
elif auth_setting['in'] == 'query':
|
elif auth_setting['in'] == 'query':
|
||||||
queries.append((auth_setting['key'], auth_setting['value']))
|
queries.append((auth_setting['key'], auth_setting['value']))
|
||||||
|
@ -535,7 +535,7 @@ conf = petstore_api.Configuration(
|
|||||||
"qa-petstore",
|
"qa-petstore",
|
||||||
"dev-petstore"
|
"dev-petstore"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'port': {
|
'port': {
|
||||||
'description': "No description provided",
|
'description': "No description provided",
|
||||||
'default_value': "80",
|
'default_value': "80",
|
||||||
@ -543,8 +543,8 @@ conf = petstore_api.Configuration(
|
|||||||
"80",
|
"80",
|
||||||
"8080"
|
"8080"
|
||||||
]
|
]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'url': "https://localhost:8080/{version}",
|
'url': "https://localhost:8080/{version}",
|
||||||
@ -557,8 +557,8 @@ conf = petstore_api.Configuration(
|
|||||||
"v1",
|
"v1",
|
||||||
"v2"
|
"v2"
|
||||||
]
|
]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ class RESTClientObject(object):
|
|||||||
maxsize = 4
|
maxsize = 4
|
||||||
|
|
||||||
# https pool manager
|
# https pool manager
|
||||||
if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''):
|
if configuration.proxy and not should_bypass_proxies(
|
||||||
|
configuration.host, no_proxy=configuration.no_proxy or ''):
|
||||||
self.pool_manager = urllib3.ProxyManager(
|
self.pool_manager = urllib3.ProxyManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
maxsize=maxsize,
|
maxsize=maxsize,
|
||||||
@ -147,7 +148,8 @@ class RESTClientObject(object):
|
|||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
if query_params:
|
if query_params:
|
||||||
url += '?' + urlencode(query_params)
|
url += '?' + urlencode(query_params)
|
||||||
if ('Content-Type' not in headers) or (re.search('json', headers['Content-Type'], re.IGNORECASE)):
|
if ('Content-Type' not in headers) or (re.search('json',
|
||||||
|
headers['Content-Type'], re.IGNORECASE)):
|
||||||
request_body = None
|
request_body = None
|
||||||
if body is not None:
|
if body is not None:
|
||||||
request_body = json.dumps(body)
|
request_body = json.dumps(body)
|
||||||
@ -294,6 +296,8 @@ class RESTClientObject(object):
|
|||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
# end of class RESTClientObject
|
# end of class RESTClientObject
|
||||||
|
|
||||||
|
|
||||||
def is_ipv4(target):
|
def is_ipv4(target):
|
||||||
""" Test if IPv4 address or not
|
""" Test if IPv4 address or not
|
||||||
"""
|
"""
|
||||||
@ -303,6 +307,7 @@ def is_ipv4(target):
|
|||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def in_ipv4net(target, net):
|
def in_ipv4net(target, net):
|
||||||
""" Test if target belongs to given IPv4 network
|
""" Test if target belongs to given IPv4 network
|
||||||
"""
|
"""
|
||||||
@ -317,6 +322,7 @@ def in_ipv4net(target, net):
|
|||||||
except ipaddress.NetmaskValueError:
|
except ipaddress.NetmaskValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def should_bypass_proxies(url, no_proxy=None):
|
def should_bypass_proxies(url, no_proxy=None):
|
||||||
""" Yet another requests.should_bypass_proxies
|
""" Yet another requests.should_bypass_proxies
|
||||||
Test if proxies should not be used for a particular url.
|
Test if proxies should not be used for a particular url.
|
||||||
@ -329,12 +335,12 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# special cases
|
# special cases
|
||||||
if no_proxy in [None , '']:
|
if no_proxy in [None, '']:
|
||||||
return False
|
return False
|
||||||
if no_proxy == '*':
|
if no_proxy == '*':
|
||||||
return True
|
return True
|
||||||
|
|
||||||
no_proxy = no_proxy.lower().replace(' ','');
|
no_proxy = no_proxy.lower().replace(' ', '');
|
||||||
entries = (
|
entries = (
|
||||||
host for host in no_proxy.split(',') if host
|
host for host in no_proxy.split(',') if host
|
||||||
)
|
)
|
||||||
@ -343,4 +349,4 @@ def should_bypass_proxies(url, no_proxy=None):
|
|||||||
for item in entries:
|
for item in entries:
|
||||||
if in_ipv4net(parsed.hostname, item):
|
if in_ipv4net(parsed.hostname, item):
|
||||||
return True
|
return True
|
||||||
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} )
|
return proxy_bypass_environment(parsed.hostname, {'no': no_proxy})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user