From e0d8d0f5d612da35fbe75bcb6b7075fde29bbf9e Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 27 Apr 2022 16:00:44 +0800 Subject: [PATCH] better code format for python cilent (#12251) --- .../main/resources/python/api_client.mustache | 37 ++++++++++++------- .../resources/python/configuration.mustache | 4 +- .../src/main/resources/python/rest.mustache | 16 +++++--- .../python/petstore_api/api_client.py | 35 +++++++++++------- .../petstore/python/petstore_api/rest.py | 16 +++++--- .../petstore_api/api_client.py | 35 +++++++++++------- .../petstore_api/rest.py | 16 +++++--- .../python/x_auth_id_alias/api_client.py | 35 +++++++++++------- .../python/x_auth_id_alias/configuration.py | 6 +-- .../python/x_auth_id_alias/rest.py | 16 +++++--- .../python/dynamic_servers/api_client.py | 35 +++++++++++------- .../python/dynamic_servers/configuration.py | 6 +-- .../python/dynamic_servers/rest.py | 16 +++++--- .../python/petstore_api/api_client.py | 37 ++++++++++++------- .../python/petstore_api/configuration.py | 6 +-- .../petstore/python/petstore_api/rest.py | 16 +++++--- 16 files changed, 211 insertions(+), 121 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/api_client.mustache b/modules/openapi-generator/src/main/resources/python/api_client.mustache index 890e813beee..c7287360744 100644 --- a/modules/openapi-generator/src/main/resources/python/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_client.mustache @@ -173,7 +173,7 @@ class ApiClient(object): post_params.extend(self.files_parameters(files)) if header_params['Content-Type'].startswith("multipart"): post_params = self.parameters_to_multipart(post_params, - (dict) ) + (dict)) # body if body: @@ -260,13 +260,14 @@ class ApiClient(object): if collection_types is None: collection_types = (dict) 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 - v = json.dumps(v, ensure_ascii=False).encode("utf-8") - field = RequestField(k, v) - field.make_multipart(content_type="application/json; charset=utf-8") - new_params.append(field) + if isinstance( + v, collection_types): # v is instance of collection_type, formatting as application/json + v = json.dumps(v, ensure_ascii=False).encode("utf-8") + field = RequestField(k, v) + field.make_multipart(content_type="application/json; charset=utf-8") + new_params.append(field) else: - new_params.append((k, v)) + new_params.append((k, v)) return new_params @classmethod @@ -285,8 +286,10 @@ class ApiClient(object): """ if isinstance(obj, (ModelNormal, ModelComposed)): 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): return cls.get_file_data_and_close_file(obj) 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] if isinstance(obj, dict): 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): """Deserializes response into an object. @@ -543,7 +548,9 @@ class ApiClient(object): file_instance.close() 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. :param files: None or a dict with key=param_name and @@ -634,13 +641,15 @@ class ApiClient(object): if 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 for auth in auth_settings: auth_setting = self.configuration.auth_settings().get(auth) 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): if auth_setting['in'] == 'cookie': @@ -654,7 +663,7 @@ class ApiClient(object): # that are calculated dynamically. signing_info = self.configuration.signing_info auth_headers = signing_info.get_http_signature_headers( - resource_path, method, headers, body, queries) + resource_path, method, headers, body, queries) headers.update(auth_headers) {{/hasHttpSignatureMethods}} elif auth_setting['in'] == 'query': diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index 8e586cf68ce..10513a8f052 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -569,9 +569,9 @@ conf = {{{packageName}}}.Configuration( ] {{/-last}} {{/enumValues}} - }{{^-last}},{{/-last}} + }{{^-last}},{{/-last}} {{#-last}} - } + } {{/-last}} {{/variables}} }{{^-last}},{{/-last}} diff --git a/modules/openapi-generator/src/main/resources/python/rest.mustache b/modules/openapi-generator/src/main/resources/python/rest.mustache index 4740f10fd00..1865fe74da2 100644 --- a/modules/openapi-generator/src/main/resources/python/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/rest.mustache @@ -66,7 +66,8 @@ class RESTClientObject(object): maxsize = 4 # 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( num_pools=pools_size, maxsize=maxsize, @@ -139,7 +140,8 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' if 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 if body is not None: request_body = json.dumps(body) @@ -286,6 +288,8 @@ class RESTClientObject(object): body=body) # end of class RESTClientObject + + def is_ipv4(target): """ Test if IPv4 address or not """ @@ -295,6 +299,7 @@ def is_ipv4(target): except ipaddress.AddressValueError: return False + def in_ipv4net(target, net): """ Test if target belongs to given IPv4 network """ @@ -309,6 +314,7 @@ def in_ipv4net(target, net): except ipaddress.NetmaskValueError: return False + def should_bypass_proxies(url, no_proxy=None): """ Yet another requests.should_bypass_proxies 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 # special cases - if no_proxy in [None , '']: + if no_proxy in [None, '']: return False if no_proxy == '*': return True - no_proxy = no_proxy.lower().replace(' ',''); + no_proxy = no_proxy.lower().replace(' ', ''); entries = ( 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: if in_ipv4net(parsed.hostname, item): return True - return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} ) + return proxy_bypass_environment(parsed.hostname, {'no': no_proxy}) diff --git a/samples/client/petstore/python/petstore_api/api_client.py b/samples/client/petstore/python/petstore_api/api_client.py index e283cf092d7..1614dddbf7d 100644 --- a/samples/client/petstore/python/petstore_api/api_client.py +++ b/samples/client/petstore/python/petstore_api/api_client.py @@ -175,7 +175,7 @@ class ApiClient(object): post_params.extend(self.files_parameters(files)) if header_params['Content-Type'].startswith("multipart"): post_params = self.parameters_to_multipart(post_params, - (dict) ) + (dict)) # body if body: @@ -248,13 +248,14 @@ class ApiClient(object): if collection_types is None: collection_types = (dict) 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 - v = json.dumps(v, ensure_ascii=False).encode("utf-8") - field = RequestField(k, v) - field.make_multipart(content_type="application/json; charset=utf-8") - new_params.append(field) + if isinstance( + v, collection_types): # v is instance of collection_type, formatting as application/json + v = json.dumps(v, ensure_ascii=False).encode("utf-8") + field = RequestField(k, v) + field.make_multipart(content_type="application/json; charset=utf-8") + new_params.append(field) else: - new_params.append((k, v)) + new_params.append((k, v)) return new_params @classmethod @@ -273,8 +274,10 @@ class ApiClient(object): """ if isinstance(obj, (ModelNormal, ModelComposed)): 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): return cls.get_file_data_and_close_file(obj) 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] if isinstance(obj, dict): 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): """Deserializes response into an object. @@ -531,7 +536,9 @@ class ApiClient(object): file_instance.close() 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. :param files: None or a dict with key=param_name and @@ -622,13 +629,15 @@ class ApiClient(object): if 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 for auth in auth_settings: auth_setting = self.configuration.auth_settings().get(auth) 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): if auth_setting['in'] == 'cookie': diff --git a/samples/client/petstore/python/petstore_api/rest.py b/samples/client/petstore/python/petstore_api/rest.py index e264c456aab..8ec610c5cc6 100644 --- a/samples/client/petstore/python/petstore_api/rest.py +++ b/samples/client/petstore/python/petstore_api/rest.py @@ -74,7 +74,8 @@ class RESTClientObject(object): maxsize = 4 # 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( num_pools=pools_size, maxsize=maxsize, @@ -147,7 +148,8 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' if 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 if body is not None: request_body = json.dumps(body) @@ -294,6 +296,8 @@ class RESTClientObject(object): body=body) # end of class RESTClientObject + + def is_ipv4(target): """ Test if IPv4 address or not """ @@ -303,6 +307,7 @@ def is_ipv4(target): except ipaddress.AddressValueError: return False + def in_ipv4net(target, net): """ Test if target belongs to given IPv4 network """ @@ -317,6 +322,7 @@ def in_ipv4net(target, net): except ipaddress.NetmaskValueError: return False + def should_bypass_proxies(url, no_proxy=None): """ Yet another requests.should_bypass_proxies 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 # special cases - if no_proxy in [None , '']: + if no_proxy in [None, '']: return False if no_proxy == '*': return True - no_proxy = no_proxy.lower().replace(' ',''); + no_proxy = no_proxy.lower().replace(' ', ''); entries = ( 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: if in_ipv4net(parsed.hostname, item): return True - return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} ) + return proxy_bypass_environment(parsed.hostname, {'no': no_proxy}) diff --git a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/api_client.py b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/api_client.py index e283cf092d7..1614dddbf7d 100644 --- a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/api_client.py +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/api_client.py @@ -175,7 +175,7 @@ class ApiClient(object): post_params.extend(self.files_parameters(files)) if header_params['Content-Type'].startswith("multipart"): post_params = self.parameters_to_multipart(post_params, - (dict) ) + (dict)) # body if body: @@ -248,13 +248,14 @@ class ApiClient(object): if collection_types is None: collection_types = (dict) 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 - v = json.dumps(v, ensure_ascii=False).encode("utf-8") - field = RequestField(k, v) - field.make_multipart(content_type="application/json; charset=utf-8") - new_params.append(field) + if isinstance( + v, collection_types): # v is instance of collection_type, formatting as application/json + v = json.dumps(v, ensure_ascii=False).encode("utf-8") + field = RequestField(k, v) + field.make_multipart(content_type="application/json; charset=utf-8") + new_params.append(field) else: - new_params.append((k, v)) + new_params.append((k, v)) return new_params @classmethod @@ -273,8 +274,10 @@ class ApiClient(object): """ if isinstance(obj, (ModelNormal, ModelComposed)): 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): return cls.get_file_data_and_close_file(obj) 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] if isinstance(obj, dict): 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): """Deserializes response into an object. @@ -531,7 +536,9 @@ class ApiClient(object): file_instance.close() 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. :param files: None or a dict with key=param_name and @@ -622,13 +629,15 @@ class ApiClient(object): if 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 for auth in auth_settings: auth_setting = self.configuration.auth_settings().get(auth) 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): if auth_setting['in'] == 'cookie': diff --git a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/rest.py b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/rest.py index e264c456aab..8ec610c5cc6 100644 --- a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/rest.py +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/rest.py @@ -74,7 +74,8 @@ class RESTClientObject(object): maxsize = 4 # 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( num_pools=pools_size, maxsize=maxsize, @@ -147,7 +148,8 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' if 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 if body is not None: request_body = json.dumps(body) @@ -294,6 +296,8 @@ class RESTClientObject(object): body=body) # end of class RESTClientObject + + def is_ipv4(target): """ Test if IPv4 address or not """ @@ -303,6 +307,7 @@ def is_ipv4(target): except ipaddress.AddressValueError: return False + def in_ipv4net(target, net): """ Test if target belongs to given IPv4 network """ @@ -317,6 +322,7 @@ def in_ipv4net(target, net): except ipaddress.NetmaskValueError: return False + def should_bypass_proxies(url, no_proxy=None): """ Yet another requests.should_bypass_proxies 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 # special cases - if no_proxy in [None , '']: + if no_proxy in [None, '']: return False if no_proxy == '*': return True - no_proxy = no_proxy.lower().replace(' ',''); + no_proxy = no_proxy.lower().replace(' ', ''); entries = ( 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: if in_ipv4net(parsed.hostname, item): return True - return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} ) + return proxy_bypass_environment(parsed.hostname, {'no': no_proxy}) diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/api_client.py b/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/api_client.py index eb7268814fa..ecabdac2e68 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/api_client.py +++ b/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/api_client.py @@ -175,7 +175,7 @@ class ApiClient(object): post_params.extend(self.files_parameters(files)) if header_params['Content-Type'].startswith("multipart"): post_params = self.parameters_to_multipart(post_params, - (dict) ) + (dict)) # body if body: @@ -248,13 +248,14 @@ class ApiClient(object): if collection_types is None: collection_types = (dict) 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 - v = json.dumps(v, ensure_ascii=False).encode("utf-8") - field = RequestField(k, v) - field.make_multipart(content_type="application/json; charset=utf-8") - new_params.append(field) + if isinstance( + v, collection_types): # v is instance of collection_type, formatting as application/json + v = json.dumps(v, ensure_ascii=False).encode("utf-8") + field = RequestField(k, v) + field.make_multipart(content_type="application/json; charset=utf-8") + new_params.append(field) else: - new_params.append((k, v)) + new_params.append((k, v)) return new_params @classmethod @@ -273,8 +274,10 @@ class ApiClient(object): """ if isinstance(obj, (ModelNormal, ModelComposed)): 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): return cls.get_file_data_and_close_file(obj) 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] if isinstance(obj, dict): 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): """Deserializes response into an object. @@ -531,7 +536,9 @@ class ApiClient(object): file_instance.close() 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. :param files: None or a dict with key=param_name and @@ -622,13 +629,15 @@ class ApiClient(object): if 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 for auth in auth_settings: auth_setting = self.configuration.auth_settings().get(auth) 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): if auth_setting['in'] == 'cookie': diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/configuration.py b/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/configuration.py index d3b86dbde09..2c57fdff92c 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/configuration.py +++ b/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/configuration.py @@ -440,7 +440,7 @@ conf = x_auth_id_alias.Configuration( "qa-petstore", "dev-petstore" ] - }, + }, 'port': { 'description': "No description provided", 'default_value': "80", @@ -448,8 +448,8 @@ conf = x_auth_id_alias.Configuration( "80", "8080" ] - } } + } }, { 'url': "https://localhost:8080/{version}", @@ -462,8 +462,8 @@ conf = x_auth_id_alias.Configuration( "v1", "v2" ] - } } + } } ] diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/rest.py b/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/rest.py index 636f31b19a3..d0ce3593940 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/rest.py +++ b/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/rest.py @@ -74,7 +74,8 @@ class RESTClientObject(object): maxsize = 4 # 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( num_pools=pools_size, maxsize=maxsize, @@ -147,7 +148,8 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' if 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 if body is not None: request_body = json.dumps(body) @@ -294,6 +296,8 @@ class RESTClientObject(object): body=body) # end of class RESTClientObject + + def is_ipv4(target): """ Test if IPv4 address or not """ @@ -303,6 +307,7 @@ def is_ipv4(target): except ipaddress.AddressValueError: return False + def in_ipv4net(target, net): """ Test if target belongs to given IPv4 network """ @@ -317,6 +322,7 @@ def in_ipv4net(target, net): except ipaddress.NetmaskValueError: return False + def should_bypass_proxies(url, no_proxy=None): """ Yet another requests.should_bypass_proxies 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 # special cases - if no_proxy in [None , '']: + if no_proxy in [None, '']: return False if no_proxy == '*': return True - no_proxy = no_proxy.lower().replace(' ',''); + no_proxy = no_proxy.lower().replace(' ', ''); entries = ( 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: if in_ipv4net(parsed.hostname, item): return True - return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} ) + return proxy_bypass_environment(parsed.hostname, {'no': no_proxy}) diff --git a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/api_client.py b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/api_client.py index 61d33ce421c..5e851a65574 100644 --- a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/api_client.py +++ b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/api_client.py @@ -175,7 +175,7 @@ class ApiClient(object): post_params.extend(self.files_parameters(files)) if header_params['Content-Type'].startswith("multipart"): post_params = self.parameters_to_multipart(post_params, - (dict) ) + (dict)) # body if body: @@ -248,13 +248,14 @@ class ApiClient(object): if collection_types is None: collection_types = (dict) 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 - v = json.dumps(v, ensure_ascii=False).encode("utf-8") - field = RequestField(k, v) - field.make_multipart(content_type="application/json; charset=utf-8") - new_params.append(field) + if isinstance( + v, collection_types): # v is instance of collection_type, formatting as application/json + v = json.dumps(v, ensure_ascii=False).encode("utf-8") + field = RequestField(k, v) + field.make_multipart(content_type="application/json; charset=utf-8") + new_params.append(field) else: - new_params.append((k, v)) + new_params.append((k, v)) return new_params @classmethod @@ -273,8 +274,10 @@ class ApiClient(object): """ if isinstance(obj, (ModelNormal, ModelComposed)): 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): return cls.get_file_data_and_close_file(obj) 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] if isinstance(obj, dict): 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): """Deserializes response into an object. @@ -531,7 +536,9 @@ class ApiClient(object): file_instance.close() 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. :param files: None or a dict with key=param_name and @@ -622,13 +629,15 @@ class ApiClient(object): if 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 for auth in auth_settings: auth_setting = self.configuration.auth_settings().get(auth) 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): if auth_setting['in'] == 'cookie': diff --git a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/configuration.py b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/configuration.py index afda4f4fd36..61b3561a826 100644 --- a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/configuration.py +++ b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/configuration.py @@ -401,7 +401,7 @@ class Configuration(object): "qa-petstore", "dev-petstore" ] - }, + }, 'port': { 'description': "No description provided", 'default_value': "80", @@ -409,8 +409,8 @@ class Configuration(object): "80", "8080" ] - } } + } }, { 'url': "https://localhost:8080/{version}", @@ -424,8 +424,8 @@ class Configuration(object): "v2", "v3" ] - } } + } } ] diff --git a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/rest.py b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/rest.py index 2ad59429196..8e5886bb99e 100644 --- a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/rest.py +++ b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/rest.py @@ -74,7 +74,8 @@ class RESTClientObject(object): maxsize = 4 # 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( num_pools=pools_size, maxsize=maxsize, @@ -147,7 +148,8 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' if 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 if body is not None: request_body = json.dumps(body) @@ -294,6 +296,8 @@ class RESTClientObject(object): body=body) # end of class RESTClientObject + + def is_ipv4(target): """ Test if IPv4 address or not """ @@ -303,6 +307,7 @@ def is_ipv4(target): except ipaddress.AddressValueError: return False + def in_ipv4net(target, net): """ Test if target belongs to given IPv4 network """ @@ -317,6 +322,7 @@ def in_ipv4net(target, net): except ipaddress.NetmaskValueError: return False + def should_bypass_proxies(url, no_proxy=None): """ Yet another requests.should_bypass_proxies 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 # special cases - if no_proxy in [None , '']: + if no_proxy in [None, '']: return False if no_proxy == '*': return True - no_proxy = no_proxy.lower().replace(' ',''); + no_proxy = no_proxy.lower().replace(' ', ''); entries = ( 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: if in_ipv4net(parsed.hostname, item): return True - return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} ) + return proxy_bypass_environment(parsed.hostname, {'no': no_proxy}) diff --git a/samples/openapi3/client/petstore/python/petstore_api/api_client.py b/samples/openapi3/client/petstore/python/petstore_api/api_client.py index eb1abcf5cc3..a3ea0bc5d0f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -175,7 +175,7 @@ class ApiClient(object): post_params.extend(self.files_parameters(files)) if header_params['Content-Type'].startswith("multipart"): post_params = self.parameters_to_multipart(post_params, - (dict) ) + (dict)) # body if body: @@ -248,13 +248,14 @@ class ApiClient(object): if collection_types is None: collection_types = (dict) 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 - v = json.dumps(v, ensure_ascii=False).encode("utf-8") - field = RequestField(k, v) - field.make_multipart(content_type="application/json; charset=utf-8") - new_params.append(field) + if isinstance( + v, collection_types): # v is instance of collection_type, formatting as application/json + v = json.dumps(v, ensure_ascii=False).encode("utf-8") + field = RequestField(k, v) + field.make_multipart(content_type="application/json; charset=utf-8") + new_params.append(field) else: - new_params.append((k, v)) + new_params.append((k, v)) return new_params @classmethod @@ -273,8 +274,10 @@ class ApiClient(object): """ if isinstance(obj, (ModelNormal, ModelComposed)): 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): return cls.get_file_data_and_close_file(obj) 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] if isinstance(obj, dict): 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): """Deserializes response into an object. @@ -531,7 +536,9 @@ class ApiClient(object): file_instance.close() 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. :param files: None or a dict with key=param_name and @@ -622,13 +629,15 @@ class ApiClient(object): if 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 for auth in auth_settings: auth_setting = self.configuration.auth_settings().get(auth) 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): if auth_setting['in'] == 'cookie': @@ -641,7 +650,7 @@ class ApiClient(object): # that are calculated dynamically. signing_info = self.configuration.signing_info auth_headers = signing_info.get_http_signature_headers( - resource_path, method, headers, body, queries) + resource_path, method, headers, body, queries) headers.update(auth_headers) elif auth_setting['in'] == 'query': queries.append((auth_setting['key'], auth_setting['value'])) diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index 44b3f666ac2..0c4db4c52af 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -535,7 +535,7 @@ conf = petstore_api.Configuration( "qa-petstore", "dev-petstore" ] - }, + }, 'port': { 'description': "No description provided", 'default_value': "80", @@ -543,8 +543,8 @@ conf = petstore_api.Configuration( "80", "8080" ] - } } + } }, { 'url': "https://localhost:8080/{version}", @@ -557,8 +557,8 @@ conf = petstore_api.Configuration( "v1", "v2" ] - } } + } } ] diff --git a/samples/openapi3/client/petstore/python/petstore_api/rest.py b/samples/openapi3/client/petstore/python/petstore_api/rest.py index e264c456aab..8ec610c5cc6 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/rest.py +++ b/samples/openapi3/client/petstore/python/petstore_api/rest.py @@ -74,7 +74,8 @@ class RESTClientObject(object): maxsize = 4 # 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( num_pools=pools_size, maxsize=maxsize, @@ -147,7 +148,8 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' if 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 if body is not None: request_body = json.dumps(body) @@ -294,6 +296,8 @@ class RESTClientObject(object): body=body) # end of class RESTClientObject + + def is_ipv4(target): """ Test if IPv4 address or not """ @@ -303,6 +307,7 @@ def is_ipv4(target): except ipaddress.AddressValueError: return False + def in_ipv4net(target, net): """ Test if target belongs to given IPv4 network """ @@ -317,6 +322,7 @@ def in_ipv4net(target, net): except ipaddress.NetmaskValueError: return False + def should_bypass_proxies(url, no_proxy=None): """ Yet another requests.should_bypass_proxies 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 # special cases - if no_proxy in [None , '']: + if no_proxy in [None, '']: return False if no_proxy == '*': return True - no_proxy = no_proxy.lower().replace(' ',''); + no_proxy = no_proxy.lower().replace(' ', ''); entries = ( 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: if in_ipv4net(parsed.hostname, item): return True - return proxy_bypass_environment(parsed.hostname, {'no': no_proxy} ) + return proxy_bypass_environment(parsed.hostname, {'no': no_proxy})