Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class ApiClient(object):
self.cookie = cookie
# Set default User-Agent.
self.user_agent = '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{{packageVersion}}}/python{{/httpUserAgent}}'

def __del__(self):
self.pool.close()
self.pool.join()

@property
def user_agent(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3-SNAPSHOT
2.3.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore-security-test/python/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# petstore_api
# petstore-api
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end --

This Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import json
import mimetypes
import tempfile
import threading
from multiprocessing.pool import ThreadPool

from datetime import date, datetime

Expand Down Expand Up @@ -64,13 +64,18 @@ def __init__(self, configuration=None, header_name=None, header_value=None, cook
configuration = Configuration()
self.configuration = configuration

self.pool = ThreadPool()
self.rest_client = RESTClientObject(configuration)
self.default_headers = {}
if header_name is not None:
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
self.user_agent = 'Swagger-Codegen/1.0.0/python'

def __del__(self):
self.pool.close()
self.pool.join()

@property
def user_agent(self):
Expand All @@ -92,11 +97,11 @@ def set_default_header(self, header_name, header_value):
def __call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
response_type=None, auth_settings=None, callback=None,
response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=None, _preload_content=True,
_request_timeout=None):

config = Configuration()
config = self.configuration

# header parameters
header_params = header_params or {}
Expand Down Expand Up @@ -159,12 +164,7 @@ def __call_api(self, resource_path, method,
else:
return_data = None

if callback:
if _return_http_data_only:
callback(return_data)
else:
callback((return_data, response_data.status, response_data.getheaders()))
elif _return_http_data_only:
if _return_http_data_only:
return (return_data)
else:
return (return_data, response_data.status, response_data.getheaders())
Expand Down Expand Up @@ -278,7 +278,7 @@ def __deserialize(self, data, klass):
def call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
response_type=None, auth_settings=None, callback=None,
response_type=None, auth_settings=None, async=None,
_return_http_data_only=None, collection_formats=None, _preload_content=True,
_request_timeout=None):
"""
Expand All @@ -298,9 +298,7 @@ def call_api(self, resource_path, method,
:param response: Response data type.
:param files dict: key -> filename, value -> filepath,
for `multipart/form-data`.
:param callback function: Callback function for asynchronous request.
If provide this parameter,
the request will be called asynchronously.
:param async bool: execute request asynchronously
:param _return_http_data_only: response data without head status code and headers
:param collection_formats: dict of collection formats for path, query,
header, and post parameters.
Expand All @@ -315,22 +313,20 @@ def call_api(self, resource_path, method,
If parameter callback is None,
then the method will return the response directly.
"""
if callback is None:
if not async:
return self.__call_api(resource_path, method,
path_params, query_params, header_params,
body, post_params, files,
response_type, auth_settings, callback,
response_type, auth_settings,
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
else:
thread = threading.Thread(target=self.__call_api,
args=(resource_path, method,
path_params, query_params,
header_params, body,
post_params, files,
response_type, auth_settings,
callback, _return_http_data_only,
collection_formats, _preload_content, _request_timeout))
thread.start()
thread = self.pool.apply_async(self.__call_api, (resource_path, method,
path_params, query_params,
header_params, body,
post_params, files,
response_type, auth_settings,
_return_http_data_only,
collection_formats, _preload_content, _request_timeout))
return thread

def request(self, method, url, query_params=None, headers=None,
Expand Down Expand Up @@ -610,17 +606,23 @@ def __deserialize_model(self, data, klass):
:param klass: class literal.
:return: model object.
"""
if not klass.swagger_types:

if not klass.swagger_types and not hasattr(klass, 'get_real_child_model'):
return data

kwargs = {}
for attr, attr_type in iteritems(klass.swagger_types):
if data is not None \
and klass.attribute_map[attr] in data \
and isinstance(data, (list, dict)):
value = data[klass.attribute_map[attr]]
kwargs[attr] = self.__deserialize(value, attr_type)

instance = klass(**kwargs)

if klass.swagger_types is not None:
for attr, attr_type in iteritems(klass.swagger_types):
if data is not None \
and klass.attribute_map[attr] in data \
and isinstance(data, (list, dict)):
value = data[klass.attribute_map[attr]]
kwargs[attr] = self.__deserialize(value, attr_type)

instance = klass(**kwargs)

if hasattr(instance, 'get_real_child_model'):
klass_name = instance.get_real_child_model(data)
if klass_name:
instance = self.__deserialize(data, klass_name)
return instance
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,18 @@ def test_code_inject____end__rn_n_r(self, **kwargs):
"""
To test code injection */ ' \" =end -- \\r\\n \\n \\r
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
>>> def callback_function(response):
>>> pprint(response)
>>>
>>> thread = api.test_code_inject____end__rn_n_r(callback=callback_function)

:param callback function: The callback function
for asynchronous request. (optional)
asynchronous HTTP request, please pass async=True
>>> thread = api.test_code_inject____end__rn_n_r(async=True)
>>> result = thread.get()

:param async bool
:param str test_code_inject____end____rn_n_r: To test code injection */ ' \" =end -- \\r\\n \\n \\r
:return: None
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('callback'):
if kwargs.get('async'):
return self.test_code_inject____end__rn_n_r_with_http_info(**kwargs)
else:
(data) = self.test_code_inject____end__rn_n_r_with_http_info(**kwargs)
Expand All @@ -64,23 +60,19 @@ def test_code_inject____end__rn_n_r_with_http_info(self, **kwargs):
"""
To test code injection */ ' \" =end -- \\r\\n \\n \\r
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
>>> def callback_function(response):
>>> pprint(response)
>>>
>>> thread = api.test_code_inject____end__rn_n_r_with_http_info(callback=callback_function)

:param callback function: The callback function
for asynchronous request. (optional)
asynchronous HTTP request, please pass async=True
>>> thread = api.test_code_inject____end__rn_n_r_with_http_info(async=True)
>>> result = thread.get()

:param async bool
:param str test_code_inject____end____rn_n_r: To test code injection */ ' \" =end -- \\r\\n \\n \\r
:return: None
If the method is called asynchronously,
returns the request thread.
"""

all_params = ['test_code_inject____end____rn_n_r']
all_params.append('callback')
all_params.append('async')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
Expand Down Expand Up @@ -130,7 +122,7 @@ def test_code_inject____end__rn_n_r_with_http_info(self, **kwargs):
files=local_var_files,
response_type=None,
auth_settings=auth_settings,
callback=params.get('callback'),
async=params.get('async'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, _return=None):
"""

self.__return = None
self.discriminator = None

if _return is not None:
self._return = _return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def __init__(self, configuration, pools_size=4, maxsize=4):
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680
# maxsize is the number of requests to host that are allowed in parallel
# ca_certs vs cert_file vs key_file
# http://stackoverflow.com/a/23957365/2985775
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html

# cert_reqs
if configuration.verify_ssl:
Expand Down Expand Up @@ -142,7 +141,7 @@ def request(self, method, url, query_params=None, headers=None,
url += '?' + urlencode(query_params)
if re.search('json', headers['Content-Type'], re.IGNORECASE):
request_body = None
if body:
if body is not None:
request_body = json.dumps(body)
r = self.pool_manager.request(method, url,
body=request_body,
Expand Down Expand Up @@ -203,7 +202,7 @@ def request(self, method, url, query_params=None, headers=None,
# log response body
logger.debug("response body: %s", r.data)

if r.status not in range(200, 206):
if not 200 <= r.status <= 299:
raise ApiException(http_resp=r)

return r
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore-security-test/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import sys
from setuptools import setup, find_packages

NAME = "petstore_api"
NAME = "petstore-api"
VERSION = "1.0.0"
# To install the library, run the following
#
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This endpoint does not need any parameter.

### Return type

[**dict(str, int)**](dict.md)
**dict(str, int)**

### Authorization

Expand Down
4 changes: 4 additions & 0 deletions samples/client/petstore/python/petstore_api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def __init__(self, configuration=None, header_name=None, header_value=None, cook
self.cookie = cookie
# Set default User-Agent.
self.user_agent = 'Swagger-Codegen/1.0.0/python'

def __del__(self):
self.pool.close()
self.pool.join()

@property
def user_agent(self):
Expand Down