mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 19:33:55 +00:00
Revert "Revert "[Python] Fix issue in python client""
This reverts commit c59e2b88b1
.
This commit is contained in:
parent
ed13d7b1b8
commit
a26cf60a22
@ -25,6 +25,7 @@ from .rest import ApiException
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import urllib
|
import urllib
|
||||||
import json
|
import json
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
@ -15,7 +15,7 @@ Copyright 2015 SmartBear Software
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
ref: https://github.com/swagger-api/swagger-codegen
|
ref: https://github.com/swagger-api/swagger-codegen
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
@ -27,10 +27,11 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
# for python3
|
# for python3
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from six import iteritems
|
||||||
|
|
||||||
def singleton(cls, *args, **kw):
|
def singleton(cls, *args, **kw):
|
||||||
instances = {}
|
instances = {}
|
||||||
@ -72,36 +73,23 @@ class Configuration(object):
|
|||||||
self.password = ""
|
self.password = ""
|
||||||
|
|
||||||
# Logging Settings
|
# Logging Settings
|
||||||
|
self.logger = {}
|
||||||
|
self.logger["package_logger"] = logging.getLogger("{{packageName}}")
|
||||||
|
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
|
||||||
|
# Log format
|
||||||
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
|
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
|
||||||
# Debug file location
|
# Debug file location
|
||||||
self.__logging_file = None
|
self.logging_stream_handler = None
|
||||||
|
self.logging_file_handler = None
|
||||||
|
self.logging_file = None
|
||||||
# Debug switch
|
# Debug switch
|
||||||
self.__debug = False
|
self.debug = False
|
||||||
self.init_logger()
|
|
||||||
|
|
||||||
# SSL/TLS verification
|
# SSL/TLS verification
|
||||||
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
||||||
self.verify_ssl = True
|
self.verify_ssl = True
|
||||||
# Set this to customize the certificate file to verify the peer.
|
# Set this to customize the certificate file to verify the peer.
|
||||||
self.ssl_ca_cert = None
|
self.ssl_ca_cert = None
|
||||||
|
|
||||||
def init_logger(self):
|
|
||||||
"""
|
|
||||||
Initializes logger settings.
|
|
||||||
"""
|
|
||||||
self.logger = logging.getLogger()
|
|
||||||
formatter = logging.Formatter(self.logging_format)
|
|
||||||
stream_handler = logging.StreamHandler()
|
|
||||||
stream_handler.setFormatter(formatter)
|
|
||||||
self.logger.addHandler(stream_handler)
|
|
||||||
if self.__debug:
|
|
||||||
self.logger.setLevel(logging.DEBUG)
|
|
||||||
else:
|
|
||||||
self.logger.setLevel(logging.WARNING)
|
|
||||||
if self.__logging_file:
|
|
||||||
file_handler = logging.FileHandler(self.__logging_file)
|
|
||||||
file_handler.setFormatter(formatter)
|
|
||||||
self.logger.addFilter(file_handler)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def logging_file(self):
|
def logging_file(self):
|
||||||
@ -111,10 +99,23 @@ class Configuration(object):
|
|||||||
def logging_file(self, value):
|
def logging_file(self, value):
|
||||||
self.__logging_file = value
|
self.__logging_file = value
|
||||||
if self.__logging_file:
|
if self.__logging_file:
|
||||||
formater = logging.Formatter(self.logging_format)
|
# If set logging file,
|
||||||
file_handler = logging.FileHandler(self.__logging_file)
|
# then add file handler and remove stream handler.
|
||||||
file_handler.setFormatter(formater)
|
self.logging_file_handler = logging.FileHandler(self.__logging_file)
|
||||||
self.logger.addHandler(file_handler)
|
self.logging_file_handler.setFormatter(self.logging_formatter)
|
||||||
|
for _, logger in iteritems(self.logger):
|
||||||
|
logger.addHandler(self.logging_file_handler)
|
||||||
|
if self.logging_stream_handler:
|
||||||
|
logger.removeHandler(self.logging_stream_handler)
|
||||||
|
else:
|
||||||
|
# If not set logging file,
|
||||||
|
# then add stream handler and remove file handler.
|
||||||
|
self.logging_stream_handler = logging.StreamHandler()
|
||||||
|
self.logging_stream_handler.setFormatter(self.logging_formatter)
|
||||||
|
for _, logger in iteritems(self.logger):
|
||||||
|
logger.addHandler(self.logging_stream_handler)
|
||||||
|
if self.logging_file_handler:
|
||||||
|
logger.removeHandler(self.logging_file_handler)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def debug(self):
|
def debug(self):
|
||||||
@ -125,13 +126,26 @@ class Configuration(object):
|
|||||||
self.__debug = value
|
self.__debug = value
|
||||||
if self.__debug:
|
if self.__debug:
|
||||||
# if debug status is True, turn on debug logging
|
# if debug status is True, turn on debug logging
|
||||||
self.logger.setLevel(logging.DEBUG)
|
for _, logger in iteritems(self.logger):
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
# turn on httplib debug
|
# turn on httplib debug
|
||||||
httplib.HTTPConnection.debuglevel = 1
|
httplib.HTTPConnection.debuglevel = 1
|
||||||
else:
|
else:
|
||||||
# if debug status is False, turn off debug logging,
|
# if debug status is False, turn off debug logging,
|
||||||
# setting log level to default `logging.WARNING`
|
# setting log level to default `logging.WARNING`
|
||||||
self.logger.setLevel(logging.WARNING)
|
for _, logger in iteritems(self.logger):
|
||||||
|
logger.setLevel(logging.WARNING)
|
||||||
|
# turn off httplib debug
|
||||||
|
httplib.HTTPConnection.debuglevel = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logging_format(self):
|
||||||
|
return self.__logging_format
|
||||||
|
|
||||||
|
@logging_format.setter
|
||||||
|
def logging_format(self, value):
|
||||||
|
self.__logging_format = value
|
||||||
|
self.logging_formatter = logging.Formatter(self.__logging_format)
|
||||||
|
|
||||||
def get_api_key_with_prefix(self, identifier):
|
def get_api_key_with_prefix(self, identifier):
|
||||||
"""
|
"""
|
||||||
|
@ -25,6 +25,7 @@ from .rest import ApiException
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import urllib
|
import urllib
|
||||||
import json
|
import json
|
||||||
import mimetypes
|
import mimetypes
|
||||||
@ -180,16 +181,19 @@ class ApiClient(object):
|
|||||||
If obj is str, int, float, bool, return directly.
|
If obj is str, int, float, bool, return directly.
|
||||||
If obj is datetime.datetime, datetime.date
|
If obj is datetime.datetime, datetime.date
|
||||||
convert to string in iso8601 format.
|
convert to string in iso8601 format.
|
||||||
If obj is list, santize each element in the list.
|
If obj is list, sanitize each element in the list.
|
||||||
If obj is dict, return the dict.
|
If obj is dict, return the dict.
|
||||||
If obj is swagger model, return the properties dict.
|
If obj is swagger model, return the properties dict.
|
||||||
|
|
||||||
:param obj: The data to serialize.
|
:param obj: The data to serialize.
|
||||||
:return: The serialized form of data.
|
:return: The serialized form of data.
|
||||||
"""
|
"""
|
||||||
|
types = (str, int, float, bool, tuple)
|
||||||
|
if sys.version_info < (3,0):
|
||||||
|
types = types + (unicode,)
|
||||||
if isinstance(obj, type(None)):
|
if isinstance(obj, type(None)):
|
||||||
return None
|
return None
|
||||||
elif isinstance(obj, (str, int, float, bool, tuple)):
|
elif isinstance(obj, types):
|
||||||
return obj
|
return obj
|
||||||
elif isinstance(obj, list):
|
elif isinstance(obj, list):
|
||||||
return [self.sanitize_for_serialization(sub_obj)
|
return [self.sanitize_for_serialization(sub_obj)
|
||||||
|
@ -15,7 +15,7 @@ Copyright 2015 SmartBear Software
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
ref: https://github.com/swagger-api/swagger-codegen
|
ref: https://github.com/swagger-api/swagger-codegen
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
@ -27,10 +27,11 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
# for python3
|
# for python3
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from six import iteritems
|
||||||
|
|
||||||
def singleton(cls, *args, **kw):
|
def singleton(cls, *args, **kw):
|
||||||
instances = {}
|
instances = {}
|
||||||
@ -72,36 +73,23 @@ class Configuration(object):
|
|||||||
self.password = ""
|
self.password = ""
|
||||||
|
|
||||||
# Logging Settings
|
# Logging Settings
|
||||||
|
self.logger = {}
|
||||||
|
self.logger["package_logger"] = logging.getLogger("swagger_client")
|
||||||
|
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
|
||||||
|
# Log format
|
||||||
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
|
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
|
||||||
# Debug file location
|
# Debug file location
|
||||||
self.__logging_file = None
|
self.logging_stream_handler = None
|
||||||
|
self.logging_file_handler = None
|
||||||
|
self.logging_file = None
|
||||||
# Debug switch
|
# Debug switch
|
||||||
self.__debug = False
|
self.debug = False
|
||||||
self.init_logger()
|
|
||||||
|
|
||||||
# SSL/TLS verification
|
# SSL/TLS verification
|
||||||
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
||||||
self.verify_ssl = True
|
self.verify_ssl = True
|
||||||
# Set this to customize the certificate file to verify the peer.
|
# Set this to customize the certificate file to verify the peer.
|
||||||
self.ssl_ca_cert = None
|
self.ssl_ca_cert = None
|
||||||
|
|
||||||
def init_logger(self):
|
|
||||||
"""
|
|
||||||
Initializes logger settings.
|
|
||||||
"""
|
|
||||||
self.logger = logging.getLogger()
|
|
||||||
formatter = logging.Formatter(self.logging_format)
|
|
||||||
stream_handler = logging.StreamHandler()
|
|
||||||
stream_handler.setFormatter(formatter)
|
|
||||||
self.logger.addHandler(stream_handler)
|
|
||||||
if self.__debug:
|
|
||||||
self.logger.setLevel(logging.DEBUG)
|
|
||||||
else:
|
|
||||||
self.logger.setLevel(logging.WARNING)
|
|
||||||
if self.__logging_file:
|
|
||||||
file_handler = logging.FileHandler(self.__logging_file)
|
|
||||||
file_handler.setFormatter(formatter)
|
|
||||||
self.logger.addFilter(file_handler)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def logging_file(self):
|
def logging_file(self):
|
||||||
@ -111,10 +99,23 @@ class Configuration(object):
|
|||||||
def logging_file(self, value):
|
def logging_file(self, value):
|
||||||
self.__logging_file = value
|
self.__logging_file = value
|
||||||
if self.__logging_file:
|
if self.__logging_file:
|
||||||
formater = logging.Formatter(self.logging_format)
|
# If set logging file,
|
||||||
file_handler = logging.FileHandler(self.__logging_file)
|
# then add file handler and remove stream handler.
|
||||||
file_handler.setFormatter(formater)
|
self.logging_file_handler = logging.FileHandler(self.__logging_file)
|
||||||
self.logger.addHandler(file_handler)
|
self.logging_file_handler.setFormatter(self.logging_formatter)
|
||||||
|
for _, logger in iteritems(self.logger):
|
||||||
|
logger.addHandler(self.logging_file_handler)
|
||||||
|
if self.logging_stream_handler:
|
||||||
|
logger.removeHandler(self.logging_stream_handler)
|
||||||
|
else:
|
||||||
|
# If not set logging file,
|
||||||
|
# then add stream handler and remove file handler.
|
||||||
|
self.logging_stream_handler = logging.StreamHandler()
|
||||||
|
self.logging_stream_handler.setFormatter(self.logging_formatter)
|
||||||
|
for _, logger in iteritems(self.logger):
|
||||||
|
logger.addHandler(self.logging_stream_handler)
|
||||||
|
if self.logging_file_handler:
|
||||||
|
logger.removeHandler(self.logging_file_handler)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def debug(self):
|
def debug(self):
|
||||||
@ -125,13 +126,26 @@ class Configuration(object):
|
|||||||
self.__debug = value
|
self.__debug = value
|
||||||
if self.__debug:
|
if self.__debug:
|
||||||
# if debug status is True, turn on debug logging
|
# if debug status is True, turn on debug logging
|
||||||
self.logger.setLevel(logging.DEBUG)
|
for _, logger in iteritems(self.logger):
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
# turn on httplib debug
|
# turn on httplib debug
|
||||||
httplib.HTTPConnection.debuglevel = 1
|
httplib.HTTPConnection.debuglevel = 1
|
||||||
else:
|
else:
|
||||||
# if debug status is False, turn off debug logging,
|
# if debug status is False, turn off debug logging,
|
||||||
# setting log level to default `logging.WARNING`
|
# setting log level to default `logging.WARNING`
|
||||||
self.logger.setLevel(logging.WARNING)
|
for _, logger in iteritems(self.logger):
|
||||||
|
logger.setLevel(logging.WARNING)
|
||||||
|
# turn off httplib debug
|
||||||
|
httplib.HTTPConnection.debuglevel = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logging_format(self):
|
||||||
|
return self.__logging_format
|
||||||
|
|
||||||
|
@logging_format.setter
|
||||||
|
def logging_format(self, value):
|
||||||
|
self.__logging_format = value
|
||||||
|
self.logging_formatter = logging.Formatter(self.__logging_format)
|
||||||
|
|
||||||
def get_api_key_with_prefix(self, identifier):
|
def get_api_key_with_prefix(self, identifier):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user