From 16fea70db354cffd3e84e850855391b0c9313744 Mon Sep 17 00:00:00 2001 From: alakjana Date: Tue, 27 Sep 2022 15:50:20 +0530 Subject: [PATCH] py lint --- openapiart/common.py | 18 ++++++++++++------ openapiart/generator.py | 26 +++++++++++++++----------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/openapiart/common.py b/openapiart/common.py index 1891b651..563cb6cd 100644 --- a/openapiart/common.py +++ b/openapiart/common.py @@ -13,21 +13,23 @@ except ImportError: from typing_extensions import Literal -#grpc-begin +# grpc-begin import grpc from google.protobuf import json_format import sanity_pb2_grpc as pb2_grpc import sanity_pb2 as pb2 -#grpc-end + +# grpc-end if sys.version_info[0] == 3: unicode = str openapi_warnings = [] -#grpc-begin +# grpc-begin class Transport: HTTP = "http" GRPC = "grpc" + def api( location=None, transport=None, @@ -87,8 +89,10 @@ class send_recv method to communicate with a REST based server. except ImportError as err: msg = "Extension %s is not installed or invalid: %s" raise Exception(msg % (ext, err)) -#grpc-end -#http-begin + + +# grpc-end +# http-begin def api( location=None, verify=True, @@ -132,7 +136,9 @@ class send_recv method to communicate with a REST based server. except ImportError as err: msg = "Extension %s is not installed or invalid: %s" raise Exception(msg % (ext, err)) -#http-end + + +# http-end class HttpTransport(object): def __init__(self, **kwargs): """Use args from api() method to instantiate an HTTP transport""" diff --git a/openapiart/generator.py b/openapiart/generator.py index e7120d2a..11682647 100644 --- a/openapiart/generator.py +++ b/openapiart/generator.py @@ -48,7 +48,7 @@ def __init__( protobuf_package_name, output_dir=None, extension_prefix=None, - py_generate_grpc=True + py_generate_grpc=True, ): self._parsers = {} self._base_url = "" @@ -145,28 +145,32 @@ def generate(self): ) as fp: common_content = fp.read() if self._py_generate_grpc: - grpc_chop = re.compile('#grpc-begin|#grpc-end', re.DOTALL) - common_content = grpc_chop.sub('', common_content) - http_chop = re.compile('#http-begin.*?#http-end', re.DOTALL) - common_content = http_chop.sub('', common_content) + grpc_chop = re.compile("# grpc-begin|# grpc-end", re.DOTALL) + common_content = grpc_chop.sub("", common_content) + http_chop = re.compile("# http-begin.*?# http-end", re.DOTALL) + common_content = http_chop.sub("", common_content) cnf_text = "import sanity_pb2_grpc as pb2_grpc" modify_text = "try:\n from {pkg_name} {text}\nexcept ImportError:\n {text}".format( pkg_name=self._package_name, - text=cnf_text.replace("sanity", self._protobuf_package_name), + text=cnf_text.replace( + "sanity", self._protobuf_package_name + ), ) common_content = common_content.replace(cnf_text, modify_text) cnf_text = "import sanity_pb2 as pb2" modify_text = "try:\n from {pkg_name} {text}\nexcept ImportError:\n {text}".format( pkg_name=self._package_name, - text=cnf_text.replace("sanity", self._protobuf_package_name), + text=cnf_text.replace( + "sanity", self._protobuf_package_name + ), ) common_content = common_content.replace(cnf_text, modify_text) else: - grpc_chop = re.compile('#grpc-begin.*?#grpc-end', re.DOTALL) - common_content = grpc_chop.sub('', common_content) - http_chop = re.compile('#http-begin|#http-end', re.DOTALL) - common_content = http_chop.sub('', common_content) + grpc_chop = re.compile("# grpc-begin.*?# grpc-end", re.DOTALL) + common_content = grpc_chop.sub("", common_content) + http_chop = re.compile("# http-begin|# http-end", re.DOTALL) + common_content = http_chop.sub("", common_content) if re.search(r"def[\s+]api\(", common_content) is not None: self._generated_top_level_factories.append("api")