Merge pull request #1019 from geekerzp/python-refactor

[Python] Enhancements of python client
This commit is contained in:
wing328 2015-07-29 17:39:58 +08:00
commit bd28271b0b
19 changed files with 403 additions and 146 deletions

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software
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.
NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
from __future__ import absolute_import
import sys
@ -34,6 +31,10 @@ from ..api_client import ApiClient
{{#operations}}
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):
config = Configuration()

View File

@ -1,10 +1,20 @@
#!/usr/bin/env python
# coding: utf-8
"""Swagger generic API client. This client handles the client-
server communication, and is invariant across implementations. Specifics of
the methods and models for each application are generated from the Swagger
templates."""
"""
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 . import models
@ -38,15 +48,27 @@ from .configuration import Configuration
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
: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
Swagger generic API client. This client handles the client-
server communication, and is invariant across implementations. Specifics of
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,
header_name=None, header_value=None, cookie=None):
"""
Constructor of the class.
"""
self.default_headers = {}
if header_name is not None:
self.default_headers[header_name] = header_value
@ -57,10 +79,16 @@ class ApiClient(object):
@property
def user_agent(self):
"""
Gets user agent.
"""
return self.default_headers['User-Agent']
@user_agent.setter
def user_agent(self, value):
"""
Sets user agent.
"""
self.default_headers['User-Agent'] = value
def set_default_header(self, header_name, header_value):
@ -129,11 +157,12 @@ class ApiClient(object):
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:
return ','.join(obj)
@ -142,7 +171,7 @@ class ApiClient(object):
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 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 dict, return the 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)):
return None
@ -181,13 +213,13 @@ class ApiClient(object):
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
deserialzied object, or string of class name
deserialzied object, or string of class name.
:return: deserialized object
:return: deserialized object.
"""
# handle file downloading
# save response body into a tmp file and return the instance
@ -204,10 +236,12 @@ class ApiClient(object):
def __deserialize(self, data, klass):
"""
:param data: dict, list or str
:param klass: class literal, or string of class name
Deserializes dict, list, str into an object.
:return: object
:param data: dict, list or str.
:param klass: class literal, or string of class name.
:return: object.
"""
if data is None:
return None
@ -248,8 +282,7 @@ class ApiClient(object):
body=None, post_params=None, files=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 method: Method to call.
@ -293,7 +326,7 @@ class ApiClient(object):
def request(self, method, url, query_params=None, headers=None,
post_params=None, body=None):
"""
Perform http request using RESTClient.
Makes the HTTP request using RESTClient.
"""
if method == "GET":
return RESTClient.GET(url,
@ -329,6 +362,13 @@ class ApiClient(object):
)
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 = {}
if post_params:
@ -350,7 +390,10 @@ class ApiClient(object):
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:
return
@ -364,7 +407,10 @@ class ApiClient(object):
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:
return 'application/json'
@ -378,7 +424,11 @@ class ApiClient(object):
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()
@ -399,12 +449,12 @@ class ApiClient(object):
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,
otherwise a random filename.
:param response: RESTResponse
:return: file path
:param response: RESTResponse.
:return: file path.
"""
config = Configuration()
@ -426,12 +476,12 @@ class ApiClient(object):
def __deserialize_primitive(self, data, klass):
"""
Deserialize string to primitive type
Deserializes string to primitive type.
:param data: str
:param klass: class literal
:param data: str.
:param klass: class literal.
:return: int, float, str, bool
:return: int, float, str, bool.
"""
try:
value = klass(data)
@ -443,16 +493,18 @@ class ApiClient(object):
def __deserialize_object(self):
"""
Deserialize empty object
Deserializes empty object.
:return: object.
"""
return object()
def __deserialize_date(self, string):
"""
Deserialize string to date
Deserializes string to date.
:param string: str
:return: date
:param string: str.
:return: date.
"""
try:
from dateutil.parser import parse
@ -468,12 +520,12 @@ class ApiClient(object):
def __deserialize_datatime(self, string):
"""
Deserialize string to datetime.
Deserializes string to datetime.
The string should be in iso8601 datetime format.
:param string: str
:return: datetime
:param string: str.
:return: datetime.
"""
try:
from dateutil.parser import parse
@ -489,10 +541,11 @@ class ApiClient(object):
def __deserialize_model(self, data, klass):
"""
Deserialize list or dict to model
Deserializes list or dict to model.
:param data: dict, list
:param klass: class literal
:param data: dict, list.
:param klass: class literal.
:return: model object.
"""
instance = klass()

View File

@ -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
import base64
import urllib3
@ -18,26 +36,45 @@ def singleton(cls, *args, **kw):
@singleton
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):
"""
Constructor
"""
# Default Base url
self.host = "{{basePath}}"
# Default api client
self.api_client = None
# Temp file folder
# Temp file folder for download
self.temp_folder_path = None
# Authentication Settings
# dict to store API key(s)
self.api_key = {}
# dict to store API prefix (e.g. Bearer)
self.api_key_prefix = {}
# Username for HTTP basic authentication
self.username = ""
# Password for HTTP basic authentication
self.password = ""
# Logging Settings
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
# Debug file location
self.__logging_file = None
# Debug switch
self.__debug = False
self.init_logger()
def init_logger(self):
"""
Initializes logger settings.
"""
self.logger = logging.getLogger()
formatter = logging.Formatter(self.logging_format)
stream_handler = logging.StreamHandler()
@ -82,20 +119,33 @@ class Configuration(object):
# setting log level to default `logging.WARNING`
self.logger.setLevel(logging.WARNING)
def get_api_key_with_prefix(self, key):
""" Return api key prepend prefix for key """
if self.api_key.get(key) and self.api_key_prefix.get(key):
return self.api_key_prefix[key] + ' ' + self.api_key[key]
elif self.api_key.get(key):
return self.api_key[key]
def get_api_key_with_prefix(self, identifier):
"""
Gets API key (with prefix if set).
:param identifier: The identifier of apiKey.
: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):
""" 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)\
.get('authorization')
def auth_settings(self):
""" Return Auth Settings for api client """
"""
Gets Auth Settings dict for api client.
:return: The Auth Settings information dict.
"""
return {
{{#authMethods}}
{{#isApiKey}}
@ -120,6 +170,11 @@ class Configuration(object):
}
def to_debug_report(self):
"""
Gets the essential information for debugging.
:return: The report for debugging.
"""
return "Python SDK Debug Report:\n"\
"OS: {env}\n"\
"Python Version: {pyversion}\n"\

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software
See the License for the specific language governing permissions and
limitations under the License.
"""
{{#models}}
{{#model}}
from pprint import pformat

View File

@ -1,6 +1,20 @@
# 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:
https://www.dropbox.com/developers/core/sdks/python
"""

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# coding: utf-8
import sys
from setuptools import setup, find_packages
@ -34,11 +35,3 @@ setup(
)
{{/hasMore}}{{/apis}}{{/apiInfo}}

View File

@ -1,3 +1,5 @@
# coding: utf-8
import sys
from setuptools import setup, find_packages
@ -33,11 +35,3 @@ setup(
)

View File

@ -1,10 +1,20 @@
#!/usr/bin/env python
# coding: utf-8
"""Swagger generic API client. This client handles the client-
server communication, and is invariant across implementations. Specifics of
the methods and models for each application are generated from the Swagger
templates."""
"""
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 . import models
@ -38,29 +48,47 @@ from .configuration import Configuration
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
: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
Swagger generic API client. This client handles the client-
server communication, and is invariant across implementations. Specifics of
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,
header_name=None, header_value=None):
header_name=None, header_value=None, cookie=None):
"""
Constructor of the class.
"""
self.default_headers = {}
if header_name is not None:
self.default_headers[header_name] = header_value
self.host = host
self.cookie = None
self.cookie = cookie
# Set default User-Agent.
self.user_agent = 'Python-Swagger'
@property
def user_agent(self):
"""
Gets user agent.
"""
return self.default_headers['User-Agent']
@user_agent.setter
def user_agent(self, value):
"""
Sets user agent.
"""
self.default_headers['User-Agent'] = value
def set_default_header(self, header_name, header_value):
@ -129,11 +157,12 @@ class ApiClient(object):
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:
return ','.join(obj)
@ -142,7 +171,7 @@ class ApiClient(object):
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 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 dict, return the 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)):
return None
@ -181,13 +213,13 @@ class ApiClient(object):
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
deserialzied object, or string of class name
deserialzied object, or string of class name.
:return: deserialized object
:return: deserialized object.
"""
# handle file downloading
# save response body into a tmp file and return the instance
@ -204,10 +236,12 @@ class ApiClient(object):
def __deserialize(self, data, klass):
"""
:param data: dict, list or str
:param klass: class literal, or string of class name
Deserializes dict, list, str into an object.
:return: object
:param data: dict, list or str.
:param klass: class literal, or string of class name.
:return: object.
"""
if data is None:
return None
@ -219,7 +253,7 @@ class ApiClient(object):
for sub_data in data]
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)
for k, v in iteritems(data)}
@ -248,8 +282,7 @@ class ApiClient(object):
body=None, post_params=None, files=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 method: Method to call.
@ -293,7 +326,7 @@ class ApiClient(object):
def request(self, method, url, query_params=None, headers=None,
post_params=None, body=None):
"""
Perform http request using RESTClient.
Makes the HTTP request using RESTClient.
"""
if method == "GET":
return RESTClient.GET(url,
@ -329,6 +362,13 @@ class ApiClient(object):
)
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 = {}
if post_params:
@ -350,7 +390,10 @@ class ApiClient(object):
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:
return
@ -364,7 +407,10 @@ class ApiClient(object):
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:
return 'application/json'
@ -378,7 +424,11 @@ class ApiClient(object):
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()
@ -399,12 +449,12 @@ class ApiClient(object):
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,
otherwise a random filename.
:param response: RESTResponse
:return: file path
:param response: RESTResponse.
:return: file path.
"""
config = Configuration()
@ -426,12 +476,12 @@ class ApiClient(object):
def __deserialize_primitive(self, data, klass):
"""
Deserialize string to primitive type
Deserializes string to primitive type.
:param data: str
:param klass: class literal
:param data: str.
:param klass: class literal.
:return: int, float, str, bool
:return: int, float, str, bool.
"""
try:
value = klass(data)
@ -443,16 +493,18 @@ class ApiClient(object):
def __deserialize_object(self):
"""
Deserialize empty object
Deserializes empty object.
:return: object.
"""
return object()
def __deserialize_date(self, string):
"""
Deserialize string to date
Deserializes string to date.
:param string: str
:return: date
:param string: str.
:return: date.
"""
try:
from dateutil.parser import parse
@ -468,12 +520,12 @@ class ApiClient(object):
def __deserialize_datatime(self, string):
"""
Deserialize string to datetime.
Deserializes string to datetime.
The string should be in iso8601 datetime format.
:param string: str
:return: datetime
:param string: str.
:return: datetime.
"""
try:
from dateutil.parser import parse
@ -489,10 +541,11 @@ class ApiClient(object):
def __deserialize_model(self, data, klass):
"""
Deserialize list or dict to model
Deserializes list or dict to model.
:param data: dict, list
:param klass: class literal
:param data: dict, list.
:param klass: class literal.
:return: model object.
"""
instance = klass()

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software
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.
NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
from __future__ import absolute_import
import sys
@ -33,6 +30,10 @@ from ..api_client import ApiClient
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):
config = Configuration()

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software
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.
NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
from __future__ import absolute_import
import sys
@ -33,6 +30,10 @@ from ..api_client import ApiClient
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):
config = Configuration()

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,10 +15,8 @@ Copyright 2015 SmartBear Software
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.
NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
from __future__ import absolute_import
import sys
@ -33,6 +30,10 @@ from ..api_client import ApiClient
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):
config = Configuration()

View File

@ -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
import base64
import urllib3
@ -18,26 +36,45 @@ def singleton(cls, *args, **kw):
@singleton
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):
"""
Constructor
"""
# Default Base url
self.host = "http://petstore.swagger.io/v2"
# Default api client
self.api_client = None
# Temp file folder
# Temp file folder for download
self.temp_folder_path = None
# Authentication Settings
# dict to store API key(s)
self.api_key = {}
# dict to store API prefix (e.g. Bearer)
self.api_key_prefix = {}
# Username for HTTP basic authentication
self.username = ""
# Password for HTTP basic authentication
self.password = ""
# Logging Settings
self.logging_format = '%(asctime)s %(levelname)s %(message)s'
# Debug file location
self.__logging_file = None
# Debug switch
self.__debug = False
self.init_logger()
def init_logger(self):
"""
Initializes logger settings.
"""
self.logger = logging.getLogger()
formatter = logging.Formatter(self.logging_format)
stream_handler = logging.StreamHandler()
@ -82,20 +119,33 @@ class Configuration(object):
# setting log level to default `logging.WARNING`
self.logger.setLevel(logging.WARNING)
def get_api_key_with_prefix(self, key):
""" Return api key prepend prefix for key """
if self.api_key.get(key) and self.api_key_prefix.get(key):
return self.api_key_prefix[key] + ' ' + self.api_key[key]
elif self.api_key.get(key):
return self.api_key[key]
def get_api_key_with_prefix(self, identifier):
"""
Gets API key (with prefix if set).
:param identifier: The identifier of apiKey.
: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):
""" 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)\
.get('authorization')
def auth_settings(self):
""" Return Auth Settings for api client """
"""
Gets Auth Settings dict for api client.
:return: The Auth Settings information dict.
"""
return {
'api_key':
{
@ -107,6 +157,11 @@ class Configuration(object):
}
def to_debug_report(self):
"""
Gets the essential information for debugging.
:return: The report for debugging.
"""
return "Python SDK Debug Report:\n"\
"OS: {env}\n"\
"Python Version: {pyversion}\n"\

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software
See the License for the specific language governing permissions and
limitations under the License.
"""
from pprint import pformat
from six import iteritems

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software
See the License for the specific language governing permissions and
limitations under the License.
"""
from pprint import pformat
from six import iteritems

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software
See the License for the specific language governing permissions and
limitations under the License.
"""
from pprint import pformat
from six import iteritems

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software
See the License for the specific language governing permissions and
limitations under the License.
"""
from pprint import pformat
from six import iteritems

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# coding: utf-8
"""
@ -16,6 +15,7 @@ Copyright 2015 SmartBear Software
See the License for the specific language governing permissions and
limitations under the License.
"""
from pprint import pformat
from six import iteritems

View File

@ -1,6 +1,20 @@
# 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:
https://www.dropbox.com/developers/core/sdks/python
"""

View File

@ -150,6 +150,28 @@ class DeserializationTests(unittest.TestCase):
self.assertEqual(deserialized[0].name, "doggie0")
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):
""" deserialize None """
deserialized = self.deserialize(None, "datetime")