From d2b91073e1fc499fea67141ff4c17740d25f8e83 Mon Sep 17 00:00:00 2001 From: Mehdy Bohlool Date: Mon, 25 Sep 2017 23:16:48 -0700 Subject: [PATCH] [python] Add default Configuration (#6554) * Add default configuration * Fix assert_hostname bug in rest.py * Update petstore sample --- .../resources/python/configuration.mustache | 17 ++++++++++++++++- .../src/main/resources/python/rest.mustache | 2 +- .../petstore_api/configuration.py | 17 ++++++++++++++++- .../petstore_api/configuration.py | 17 ++++++++++++++++- .../python/petstore_api/configuration.py | 17 ++++++++++++++++- .../client/petstore/python/petstore_api/rest.py | 2 +- 6 files changed, 66 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/configuration.mustache b/modules/swagger-codegen/src/main/resources/python/configuration.mustache index 512e755c24f..744b277455a 100644 --- a/modules/swagger-codegen/src/main/resources/python/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/python/configuration.mustache @@ -6,15 +6,30 @@ from __future__ import absolute_import import urllib3 +import copy import logging import multiprocessing import sys from six import iteritems +from six import with_metaclass from six.moves import http_client as httplib +class TypeWithDefault(type): + def __init__(cls, name, bases, dct): + super(TypeWithDefault, cls).__init__(name, bases, dct) + cls._default = None -class Configuration(object): + def __call__(cls): + if cls._default == None: + cls._default = type.__call__(cls) + return copy.copy(cls._default) + + def set_default(cls, default): + cls._default = copy.copy(default) + + +class Configuration(with_metaclass(TypeWithDefault, object)): """ NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index 49508f77324..aa92c7eba73 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -69,7 +69,7 @@ class RESTClientObject(object): addition_pool_args = {} if configuration.assert_hostname is not None: - addition_pool_args['assert_hostname'] = config.assert_hostname + addition_pool_args['assert_hostname'] = configuration.assert_hostname if maxsize is None: if configuration.connection_pool_maxsize is not None: diff --git a/samples/client/petstore/python-asyncio/petstore_api/configuration.py b/samples/client/petstore/python-asyncio/petstore_api/configuration.py index 9e1fcf24089..29bf22034aa 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/configuration.py +++ b/samples/client/petstore/python-asyncio/petstore_api/configuration.py @@ -15,15 +15,30 @@ from __future__ import absolute_import import urllib3 +import copy import logging import multiprocessing import sys from six import iteritems +from six import with_metaclass from six.moves import http_client as httplib +class TypeWithDefault(type): + def __init__(cls, name, bases, dct): + super(TypeWithDefault, cls).__init__(name, bases, dct) + cls._default = None -class Configuration(object): + def __call__(cls): + if cls._default == None: + cls._default = type.__call__(cls) + return copy.copy(cls._default) + + def set_default(cls, default): + cls._default = copy.copy(default) + + +class Configuration(with_metaclass(TypeWithDefault, object)): """ NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen diff --git a/samples/client/petstore/python-tornado/petstore_api/configuration.py b/samples/client/petstore/python-tornado/petstore_api/configuration.py index 9e1fcf24089..29bf22034aa 100644 --- a/samples/client/petstore/python-tornado/petstore_api/configuration.py +++ b/samples/client/petstore/python-tornado/petstore_api/configuration.py @@ -15,15 +15,30 @@ from __future__ import absolute_import import urllib3 +import copy import logging import multiprocessing import sys from six import iteritems +from six import with_metaclass from six.moves import http_client as httplib +class TypeWithDefault(type): + def __init__(cls, name, bases, dct): + super(TypeWithDefault, cls).__init__(name, bases, dct) + cls._default = None -class Configuration(object): + def __call__(cls): + if cls._default == None: + cls._default = type.__call__(cls) + return copy.copy(cls._default) + + def set_default(cls, default): + cls._default = copy.copy(default) + + +class Configuration(with_metaclass(TypeWithDefault, object)): """ NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen diff --git a/samples/client/petstore/python/petstore_api/configuration.py b/samples/client/petstore/python/petstore_api/configuration.py index 9e1fcf24089..29bf22034aa 100644 --- a/samples/client/petstore/python/petstore_api/configuration.py +++ b/samples/client/petstore/python/petstore_api/configuration.py @@ -15,15 +15,30 @@ from __future__ import absolute_import import urllib3 +import copy import logging import multiprocessing import sys from six import iteritems +from six import with_metaclass from six.moves import http_client as httplib +class TypeWithDefault(type): + def __init__(cls, name, bases, dct): + super(TypeWithDefault, cls).__init__(name, bases, dct) + cls._default = None -class Configuration(object): + def __call__(cls): + if cls._default == None: + cls._default = type.__call__(cls) + return copy.copy(cls._default) + + def set_default(cls, default): + cls._default = copy.copy(default) + + +class Configuration(with_metaclass(TypeWithDefault, object)): """ NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen diff --git a/samples/client/petstore/python/petstore_api/rest.py b/samples/client/petstore/python/petstore_api/rest.py index c0807c2fb19..5a73a2b908c 100644 --- a/samples/client/petstore/python/petstore_api/rest.py +++ b/samples/client/petstore/python/petstore_api/rest.py @@ -78,7 +78,7 @@ class RESTClientObject(object): addition_pool_args = {} if configuration.assert_hostname is not None: - addition_pool_args['assert_hostname'] = config.assert_hostname + addition_pool_args['assert_hostname'] = configuration.assert_hostname if maxsize is None: if configuration.connection_pool_maxsize is not None: