mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 14:40:53 +00:00
Merge pull request #1019 from geekerzp/python-refactor
[Python] Enhancements of python client
This commit is contained in:
commit
bd28271b0b
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software
|
|||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
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.
|
||||||
|
|
||||||
NOTE: This class is auto generated by the swagger code generator program.
|
|
||||||
Do not edit the class manually.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -34,6 +31,10 @@ from ..api_client import ApiClient
|
|||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
class {{classname}}(object):
|
class {{classname}}(object):
|
||||||
|
"""
|
||||||
|
NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, api_client=None):
|
def __init__(self, api_client=None):
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
|
@ -1,10 +1,20 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""Swagger generic API client. This client handles the client-
|
"""
|
||||||
server communication, and is invariant across implementations. Specifics of
|
Copyright 2015 SmartBear Software
|
||||||
the methods and models for each application are generated from the Swagger
|
|
||||||
templates."""
|
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.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from . import models
|
from . import models
|
||||||
@ -38,15 +48,27 @@ from .configuration import Configuration
|
|||||||
|
|
||||||
class ApiClient(object):
|
class ApiClient(object):
|
||||||
"""
|
"""
|
||||||
Generic API client for Swagger client library builds
|
Generic API client for Swagger client library builds.
|
||||||
|
|
||||||
:param host: The base path for the server to call
|
Swagger generic API client. This client handles the client-
|
||||||
:param header_name: a header to pass when making calls to the API
|
server communication, and is invariant across implementations. Specifics of
|
||||||
:param header_value: a header value to pass when making calls to the API
|
the methods and models for each application are generated from the Swagger
|
||||||
|
templates.
|
||||||
|
|
||||||
|
NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
https://github.com/swagger-api/swagger-codegen
|
||||||
|
Do not edit the class manually.
|
||||||
|
|
||||||
|
:param host: The base path for the server to call.
|
||||||
|
:param header_name: a header to pass when making calls to the API.
|
||||||
|
:param header_value: a header value to pass when making calls to the API.
|
||||||
"""
|
"""
|
||||||
def __init__(self, host=Configuration().host,
|
def __init__(self, host=Configuration().host,
|
||||||
header_name=None, header_value=None, cookie=None):
|
header_name=None, header_value=None, cookie=None):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Constructor of the class.
|
||||||
|
"""
|
||||||
self.default_headers = {}
|
self.default_headers = {}
|
||||||
if header_name is not None:
|
if header_name is not None:
|
||||||
self.default_headers[header_name] = header_value
|
self.default_headers[header_name] = header_value
|
||||||
@ -57,10 +79,16 @@ class ApiClient(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def user_agent(self):
|
def user_agent(self):
|
||||||
|
"""
|
||||||
|
Gets user agent.
|
||||||
|
"""
|
||||||
return self.default_headers['User-Agent']
|
return self.default_headers['User-Agent']
|
||||||
|
|
||||||
@user_agent.setter
|
@user_agent.setter
|
||||||
def user_agent(self, value):
|
def user_agent(self, value):
|
||||||
|
"""
|
||||||
|
Sets user agent.
|
||||||
|
"""
|
||||||
self.default_headers['User-Agent'] = value
|
self.default_headers['User-Agent'] = value
|
||||||
|
|
||||||
def set_default_header(self, header_name, header_value):
|
def set_default_header(self, header_name, header_value):
|
||||||
@ -129,11 +157,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def to_path_value(self, obj):
|
def to_path_value(self, obj):
|
||||||
"""
|
"""
|
||||||
Convert a string or object to a path-friendly value
|
Takes value and turn it into a string suitable for inclusion in
|
||||||
|
the path, by url-encoding.
|
||||||
|
|
||||||
:param obj: object or string value
|
:param obj: object or string value.
|
||||||
|
|
||||||
:return string: quoted value
|
:return string: quoted value.
|
||||||
"""
|
"""
|
||||||
if type(obj) == list:
|
if type(obj) == list:
|
||||||
return ','.join(obj)
|
return ','.join(obj)
|
||||||
@ -142,7 +171,7 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def sanitize_for_serialization(self, obj):
|
def sanitize_for_serialization(self, obj):
|
||||||
"""
|
"""
|
||||||
Sanitize an object for Request.
|
Builds a JSON POST object.
|
||||||
|
|
||||||
If obj is None, return None.
|
If obj is None, return None.
|
||||||
If obj is str, int, float, bool, return directly.
|
If obj is str, int, float, bool, return directly.
|
||||||
@ -151,6 +180,9 @@ class ApiClient(object):
|
|||||||
If obj is list, santize each element in the list.
|
If obj is list, santize 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.
|
||||||
|
:return: The serialized form of data.
|
||||||
"""
|
"""
|
||||||
if isinstance(obj, type(None)):
|
if isinstance(obj, type(None)):
|
||||||
return None
|
return None
|
||||||
@ -181,13 +213,13 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def deserialize(self, response, response_type):
|
def deserialize(self, response, response_type):
|
||||||
"""
|
"""
|
||||||
Derialize response into an object.
|
Deserializes response into an object.
|
||||||
|
|
||||||
:param response: RESTResponse object to be deserialized
|
:param response: RESTResponse object to be deserialized.
|
||||||
:param response_type: class literal for
|
:param response_type: class literal for
|
||||||
deserialzied object, or string of class name
|
deserialzied object, or string of class name.
|
||||||
|
|
||||||
:return: deserialized object
|
:return: deserialized object.
|
||||||
"""
|
"""
|
||||||
# handle file downloading
|
# handle file downloading
|
||||||
# save response body into a tmp file and return the instance
|
# save response body into a tmp file and return the instance
|
||||||
@ -204,10 +236,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize(self, data, klass):
|
def __deserialize(self, data, klass):
|
||||||
"""
|
"""
|
||||||
:param data: dict, list or str
|
Deserializes dict, list, str into an object.
|
||||||
:param klass: class literal, or string of class name
|
|
||||||
|
|
||||||
:return: object
|
:param data: dict, list or str.
|
||||||
|
:param klass: class literal, or string of class name.
|
||||||
|
|
||||||
|
:return: object.
|
||||||
"""
|
"""
|
||||||
if data is None:
|
if data is None:
|
||||||
return None
|
return None
|
||||||
@ -248,8 +282,7 @@ class ApiClient(object):
|
|||||||
body=None, post_params=None, files=None,
|
body=None, post_params=None, files=None,
|
||||||
response_type=None, auth_settings=None, callback=None):
|
response_type=None, auth_settings=None, callback=None):
|
||||||
"""
|
"""
|
||||||
Perform http request and return deserialized data
|
Makes the HTTP request and return the deserialized data.
|
||||||
|
|
||||||
|
|
||||||
:param resource_path: Path to method endpoint.
|
:param resource_path: Path to method endpoint.
|
||||||
:param method: Method to call.
|
:param method: Method to call.
|
||||||
@ -293,7 +326,7 @@ class ApiClient(object):
|
|||||||
def request(self, method, url, query_params=None, headers=None,
|
def request(self, method, url, query_params=None, headers=None,
|
||||||
post_params=None, body=None):
|
post_params=None, body=None):
|
||||||
"""
|
"""
|
||||||
Perform http request using RESTClient.
|
Makes the HTTP request using RESTClient.
|
||||||
"""
|
"""
|
||||||
if method == "GET":
|
if method == "GET":
|
||||||
return RESTClient.GET(url,
|
return RESTClient.GET(url,
|
||||||
@ -329,6 +362,13 @@ class ApiClient(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def prepare_post_parameters(self, post_params=None, files=None):
|
def prepare_post_parameters(self, post_params=None, files=None):
|
||||||
|
"""
|
||||||
|
Builds form parameters.
|
||||||
|
|
||||||
|
:param post_params: Normal form parameters.
|
||||||
|
:param files: File parameters.
|
||||||
|
:return: Form parameters with files.
|
||||||
|
"""
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
if post_params:
|
if post_params:
|
||||||
@ -350,7 +390,10 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def select_header_accept(self, accepts):
|
def select_header_accept(self, accepts):
|
||||||
"""
|
"""
|
||||||
Return `Accept` based on an array of accepts provided
|
Returns `Accept` based on an array of accepts provided.
|
||||||
|
|
||||||
|
:param accepts: List of headers.
|
||||||
|
:return: Accept (e.g. application/json).
|
||||||
"""
|
"""
|
||||||
if not accepts:
|
if not accepts:
|
||||||
return
|
return
|
||||||
@ -364,7 +407,10 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def select_header_content_type(self, content_types):
|
def select_header_content_type(self, content_types):
|
||||||
"""
|
"""
|
||||||
Return `Content-Type` baseed on an array of content_types provided
|
Returns `Content-Type` based on an array of content_types provided.
|
||||||
|
|
||||||
|
:param content_types: List of content-types.
|
||||||
|
:return: Content-Type (e.g. application/json).
|
||||||
"""
|
"""
|
||||||
if not content_types:
|
if not content_types:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
@ -378,7 +424,11 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def update_params_for_auth(self, headers, querys, auth_settings):
|
def update_params_for_auth(self, headers, querys, auth_settings):
|
||||||
"""
|
"""
|
||||||
Update header and query params based on authentication setting
|
Updates header and query params based on authentication setting.
|
||||||
|
|
||||||
|
:param headers: Header parameters dict to be updated.
|
||||||
|
:param querys: Query parameters dict to be updated.
|
||||||
|
:param auth_settings: Authentication setting identifiers list.
|
||||||
"""
|
"""
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
|
|
||||||
@ -399,12 +449,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_file(self, response):
|
def __deserialize_file(self, response):
|
||||||
"""
|
"""
|
||||||
Save response body into a file in (the defined) temporary folder,
|
Saves response body into a file in (the defined) temporary folder,
|
||||||
using the filename from the `Content-Disposition` header if provided,
|
using the filename from the `Content-Disposition` header if provided,
|
||||||
otherwise a random filename.
|
otherwise a random filename.
|
||||||
|
|
||||||
:param response: RESTResponse
|
:param response: RESTResponse.
|
||||||
:return: file path
|
:return: file path.
|
||||||
"""
|
"""
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
|
|
||||||
@ -426,12 +476,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_primitive(self, data, klass):
|
def __deserialize_primitive(self, data, klass):
|
||||||
"""
|
"""
|
||||||
Deserialize string to primitive type
|
Deserializes string to primitive type.
|
||||||
|
|
||||||
:param data: str
|
:param data: str.
|
||||||
:param klass: class literal
|
:param klass: class literal.
|
||||||
|
|
||||||
:return: int, float, str, bool
|
:return: int, float, str, bool.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
value = klass(data)
|
value = klass(data)
|
||||||
@ -443,16 +493,18 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_object(self):
|
def __deserialize_object(self):
|
||||||
"""
|
"""
|
||||||
Deserialize empty object
|
Deserializes empty object.
|
||||||
|
|
||||||
|
:return: object.
|
||||||
"""
|
"""
|
||||||
return object()
|
return object()
|
||||||
|
|
||||||
def __deserialize_date(self, string):
|
def __deserialize_date(self, string):
|
||||||
"""
|
"""
|
||||||
Deserialize string to date
|
Deserializes string to date.
|
||||||
|
|
||||||
:param string: str
|
:param string: str.
|
||||||
:return: date
|
:return: date.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
@ -468,12 +520,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_datatime(self, string):
|
def __deserialize_datatime(self, string):
|
||||||
"""
|
"""
|
||||||
Deserialize string to datetime.
|
Deserializes string to datetime.
|
||||||
|
|
||||||
The string should be in iso8601 datetime format.
|
The string should be in iso8601 datetime format.
|
||||||
|
|
||||||
:param string: str
|
:param string: str.
|
||||||
:return: datetime
|
:return: datetime.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
@ -489,10 +541,11 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_model(self, data, klass):
|
def __deserialize_model(self, data, klass):
|
||||||
"""
|
"""
|
||||||
Deserialize list or dict to model
|
Deserializes list or dict to model.
|
||||||
|
|
||||||
:param data: dict, list
|
:param data: dict, list.
|
||||||
:param klass: class literal
|
:param klass: class literal.
|
||||||
|
:return: model object.
|
||||||
"""
|
"""
|
||||||
instance = klass()
|
instance = klass()
|
||||||
|
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Copyright 2015 SmartBear Software
|
||||||
|
|
||||||
|
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.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import base64
|
import base64
|
||||||
import urllib3
|
import urllib3
|
||||||
@ -18,26 +36,45 @@ def singleton(cls, *args, **kw):
|
|||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class Configuration(object):
|
class Configuration(object):
|
||||||
|
"""
|
||||||
|
NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
https://github.com/swagger-api/swagger-codegen
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Constructor
|
||||||
|
"""
|
||||||
# Default Base url
|
# Default Base url
|
||||||
self.host = "{{basePath}}"
|
self.host = "{{basePath}}"
|
||||||
# Default api client
|
# Default api client
|
||||||
self.api_client = None
|
self.api_client = None
|
||||||
# Temp file folder
|
# Temp file folder for download
|
||||||
self.temp_folder_path = None
|
self.temp_folder_path = None
|
||||||
|
|
||||||
# Authentication Settings
|
# Authentication Settings
|
||||||
|
# dict to store API key(s)
|
||||||
self.api_key = {}
|
self.api_key = {}
|
||||||
|
# dict to store API prefix (e.g. Bearer)
|
||||||
self.api_key_prefix = {}
|
self.api_key_prefix = {}
|
||||||
|
# Username for HTTP basic authentication
|
||||||
self.username = ""
|
self.username = ""
|
||||||
|
# Password for HTTP basic authentication
|
||||||
self.password = ""
|
self.password = ""
|
||||||
|
|
||||||
# Logging Settings
|
# Logging Settings
|
||||||
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
|
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
|
||||||
|
# Debug file location
|
||||||
self.__logging_file = None
|
self.__logging_file = None
|
||||||
|
# Debug switch
|
||||||
self.__debug = False
|
self.__debug = False
|
||||||
self.init_logger()
|
self.init_logger()
|
||||||
|
|
||||||
def init_logger(self):
|
def init_logger(self):
|
||||||
|
"""
|
||||||
|
Initializes logger settings.
|
||||||
|
"""
|
||||||
self.logger = logging.getLogger()
|
self.logger = logging.getLogger()
|
||||||
formatter = logging.Formatter(self.logging_format)
|
formatter = logging.Formatter(self.logging_format)
|
||||||
stream_handler = logging.StreamHandler()
|
stream_handler = logging.StreamHandler()
|
||||||
@ -82,20 +119,33 @@ class Configuration(object):
|
|||||||
# setting log level to default `logging.WARNING`
|
# setting log level to default `logging.WARNING`
|
||||||
self.logger.setLevel(logging.WARNING)
|
self.logger.setLevel(logging.WARNING)
|
||||||
|
|
||||||
def get_api_key_with_prefix(self, key):
|
def get_api_key_with_prefix(self, identifier):
|
||||||
""" Return api key prepend prefix for key """
|
"""
|
||||||
if self.api_key.get(key) and self.api_key_prefix.get(key):
|
Gets API key (with prefix if set).
|
||||||
return self.api_key_prefix[key] + ' ' + self.api_key[key]
|
|
||||||
elif self.api_key.get(key):
|
:param identifier: The identifier of apiKey.
|
||||||
return self.api_key[key]
|
:return: The token for api key authentication.
|
||||||
|
"""
|
||||||
|
if self.api_key.get(identifier) and self.api_key_prefix.get(identifier):
|
||||||
|
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier]
|
||||||
|
elif self.api_key.get(identifier):
|
||||||
|
return self.api_key[identifier]
|
||||||
|
|
||||||
def get_basic_auth_token(self):
|
def get_basic_auth_token(self):
|
||||||
""" Return basic auth header string """
|
"""
|
||||||
|
Gets basic auth header string.
|
||||||
|
|
||||||
|
:return: The token for basic HTTP authentication.
|
||||||
|
"""
|
||||||
return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
|
return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
|
||||||
.get('authorization')
|
.get('authorization')
|
||||||
|
|
||||||
def auth_settings(self):
|
def auth_settings(self):
|
||||||
""" Return Auth Settings for api client """
|
"""
|
||||||
|
Gets Auth Settings dict for api client.
|
||||||
|
|
||||||
|
:return: The Auth Settings information dict.
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
{{#isApiKey}}
|
{{#isApiKey}}
|
||||||
@ -120,6 +170,11 @@ class Configuration(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def to_debug_report(self):
|
def to_debug_report(self):
|
||||||
|
"""
|
||||||
|
Gets the essential information for debugging.
|
||||||
|
|
||||||
|
:return: The report for debugging.
|
||||||
|
"""
|
||||||
return "Python SDK Debug Report:\n"\
|
return "Python SDK Debug Report:\n"\
|
||||||
"OS: {env}\n"\
|
"OS: {env}\n"\
|
||||||
"Python Version: {pyversion}\n"\
|
"Python Version: {pyversion}\n"\
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,6 +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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
Copyright 2015 SmartBear Software
|
||||||
|
|
||||||
|
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.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
Credit: this file (rest.py) is modified based on rest.py in Dropbox Python SDK:
|
Credit: this file (rest.py) is modified based on rest.py in Dropbox Python SDK:
|
||||||
https://www.dropbox.com/developers/core/sdks/python
|
https://www.dropbox.com/developers/core/sdks/python
|
||||||
"""
|
"""
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# coding: utf-8
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
@ -34,11 +35,3 @@ setup(
|
|||||||
)
|
)
|
||||||
|
|
||||||
{{/hasMore}}{{/apis}}{{/apiInfo}}
|
{{/hasMore}}{{/apis}}{{/apiInfo}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
@ -33,11 +35,3 @@ setup(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,20 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""Swagger generic API client. This client handles the client-
|
"""
|
||||||
server communication, and is invariant across implementations. Specifics of
|
Copyright 2015 SmartBear Software
|
||||||
the methods and models for each application are generated from the Swagger
|
|
||||||
templates."""
|
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.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from . import models
|
from . import models
|
||||||
@ -38,29 +48,47 @@ from .configuration import Configuration
|
|||||||
|
|
||||||
class ApiClient(object):
|
class ApiClient(object):
|
||||||
"""
|
"""
|
||||||
Generic API client for Swagger client library builds
|
Generic API client for Swagger client library builds.
|
||||||
|
|
||||||
:param host: The base path for the server to call
|
Swagger generic API client. This client handles the client-
|
||||||
:param header_name: a header to pass when making calls to the API
|
server communication, and is invariant across implementations. Specifics of
|
||||||
:param header_value: a header value to pass when making calls to the API
|
the methods and models for each application are generated from the Swagger
|
||||||
|
templates.
|
||||||
|
|
||||||
|
NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
https://github.com/swagger-api/swagger-codegen
|
||||||
|
Do not edit the class manually.
|
||||||
|
|
||||||
|
:param host: The base path for the server to call.
|
||||||
|
:param header_name: a header to pass when making calls to the API.
|
||||||
|
:param header_value: a header value to pass when making calls to the API.
|
||||||
"""
|
"""
|
||||||
def __init__(self, host=Configuration().host,
|
def __init__(self, host=Configuration().host,
|
||||||
header_name=None, header_value=None):
|
header_name=None, header_value=None, cookie=None):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Constructor of the class.
|
||||||
|
"""
|
||||||
self.default_headers = {}
|
self.default_headers = {}
|
||||||
if header_name is not None:
|
if header_name is not None:
|
||||||
self.default_headers[header_name] = header_value
|
self.default_headers[header_name] = header_value
|
||||||
self.host = host
|
self.host = host
|
||||||
self.cookie = None
|
self.cookie = cookie
|
||||||
# Set default User-Agent.
|
# Set default User-Agent.
|
||||||
self.user_agent = 'Python-Swagger'
|
self.user_agent = 'Python-Swagger'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user_agent(self):
|
def user_agent(self):
|
||||||
|
"""
|
||||||
|
Gets user agent.
|
||||||
|
"""
|
||||||
return self.default_headers['User-Agent']
|
return self.default_headers['User-Agent']
|
||||||
|
|
||||||
@user_agent.setter
|
@user_agent.setter
|
||||||
def user_agent(self, value):
|
def user_agent(self, value):
|
||||||
|
"""
|
||||||
|
Sets user agent.
|
||||||
|
"""
|
||||||
self.default_headers['User-Agent'] = value
|
self.default_headers['User-Agent'] = value
|
||||||
|
|
||||||
def set_default_header(self, header_name, header_value):
|
def set_default_header(self, header_name, header_value):
|
||||||
@ -129,11 +157,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def to_path_value(self, obj):
|
def to_path_value(self, obj):
|
||||||
"""
|
"""
|
||||||
Convert a string or object to a path-friendly value
|
Takes value and turn it into a string suitable for inclusion in
|
||||||
|
the path, by url-encoding.
|
||||||
|
|
||||||
:param obj: object or string value
|
:param obj: object or string value.
|
||||||
|
|
||||||
:return string: quoted value
|
:return string: quoted value.
|
||||||
"""
|
"""
|
||||||
if type(obj) == list:
|
if type(obj) == list:
|
||||||
return ','.join(obj)
|
return ','.join(obj)
|
||||||
@ -142,7 +171,7 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def sanitize_for_serialization(self, obj):
|
def sanitize_for_serialization(self, obj):
|
||||||
"""
|
"""
|
||||||
Sanitize an object for Request.
|
Builds a JSON POST object.
|
||||||
|
|
||||||
If obj is None, return None.
|
If obj is None, return None.
|
||||||
If obj is str, int, float, bool, return directly.
|
If obj is str, int, float, bool, return directly.
|
||||||
@ -151,6 +180,9 @@ class ApiClient(object):
|
|||||||
If obj is list, santize each element in the list.
|
If obj is list, santize 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.
|
||||||
|
:return: The serialized form of data.
|
||||||
"""
|
"""
|
||||||
if isinstance(obj, type(None)):
|
if isinstance(obj, type(None)):
|
||||||
return None
|
return None
|
||||||
@ -181,13 +213,13 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def deserialize(self, response, response_type):
|
def deserialize(self, response, response_type):
|
||||||
"""
|
"""
|
||||||
Derialize response into an object.
|
Deserializes response into an object.
|
||||||
|
|
||||||
:param response: RESTResponse object to be deserialized
|
:param response: RESTResponse object to be deserialized.
|
||||||
:param response_type: class literal for
|
:param response_type: class literal for
|
||||||
deserialzied object, or string of class name
|
deserialzied object, or string of class name.
|
||||||
|
|
||||||
:return: deserialized object
|
:return: deserialized object.
|
||||||
"""
|
"""
|
||||||
# handle file downloading
|
# handle file downloading
|
||||||
# save response body into a tmp file and return the instance
|
# save response body into a tmp file and return the instance
|
||||||
@ -204,10 +236,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize(self, data, klass):
|
def __deserialize(self, data, klass):
|
||||||
"""
|
"""
|
||||||
:param data: dict, list or str
|
Deserializes dict, list, str into an object.
|
||||||
:param klass: class literal, or string of class name
|
|
||||||
|
|
||||||
:return: object
|
:param data: dict, list or str.
|
||||||
|
:param klass: class literal, or string of class name.
|
||||||
|
|
||||||
|
:return: object.
|
||||||
"""
|
"""
|
||||||
if data is None:
|
if data is None:
|
||||||
return None
|
return None
|
||||||
@ -219,7 +253,7 @@ class ApiClient(object):
|
|||||||
for sub_data in data]
|
for sub_data in data]
|
||||||
|
|
||||||
if 'dict(' in klass:
|
if 'dict(' in klass:
|
||||||
sub_kls = re.match('dict\((.*), (.*)\)', klass).group(2)
|
sub_kls = re.match('dict\(([^,]*), (.*)\)', klass).group(2)
|
||||||
return {k: self.__deserialize(v, sub_kls)
|
return {k: self.__deserialize(v, sub_kls)
|
||||||
for k, v in iteritems(data)}
|
for k, v in iteritems(data)}
|
||||||
|
|
||||||
@ -248,8 +282,7 @@ class ApiClient(object):
|
|||||||
body=None, post_params=None, files=None,
|
body=None, post_params=None, files=None,
|
||||||
response_type=None, auth_settings=None, callback=None):
|
response_type=None, auth_settings=None, callback=None):
|
||||||
"""
|
"""
|
||||||
Perform http request and return deserialized data
|
Makes the HTTP request and return the deserialized data.
|
||||||
|
|
||||||
|
|
||||||
:param resource_path: Path to method endpoint.
|
:param resource_path: Path to method endpoint.
|
||||||
:param method: Method to call.
|
:param method: Method to call.
|
||||||
@ -293,7 +326,7 @@ class ApiClient(object):
|
|||||||
def request(self, method, url, query_params=None, headers=None,
|
def request(self, method, url, query_params=None, headers=None,
|
||||||
post_params=None, body=None):
|
post_params=None, body=None):
|
||||||
"""
|
"""
|
||||||
Perform http request using RESTClient.
|
Makes the HTTP request using RESTClient.
|
||||||
"""
|
"""
|
||||||
if method == "GET":
|
if method == "GET":
|
||||||
return RESTClient.GET(url,
|
return RESTClient.GET(url,
|
||||||
@ -329,6 +362,13 @@ class ApiClient(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def prepare_post_parameters(self, post_params=None, files=None):
|
def prepare_post_parameters(self, post_params=None, files=None):
|
||||||
|
"""
|
||||||
|
Builds form parameters.
|
||||||
|
|
||||||
|
:param post_params: Normal form parameters.
|
||||||
|
:param files: File parameters.
|
||||||
|
:return: Form parameters with files.
|
||||||
|
"""
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
if post_params:
|
if post_params:
|
||||||
@ -350,7 +390,10 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def select_header_accept(self, accepts):
|
def select_header_accept(self, accepts):
|
||||||
"""
|
"""
|
||||||
Return `Accept` based on an array of accepts provided
|
Returns `Accept` based on an array of accepts provided.
|
||||||
|
|
||||||
|
:param accepts: List of headers.
|
||||||
|
:return: Accept (e.g. application/json).
|
||||||
"""
|
"""
|
||||||
if not accepts:
|
if not accepts:
|
||||||
return
|
return
|
||||||
@ -364,7 +407,10 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def select_header_content_type(self, content_types):
|
def select_header_content_type(self, content_types):
|
||||||
"""
|
"""
|
||||||
Return `Content-Type` baseed on an array of content_types provided
|
Returns `Content-Type` based on an array of content_types provided.
|
||||||
|
|
||||||
|
:param content_types: List of content-types.
|
||||||
|
:return: Content-Type (e.g. application/json).
|
||||||
"""
|
"""
|
||||||
if not content_types:
|
if not content_types:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
@ -378,7 +424,11 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def update_params_for_auth(self, headers, querys, auth_settings):
|
def update_params_for_auth(self, headers, querys, auth_settings):
|
||||||
"""
|
"""
|
||||||
Update header and query params based on authentication setting
|
Updates header and query params based on authentication setting.
|
||||||
|
|
||||||
|
:param headers: Header parameters dict to be updated.
|
||||||
|
:param querys: Query parameters dict to be updated.
|
||||||
|
:param auth_settings: Authentication setting identifiers list.
|
||||||
"""
|
"""
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
|
|
||||||
@ -399,12 +449,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_file(self, response):
|
def __deserialize_file(self, response):
|
||||||
"""
|
"""
|
||||||
Save response body into a file in (the defined) temporary folder,
|
Saves response body into a file in (the defined) temporary folder,
|
||||||
using the filename from the `Content-Disposition` header if provided,
|
using the filename from the `Content-Disposition` header if provided,
|
||||||
otherwise a random filename.
|
otherwise a random filename.
|
||||||
|
|
||||||
:param response: RESTResponse
|
:param response: RESTResponse.
|
||||||
:return: file path
|
:return: file path.
|
||||||
"""
|
"""
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
|
|
||||||
@ -426,12 +476,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_primitive(self, data, klass):
|
def __deserialize_primitive(self, data, klass):
|
||||||
"""
|
"""
|
||||||
Deserialize string to primitive type
|
Deserializes string to primitive type.
|
||||||
|
|
||||||
:param data: str
|
:param data: str.
|
||||||
:param klass: class literal
|
:param klass: class literal.
|
||||||
|
|
||||||
:return: int, float, str, bool
|
:return: int, float, str, bool.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
value = klass(data)
|
value = klass(data)
|
||||||
@ -443,16 +493,18 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_object(self):
|
def __deserialize_object(self):
|
||||||
"""
|
"""
|
||||||
Deserialize empty object
|
Deserializes empty object.
|
||||||
|
|
||||||
|
:return: object.
|
||||||
"""
|
"""
|
||||||
return object()
|
return object()
|
||||||
|
|
||||||
def __deserialize_date(self, string):
|
def __deserialize_date(self, string):
|
||||||
"""
|
"""
|
||||||
Deserialize string to date
|
Deserializes string to date.
|
||||||
|
|
||||||
:param string: str
|
:param string: str.
|
||||||
:return: date
|
:return: date.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
@ -468,12 +520,12 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_datatime(self, string):
|
def __deserialize_datatime(self, string):
|
||||||
"""
|
"""
|
||||||
Deserialize string to datetime.
|
Deserializes string to datetime.
|
||||||
|
|
||||||
The string should be in iso8601 datetime format.
|
The string should be in iso8601 datetime format.
|
||||||
|
|
||||||
:param string: str
|
:param string: str.
|
||||||
:return: datetime
|
:return: datetime.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
@ -489,10 +541,11 @@ class ApiClient(object):
|
|||||||
|
|
||||||
def __deserialize_model(self, data, klass):
|
def __deserialize_model(self, data, klass):
|
||||||
"""
|
"""
|
||||||
Deserialize list or dict to model
|
Deserializes list or dict to model.
|
||||||
|
|
||||||
:param data: dict, list
|
:param data: dict, list.
|
||||||
:param klass: class literal
|
:param klass: class literal.
|
||||||
|
:return: model object.
|
||||||
"""
|
"""
|
||||||
instance = klass()
|
instance = klass()
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software
|
|||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
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.
|
||||||
|
|
||||||
NOTE: This class is auto generated by the swagger code generator program.
|
|
||||||
Do not edit the class manually.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -33,6 +30,10 @@ from ..api_client import ApiClient
|
|||||||
|
|
||||||
|
|
||||||
class PetApi(object):
|
class PetApi(object):
|
||||||
|
"""
|
||||||
|
NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, api_client=None):
|
def __init__(self, api_client=None):
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software
|
|||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
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.
|
||||||
|
|
||||||
NOTE: This class is auto generated by the swagger code generator program.
|
|
||||||
Do not edit the class manually.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -33,6 +30,10 @@ from ..api_client import ApiClient
|
|||||||
|
|
||||||
|
|
||||||
class StoreApi(object):
|
class StoreApi(object):
|
||||||
|
"""
|
||||||
|
NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, api_client=None):
|
def __init__(self, api_client=None):
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software
|
|||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
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.
|
||||||
|
|
||||||
NOTE: This class is auto generated by the swagger code generator program.
|
|
||||||
Do not edit the class manually.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -33,6 +30,10 @@ from ..api_client import ApiClient
|
|||||||
|
|
||||||
|
|
||||||
class UserApi(object):
|
class UserApi(object):
|
||||||
|
"""
|
||||||
|
NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, api_client=None):
|
def __init__(self, api_client=None):
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Copyright 2015 SmartBear Software
|
||||||
|
|
||||||
|
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.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import base64
|
import base64
|
||||||
import urllib3
|
import urllib3
|
||||||
@ -18,26 +36,45 @@ def singleton(cls, *args, **kw):
|
|||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class Configuration(object):
|
class Configuration(object):
|
||||||
|
"""
|
||||||
|
NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
https://github.com/swagger-api/swagger-codegen
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Constructor
|
||||||
|
"""
|
||||||
# Default Base url
|
# Default Base url
|
||||||
self.host = "http://petstore.swagger.io/v2"
|
self.host = "http://petstore.swagger.io/v2"
|
||||||
# Default api client
|
# Default api client
|
||||||
self.api_client = None
|
self.api_client = None
|
||||||
# Temp file folder
|
# Temp file folder for download
|
||||||
self.temp_folder_path = None
|
self.temp_folder_path = None
|
||||||
|
|
||||||
# Authentication Settings
|
# Authentication Settings
|
||||||
|
# dict to store API key(s)
|
||||||
self.api_key = {}
|
self.api_key = {}
|
||||||
|
# dict to store API prefix (e.g. Bearer)
|
||||||
self.api_key_prefix = {}
|
self.api_key_prefix = {}
|
||||||
|
# Username for HTTP basic authentication
|
||||||
self.username = ""
|
self.username = ""
|
||||||
|
# Password for HTTP basic authentication
|
||||||
self.password = ""
|
self.password = ""
|
||||||
|
|
||||||
# Logging Settings
|
# Logging Settings
|
||||||
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
|
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
|
||||||
|
# Debug file location
|
||||||
self.__logging_file = None
|
self.__logging_file = None
|
||||||
|
# Debug switch
|
||||||
self.__debug = False
|
self.__debug = False
|
||||||
self.init_logger()
|
self.init_logger()
|
||||||
|
|
||||||
def init_logger(self):
|
def init_logger(self):
|
||||||
|
"""
|
||||||
|
Initializes logger settings.
|
||||||
|
"""
|
||||||
self.logger = logging.getLogger()
|
self.logger = logging.getLogger()
|
||||||
formatter = logging.Formatter(self.logging_format)
|
formatter = logging.Formatter(self.logging_format)
|
||||||
stream_handler = logging.StreamHandler()
|
stream_handler = logging.StreamHandler()
|
||||||
@ -82,20 +119,33 @@ class Configuration(object):
|
|||||||
# setting log level to default `logging.WARNING`
|
# setting log level to default `logging.WARNING`
|
||||||
self.logger.setLevel(logging.WARNING)
|
self.logger.setLevel(logging.WARNING)
|
||||||
|
|
||||||
def get_api_key_with_prefix(self, key):
|
def get_api_key_with_prefix(self, identifier):
|
||||||
""" Return api key prepend prefix for key """
|
"""
|
||||||
if self.api_key.get(key) and self.api_key_prefix.get(key):
|
Gets API key (with prefix if set).
|
||||||
return self.api_key_prefix[key] + ' ' + self.api_key[key]
|
|
||||||
elif self.api_key.get(key):
|
:param identifier: The identifier of apiKey.
|
||||||
return self.api_key[key]
|
:return: The token for api key authentication.
|
||||||
|
"""
|
||||||
|
if self.api_key.get(identifier) and self.api_key_prefix.get(identifier):
|
||||||
|
return self.api_key_prefix[identifier] + ' ' + self.api_key[identifier]
|
||||||
|
elif self.api_key.get(identifier):
|
||||||
|
return self.api_key[identifier]
|
||||||
|
|
||||||
def get_basic_auth_token(self):
|
def get_basic_auth_token(self):
|
||||||
""" Return basic auth header string """
|
"""
|
||||||
|
Gets basic auth header string.
|
||||||
|
|
||||||
|
:return: The token for basic HTTP authentication.
|
||||||
|
"""
|
||||||
return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
|
return urllib3.util.make_headers(basic_auth=self.username + ':' + self.password)\
|
||||||
.get('authorization')
|
.get('authorization')
|
||||||
|
|
||||||
def auth_settings(self):
|
def auth_settings(self):
|
||||||
""" Return Auth Settings for api client """
|
"""
|
||||||
|
Gets Auth Settings dict for api client.
|
||||||
|
|
||||||
|
:return: The Auth Settings information dict.
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
'api_key':
|
'api_key':
|
||||||
{
|
{
|
||||||
@ -107,6 +157,11 @@ class Configuration(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def to_debug_report(self):
|
def to_debug_report(self):
|
||||||
|
"""
|
||||||
|
Gets the essential information for debugging.
|
||||||
|
|
||||||
|
:return: The report for debugging.
|
||||||
|
"""
|
||||||
return "Python SDK Debug Report:\n"\
|
return "Python SDK Debug Report:\n"\
|
||||||
"OS: {env}\n"\
|
"OS: {env}\n"\
|
||||||
"Python Version: {pyversion}\n"\
|
"Python Version: {pyversion}\n"\
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,6 +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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,6 +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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,6 +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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,6 +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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,6 +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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
Copyright 2015 SmartBear Software
|
||||||
|
|
||||||
|
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.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
Credit: this file (rest.py) is modified based on rest.py in Dropbox Python SDK:
|
Credit: this file (rest.py) is modified based on rest.py in Dropbox Python SDK:
|
||||||
https://www.dropbox.com/developers/core/sdks/python
|
https://www.dropbox.com/developers/core/sdks/python
|
||||||
"""
|
"""
|
||||||
|
@ -150,6 +150,28 @@ class DeserializationTests(unittest.TestCase):
|
|||||||
self.assertEqual(deserialized[0].name, "doggie0")
|
self.assertEqual(deserialized[0].name, "doggie0")
|
||||||
self.assertEqual(deserialized[1].name, "doggie1")
|
self.assertEqual(deserialized[1].name, "doggie1")
|
||||||
|
|
||||||
|
def test_deserialize_nested_dict(self):
|
||||||
|
""" deserialize dict(str, dict(str, int)) """
|
||||||
|
data = {
|
||||||
|
"foo": {
|
||||||
|
"bar": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deserialized = self.deserialize(data, "dict(str, dict(str, int))")
|
||||||
|
self.assertTrue(isinstance(deserialized, dict))
|
||||||
|
self.assertTrue(isinstance(deserialized["foo"], dict))
|
||||||
|
self.assertTrue(isinstance(deserialized["foo"]["bar"], int))
|
||||||
|
|
||||||
|
def test_deserialize_nested_list(self):
|
||||||
|
""" deserialize list[list[str]] """
|
||||||
|
data = [["foo"]]
|
||||||
|
|
||||||
|
deserialized = self.deserialize(data, "list[list[str]]")
|
||||||
|
self.assertTrue(isinstance(deserialized, list))
|
||||||
|
self.assertTrue(isinstance(deserialized[0], list))
|
||||||
|
self.assertTrue(isinstance(deserialized[0][0], str))
|
||||||
|
|
||||||
def test_deserialize_none(self):
|
def test_deserialize_none(self):
|
||||||
""" deserialize None """
|
""" deserialize None """
|
||||||
deserialized = self.deserialize(None, "datetime")
|
deserialized = self.deserialize(None, "datetime")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user