Merge pull request #3050 from taxpon/issue-3041

[Python] Follow PEP8 rules ( Issue #3041 )
This commit is contained in:
wing328
2016-06-06 18:18:36 +08:00
68 changed files with 654 additions and 879 deletions

View File

@@ -73,7 +73,6 @@ class {{classname}}(object):
)
params[key] = val
del params['kwargs']
{{#allParams}}
{{#required}}
# verify the required parameter '{{paramName}}' is set
@@ -85,28 +84,27 @@ class {{classname}}(object):
{{#allParams}}
{{#hasValidation}}
{{#maxLength}}
if '{{paramName}}' in params and len(params['{{paramName}}']) > {{maxLength}}:
if '{{paramName}}' in params and len(params['{{paramName}}']) > {{maxLength}}:
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than or equal to `{{maxLength}}`")
{{/maxLength}}
{{#minLength}}
if '{{paramName}}' in params and len(params['{{paramName}}']) < {{minLength}}:
if '{{paramName}}' in params and len(params['{{paramName}}']) < {{minLength}}:
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than or equal to `{{minLength}}`")
{{/minLength}}
{{#maximum}}
if '{{paramName}}' in params and params['{{paramName}}'] > {{maximum}}:
if '{{paramName}}' in params and params['{{paramName}}'] > {{maximum}}:
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than or equal to `{{maximum}}`")
{{/maximum}}
{{#minimum}}
if '{{paramName}}' in params and params['{{paramName}}'] < {{minimum}}:
if '{{paramName}}' in params and params['{{paramName}}'] < {{minimum}}:
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than or equal to `{{minimum}}`")
{{/minimum}}
{{#pattern}}
if '{{paramName}}' in params and not re.search('{{vendorExtensions.x-regex}}', params['{{paramName}}']{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}):
if '{{paramName}}' in params and not re.search('{{vendorExtensions.x-regex}}', params['{{paramName}}']{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}):
raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must conform to the pattern `{{pattern}}`")
{{/pattern}}
{{/hasValidation}}
{{/allParams}}
resource_path = '{{path}}'.replace('{format}', 'json')
path_params = {}
{{#pathParams}}

View File

@@ -191,7 +191,7 @@ class ApiClient(object):
:return: The serialized form of data.
"""
types = (str, int, float, bool, tuple)
if sys.version_info < (3,0):
if sys.version_info < (3, 0):
types = types + (unicode,)
if isinstance(obj, type(None)):
return None

View File

@@ -35,4 +35,4 @@ class {{#operations}}Test{{classname}}(unittest.TestCase):
{{/operations}}
if __name__ == '__main__':
unittest.main()
unittest.main()

View File

@@ -17,6 +17,7 @@ import logging
from six import iteritems
def singleton(cls, *args, **kw):
instances = {}
@@ -59,7 +60,6 @@ class Configuration(object):
# access token for OAuth
self.access_token = ""
{{/isOAuth}}{{/authMethods}}
# Logging Settings
self.logger = {}
self.logger["package_logger"] = logging.getLogger("{{packageName}}")

View File

@@ -36,8 +36,8 @@ class {{classname}}(object):
{{#vars}}
self._{{name}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}
{{/vars}}
{{#vars}}
{{#vars}}{{#-first}}
{{/-first}}
@property
def {{name}}(self):
"""
@@ -58,7 +58,8 @@ class {{classname}}(object):
:param {{name}}: The {{name}} of this {{classname}}.
:type: {{datatype}}
"""
{{#isEnum}}allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
{{#isEnum}}
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
if {{name}} not in allowed_values:
raise ValueError(
"Invalid value for `{{name}}`, must be one of {0}"
@@ -71,23 +72,23 @@ class {{classname}}(object):
if not {{name}}:
raise ValueError("Invalid value for `{{name}}`, must not be `None`")
{{#maxLength}}
if len({{name}}) > {{maxLength}}:
if len({{name}}) > {{maxLength}}:
raise ValueError("Invalid value for `{{name}}`, length must be less than `{{maxLength}}`")
{{/maxLength}}
{{#minLength}}
if len({{name}}) < {{minLength}}:
if len({{name}}) < {{minLength}}:
raise ValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`")
{{/minLength}}
{{#maximum}}
if {{name}} > {{maximum}}:
if {{name}} > {{maximum}}:
raise ValueError("Invalid value for `{{name}}`, must be a value less than or equal to `{{maximum}}`")
{{/maximum}}
{{#minimum}}
if {{name}} < {{minimum}}:
if {{name}} < {{minimum}}:
raise ValueError("Invalid value for `{{name}}`, must be a value greater than or equal to `{{minimum}}`")
{{/minimum}}
{{#pattern}}
if not re.search('{{vendorExtensions.x-regex}}', {{name}}{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}):
if not re.search('{{vendorExtensions.x-regex}}', {{name}}{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}):
raise ValueError("Invalid value for `{{name}}`, must be a follow pattern or equal to `{{pattern}}`")
{{/pattern}}
{{/hasValidation}}
@@ -145,6 +146,5 @@ class {{classname}}(object):
Returns true if both objects are not equal
"""
return not self == other
{{/model}}
{{/models}}
{{/models}}

View File

@@ -34,4 +34,4 @@ class Test{{classname}}(unittest.TestCase):
{{/models}}
if __name__ == '__main__':
unittest.main()
unittest.main()

View File

@@ -10,13 +10,13 @@
{{#version}}OpenAPI spec version: {{{version}}}{{/version}}
{{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
Generated by: https://github.com/swagger-api/swagger-codegen.git
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@@ -7,9 +7,7 @@ from setuptools import setup, find_packages
NAME = "{{packageName}}"
VERSION = "{{packageVersion}}"
{{#apiInfo}}{{#apis}}{{^hasMore}}
# To install the library, run the following
#
# python setup.py install
@@ -33,5 +31,4 @@ setup(
{{appDescription}}
"""
)
{{/hasMore}}{{/apis}}{{/apiInfo}}
{{/hasMore}}{{/apis}}{{/apiInfo}}