docspring 3.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docspring/__init__.py +250 -0
- docspring/api/__init__.py +20 -0
- docspring/api/client.py +13430 -0
- docspring/api_client.py +805 -0
- docspring/api_response.py +21 -0
- docspring/configuration.py +598 -0
- docspring/exceptions.py +217 -0
- docspring/models/__init__.py +146 -0
- docspring/models/add_fields_data.py +88 -0
- docspring/models/batch_generate_pdfs201_response.py +111 -0
- docspring/models/combine_pdfs_data.py +98 -0
- docspring/models/combined_submission.py +173 -0
- docspring/models/combined_submission_action.py +156 -0
- docspring/models/copy_template_options.py +92 -0
- docspring/models/create_combined_submission_response.py +107 -0
- docspring/models/create_custom_file_data.py +89 -0
- docspring/models/create_custom_file_response.py +107 -0
- docspring/models/create_folder_data.py +88 -0
- docspring/models/create_html_template.py +88 -0
- docspring/models/create_pdf_submission_data.py +112 -0
- docspring/models/create_pdf_template.py +88 -0
- docspring/models/create_submission_data_request_data.py +187 -0
- docspring/models/create_submission_data_request_event_request.py +134 -0
- docspring/models/create_submission_data_request_event_response.py +107 -0
- docspring/models/create_submission_data_request_response.py +107 -0
- docspring/models/create_submission_data_request_token_response.py +107 -0
- docspring/models/create_submission_response.py +107 -0
- docspring/models/create_webhook_data.py +88 -0
- docspring/models/custom_file.py +100 -0
- docspring/models/error_or_multiple_errors_response.py +103 -0
- docspring/models/error_response.py +101 -0
- docspring/models/folder.py +114 -0
- docspring/models/json_schema.py +110 -0
- docspring/models/list_submissions_response.py +105 -0
- docspring/models/move_folder_data.py +93 -0
- docspring/models/move_template_data.py +95 -0
- docspring/models/multiple_errors_response.py +101 -0
- docspring/models/publish_version_data.py +90 -0
- docspring/models/rename_folder_data.py +88 -0
- docspring/models/restore_version_data.py +88 -0
- docspring/models/submission.py +287 -0
- docspring/models/submission422_response.py +109 -0
- docspring/models/submission_action.py +148 -0
- docspring/models/submission_batch.py +123 -0
- docspring/models/submission_batch_data.py +106 -0
- docspring/models/submission_batch_with_submissions.py +133 -0
- docspring/models/submission_data_request.py +253 -0
- docspring/models/submission_data_request_event.py +155 -0
- docspring/models/submission_data_request_show.py +260 -0
- docspring/models/submission_data_request_token.py +109 -0
- docspring/models/submission_preview.py +257 -0
- docspring/models/success_error_response.py +101 -0
- docspring/models/success_multiple_errors_response.py +101 -0
- docspring/models/template.py +402 -0
- docspring/models/template_add_fields_response.py +103 -0
- docspring/models/template_delete_response.py +110 -0
- docspring/models/template_model_code_response.py +103 -0
- docspring/models/template_preview.py +356 -0
- docspring/models/template_publish_version_response.py +103 -0
- docspring/models/update_html_template.py +88 -0
- docspring/models/update_pdf_template.py +88 -0
- docspring/models/update_submission_data_request_data.py +185 -0
- docspring/models/update_webhook_data.py +88 -0
- docspring/models/upload_presign_response.py +108 -0
- docspring/models/webhook.py +185 -0
- docspring/py.typed +0 -0
- docspring/rest.py +259 -0
- docspring-3.1.0.dist-info/METADATA +245 -0
- docspring-3.1.0.dist-info/RECORD +72 -0
- docspring-3.1.0.dist-info/WHEEL +5 -0
- docspring-3.1.0.dist-info/licenses/LICENSE +7 -0
- docspring-3.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
DocSpring API
|
|
5
|
+
|
|
6
|
+
Use DocSpring's API to programmatically fill out PDF forms, convert HTML to PDFs, merge PDFs, or request legally binding e-signatures.
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: v1
|
|
9
|
+
Contact: support@docspring.com
|
|
10
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
11
|
+
|
|
12
|
+
Do not edit the class manually.
|
|
13
|
+
""" # noqa: E501
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
import pprint
|
|
18
|
+
import re # noqa: F401
|
|
19
|
+
import json
|
|
20
|
+
|
|
21
|
+
from pydantic import BaseModel, ConfigDict, StrictBool, StrictInt, StrictStr, ValidationInfo, field_validator
|
|
22
|
+
from typing import Any, ClassVar, Dict, List, Optional
|
|
23
|
+
from typing import Optional, Set
|
|
24
|
+
from typing_extensions import Self
|
|
25
|
+
|
|
26
|
+
class Webhook(BaseModel):
|
|
27
|
+
"""
|
|
28
|
+
Webhook
|
|
29
|
+
""" # noqa: E501
|
|
30
|
+
id: StrictStr
|
|
31
|
+
name: Optional[StrictStr]
|
|
32
|
+
url: Optional[StrictStr]
|
|
33
|
+
enabled: StrictBool
|
|
34
|
+
event_types: List[StrictStr]
|
|
35
|
+
mode: Optional[StrictStr]
|
|
36
|
+
version: StrictInt
|
|
37
|
+
api_token_ids: List[StrictStr]
|
|
38
|
+
template_ids: List[StrictStr]
|
|
39
|
+
folder_ids: List[StrictStr]
|
|
40
|
+
include_submission_data: StrictBool
|
|
41
|
+
strip_fields: List[StrictStr]
|
|
42
|
+
headers: Dict[str, StrictStr]
|
|
43
|
+
consecutive_failures: StrictInt
|
|
44
|
+
last_failure_at: Optional[StrictStr]
|
|
45
|
+
disabled_at: Optional[StrictStr]
|
|
46
|
+
disabled_reason: Optional[StrictStr]
|
|
47
|
+
secret: Optional[StrictStr]
|
|
48
|
+
created_at: Optional[StrictStr]
|
|
49
|
+
updated_at: Optional[StrictStr]
|
|
50
|
+
__properties: ClassVar[List[str]] = ["id", "name", "url", "enabled", "event_types", "mode", "version", "api_token_ids", "template_ids", "folder_ids", "include_submission_data", "strip_fields", "headers", "consecutive_failures", "last_failure_at", "disabled_at", "disabled_reason", "secret", "created_at", "updated_at"]
|
|
51
|
+
|
|
52
|
+
@field_validator('mode')
|
|
53
|
+
def mode_validate_enum(cls, value, info: ValidationInfo):
|
|
54
|
+
"""Validates the enum"""
|
|
55
|
+
# from_dict accepts enum values this client doesn't know about yet
|
|
56
|
+
if info.context and info.context.get("skip_enum_validation"):
|
|
57
|
+
return value
|
|
58
|
+
|
|
59
|
+
if value is None:
|
|
60
|
+
return value
|
|
61
|
+
|
|
62
|
+
if value not in set(['test', 'live']):
|
|
63
|
+
raise ValueError("must be one of enum values ('test', 'live')")
|
|
64
|
+
return value
|
|
65
|
+
|
|
66
|
+
model_config = ConfigDict(
|
|
67
|
+
populate_by_name=True,
|
|
68
|
+
validate_assignment=True,
|
|
69
|
+
protected_namespaces=(),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def to_str(self) -> str:
|
|
74
|
+
"""Returns the string representation of the model using alias"""
|
|
75
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
76
|
+
|
|
77
|
+
def to_json(self) -> str:
|
|
78
|
+
"""Returns the JSON representation of the model using alias"""
|
|
79
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
80
|
+
return json.dumps(self.to_dict())
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
84
|
+
"""Create an instance of Webhook from a JSON string"""
|
|
85
|
+
return cls.from_dict(json.loads(json_str))
|
|
86
|
+
|
|
87
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
88
|
+
"""Return the dictionary representation of the model using alias.
|
|
89
|
+
|
|
90
|
+
This has the following differences from calling pydantic's
|
|
91
|
+
`self.model_dump(by_alias=True)`:
|
|
92
|
+
|
|
93
|
+
* `None` is only added to the output dict for nullable fields that
|
|
94
|
+
were set at model initialization. Other fields with value `None`
|
|
95
|
+
are ignored.
|
|
96
|
+
"""
|
|
97
|
+
excluded_fields: Set[str] = set([
|
|
98
|
+
])
|
|
99
|
+
|
|
100
|
+
_dict = self.model_dump(
|
|
101
|
+
by_alias=True,
|
|
102
|
+
exclude=excluded_fields,
|
|
103
|
+
exclude_none=True,
|
|
104
|
+
)
|
|
105
|
+
# set to None if name (nullable) is None
|
|
106
|
+
# and model_fields_set contains the field
|
|
107
|
+
if self.name is None and "name" in self.model_fields_set:
|
|
108
|
+
_dict['name'] = None
|
|
109
|
+
|
|
110
|
+
# set to None if url (nullable) is None
|
|
111
|
+
# and model_fields_set contains the field
|
|
112
|
+
if self.url is None and "url" in self.model_fields_set:
|
|
113
|
+
_dict['url'] = None
|
|
114
|
+
|
|
115
|
+
# set to None if mode (nullable) is None
|
|
116
|
+
# and model_fields_set contains the field
|
|
117
|
+
if self.mode is None and "mode" in self.model_fields_set:
|
|
118
|
+
_dict['mode'] = None
|
|
119
|
+
|
|
120
|
+
# set to None if last_failure_at (nullable) is None
|
|
121
|
+
# and model_fields_set contains the field
|
|
122
|
+
if self.last_failure_at is None and "last_failure_at" in self.model_fields_set:
|
|
123
|
+
_dict['last_failure_at'] = None
|
|
124
|
+
|
|
125
|
+
# set to None if disabled_at (nullable) is None
|
|
126
|
+
# and model_fields_set contains the field
|
|
127
|
+
if self.disabled_at is None and "disabled_at" in self.model_fields_set:
|
|
128
|
+
_dict['disabled_at'] = None
|
|
129
|
+
|
|
130
|
+
# set to None if disabled_reason (nullable) is None
|
|
131
|
+
# and model_fields_set contains the field
|
|
132
|
+
if self.disabled_reason is None and "disabled_reason" in self.model_fields_set:
|
|
133
|
+
_dict['disabled_reason'] = None
|
|
134
|
+
|
|
135
|
+
# set to None if secret (nullable) is None
|
|
136
|
+
# and model_fields_set contains the field
|
|
137
|
+
if self.secret is None and "secret" in self.model_fields_set:
|
|
138
|
+
_dict['secret'] = None
|
|
139
|
+
|
|
140
|
+
# set to None if created_at (nullable) is None
|
|
141
|
+
# and model_fields_set contains the field
|
|
142
|
+
if self.created_at is None and "created_at" in self.model_fields_set:
|
|
143
|
+
_dict['created_at'] = None
|
|
144
|
+
|
|
145
|
+
# set to None if updated_at (nullable) is None
|
|
146
|
+
# and model_fields_set contains the field
|
|
147
|
+
if self.updated_at is None and "updated_at" in self.model_fields_set:
|
|
148
|
+
_dict['updated_at'] = None
|
|
149
|
+
|
|
150
|
+
return _dict
|
|
151
|
+
|
|
152
|
+
@classmethod
|
|
153
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
154
|
+
"""Create an instance of Webhook from a dict"""
|
|
155
|
+
if obj is None:
|
|
156
|
+
return None
|
|
157
|
+
|
|
158
|
+
if not isinstance(obj, dict):
|
|
159
|
+
return cls.model_validate(obj, context={"skip_enum_validation": True})
|
|
160
|
+
|
|
161
|
+
_obj = cls.model_validate({
|
|
162
|
+
"id": obj.get("id"),
|
|
163
|
+
"name": obj.get("name"),
|
|
164
|
+
"url": obj.get("url"),
|
|
165
|
+
"enabled": obj.get("enabled"),
|
|
166
|
+
"event_types": obj.get("event_types"),
|
|
167
|
+
"mode": obj.get("mode"),
|
|
168
|
+
"version": obj.get("version"),
|
|
169
|
+
"api_token_ids": obj.get("api_token_ids"),
|
|
170
|
+
"template_ids": obj.get("template_ids"),
|
|
171
|
+
"folder_ids": obj.get("folder_ids"),
|
|
172
|
+
"include_submission_data": obj.get("include_submission_data"),
|
|
173
|
+
"strip_fields": obj.get("strip_fields"),
|
|
174
|
+
"headers": obj.get("headers"),
|
|
175
|
+
"consecutive_failures": obj.get("consecutive_failures"),
|
|
176
|
+
"last_failure_at": obj.get("last_failure_at"),
|
|
177
|
+
"disabled_at": obj.get("disabled_at"),
|
|
178
|
+
"disabled_reason": obj.get("disabled_reason"),
|
|
179
|
+
"secret": obj.get("secret"),
|
|
180
|
+
"created_at": obj.get("created_at"),
|
|
181
|
+
"updated_at": obj.get("updated_at")
|
|
182
|
+
}, context={"skip_enum_validation": True})
|
|
183
|
+
return _obj
|
|
184
|
+
|
|
185
|
+
|
docspring/py.typed
ADDED
|
File without changes
|
docspring/rest.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
DocSpring API
|
|
5
|
+
|
|
6
|
+
Use DocSpring's API to programmatically fill out PDF forms, convert HTML to PDFs, merge PDFs, or request legally binding e-signatures.
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: v1
|
|
9
|
+
Contact: support@docspring.com
|
|
10
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
11
|
+
|
|
12
|
+
Do not edit the class manually.
|
|
13
|
+
""" # noqa: E501
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import io
|
|
17
|
+
import json
|
|
18
|
+
import re
|
|
19
|
+
import ssl
|
|
20
|
+
|
|
21
|
+
import urllib3
|
|
22
|
+
|
|
23
|
+
from docspring.exceptions import ApiException, ApiValueError
|
|
24
|
+
|
|
25
|
+
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
|
26
|
+
RESTResponseType = urllib3.HTTPResponse
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def is_socks_proxy_url(url):
|
|
30
|
+
if url is None:
|
|
31
|
+
return False
|
|
32
|
+
split_section = url.split("://")
|
|
33
|
+
if len(split_section) < 2:
|
|
34
|
+
return False
|
|
35
|
+
else:
|
|
36
|
+
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class RESTResponse(io.IOBase):
|
|
40
|
+
|
|
41
|
+
def __init__(self, resp) -> None:
|
|
42
|
+
self.response = resp
|
|
43
|
+
self.status = resp.status
|
|
44
|
+
self.reason = resp.reason
|
|
45
|
+
self.data = None
|
|
46
|
+
|
|
47
|
+
def read(self):
|
|
48
|
+
if self.data is None:
|
|
49
|
+
self.data = self.response.data
|
|
50
|
+
return self.data
|
|
51
|
+
|
|
52
|
+
def getheaders(self):
|
|
53
|
+
"""Returns a dictionary of the response headers."""
|
|
54
|
+
return self.response.headers
|
|
55
|
+
|
|
56
|
+
def getheader(self, name, default=None):
|
|
57
|
+
"""Returns a given response header."""
|
|
58
|
+
return self.response.headers.get(name, default)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class RESTClientObject:
|
|
62
|
+
|
|
63
|
+
def __init__(self, configuration) -> None:
|
|
64
|
+
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
|
65
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
|
|
66
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
|
|
67
|
+
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
|
|
68
|
+
|
|
69
|
+
# cert_reqs
|
|
70
|
+
if configuration.verify_ssl:
|
|
71
|
+
cert_reqs = ssl.CERT_REQUIRED
|
|
72
|
+
else:
|
|
73
|
+
cert_reqs = ssl.CERT_NONE
|
|
74
|
+
|
|
75
|
+
pool_args = {
|
|
76
|
+
"cert_reqs": cert_reqs,
|
|
77
|
+
"ca_certs": configuration.ssl_ca_cert,
|
|
78
|
+
"cert_file": configuration.cert_file,
|
|
79
|
+
"key_file": configuration.key_file,
|
|
80
|
+
"ca_cert_data": configuration.ca_cert_data,
|
|
81
|
+
}
|
|
82
|
+
if configuration.assert_hostname is not None:
|
|
83
|
+
pool_args['assert_hostname'] = (
|
|
84
|
+
configuration.assert_hostname
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
if configuration.retries is not None:
|
|
88
|
+
pool_args['retries'] = configuration.retries
|
|
89
|
+
|
|
90
|
+
if configuration.tls_server_name:
|
|
91
|
+
pool_args['server_hostname'] = configuration.tls_server_name
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if configuration.socket_options is not None:
|
|
95
|
+
pool_args['socket_options'] = configuration.socket_options
|
|
96
|
+
|
|
97
|
+
if configuration.connection_pool_maxsize is not None:
|
|
98
|
+
pool_args['maxsize'] = configuration.connection_pool_maxsize
|
|
99
|
+
|
|
100
|
+
# https pool manager
|
|
101
|
+
self.pool_manager: urllib3.PoolManager
|
|
102
|
+
|
|
103
|
+
if configuration.proxy:
|
|
104
|
+
if is_socks_proxy_url(configuration.proxy):
|
|
105
|
+
from urllib3.contrib.socks import SOCKSProxyManager
|
|
106
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
107
|
+
pool_args["headers"] = configuration.proxy_headers
|
|
108
|
+
self.pool_manager = SOCKSProxyManager(**pool_args)
|
|
109
|
+
else:
|
|
110
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
111
|
+
pool_args["proxy_headers"] = configuration.proxy_headers
|
|
112
|
+
self.pool_manager = urllib3.ProxyManager(**pool_args)
|
|
113
|
+
else:
|
|
114
|
+
self.pool_manager = urllib3.PoolManager(**pool_args)
|
|
115
|
+
|
|
116
|
+
def request(
|
|
117
|
+
self,
|
|
118
|
+
method,
|
|
119
|
+
url,
|
|
120
|
+
headers=None,
|
|
121
|
+
body=None,
|
|
122
|
+
post_params=None,
|
|
123
|
+
_request_timeout=None
|
|
124
|
+
):
|
|
125
|
+
"""Perform requests.
|
|
126
|
+
|
|
127
|
+
:param method: http request method
|
|
128
|
+
:param url: http request url
|
|
129
|
+
:param headers: http request headers
|
|
130
|
+
:param body: request json body, for `application/json`
|
|
131
|
+
:param post_params: request post parameters,
|
|
132
|
+
`application/x-www-form-urlencoded`
|
|
133
|
+
and `multipart/form-data`
|
|
134
|
+
:param _request_timeout: timeout setting for this request. If one
|
|
135
|
+
number provided, it will be total request
|
|
136
|
+
timeout. It can also be a pair (tuple) of
|
|
137
|
+
(connection, read) timeouts.
|
|
138
|
+
"""
|
|
139
|
+
method = method.upper()
|
|
140
|
+
assert method in [
|
|
141
|
+
'GET',
|
|
142
|
+
'HEAD',
|
|
143
|
+
'DELETE',
|
|
144
|
+
'POST',
|
|
145
|
+
'PUT',
|
|
146
|
+
'PATCH',
|
|
147
|
+
'OPTIONS'
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
if post_params and body:
|
|
151
|
+
raise ApiValueError(
|
|
152
|
+
"body parameter cannot be used with post_params parameter."
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
post_params = post_params or {}
|
|
156
|
+
headers = headers or {}
|
|
157
|
+
|
|
158
|
+
timeout = None
|
|
159
|
+
if _request_timeout:
|
|
160
|
+
if isinstance(_request_timeout, (int, float)):
|
|
161
|
+
timeout = urllib3.Timeout(total=_request_timeout)
|
|
162
|
+
elif (
|
|
163
|
+
isinstance(_request_timeout, tuple)
|
|
164
|
+
and len(_request_timeout) == 2
|
|
165
|
+
):
|
|
166
|
+
timeout = urllib3.Timeout(
|
|
167
|
+
connect=_request_timeout[0],
|
|
168
|
+
read=_request_timeout[1]
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
try:
|
|
172
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
|
173
|
+
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
|
|
174
|
+
|
|
175
|
+
# no content type provided or payload is json
|
|
176
|
+
content_type = headers.get('Content-Type')
|
|
177
|
+
if (
|
|
178
|
+
not content_type
|
|
179
|
+
or re.search('json', content_type, re.IGNORECASE)
|
|
180
|
+
):
|
|
181
|
+
request_body = None
|
|
182
|
+
if body is not None:
|
|
183
|
+
request_body = json.dumps(body)
|
|
184
|
+
r = self.pool_manager.request(
|
|
185
|
+
method,
|
|
186
|
+
url,
|
|
187
|
+
body=request_body,
|
|
188
|
+
timeout=timeout,
|
|
189
|
+
headers=headers,
|
|
190
|
+
preload_content=False
|
|
191
|
+
)
|
|
192
|
+
elif content_type == 'application/x-www-form-urlencoded':
|
|
193
|
+
r = self.pool_manager.request(
|
|
194
|
+
method,
|
|
195
|
+
url,
|
|
196
|
+
fields=post_params,
|
|
197
|
+
encode_multipart=False,
|
|
198
|
+
timeout=timeout,
|
|
199
|
+
headers=headers,
|
|
200
|
+
preload_content=False
|
|
201
|
+
)
|
|
202
|
+
elif content_type == 'multipart/form-data':
|
|
203
|
+
# must del headers['Content-Type'], or the correct
|
|
204
|
+
# Content-Type which generated by urllib3 will be
|
|
205
|
+
# overwritten.
|
|
206
|
+
del headers['Content-Type']
|
|
207
|
+
# Ensures that dict objects are serialized
|
|
208
|
+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
|
|
209
|
+
r = self.pool_manager.request(
|
|
210
|
+
method,
|
|
211
|
+
url,
|
|
212
|
+
fields=post_params,
|
|
213
|
+
encode_multipart=True,
|
|
214
|
+
timeout=timeout,
|
|
215
|
+
headers=headers,
|
|
216
|
+
preload_content=False
|
|
217
|
+
)
|
|
218
|
+
# Pass a `string` parameter directly in the body to support
|
|
219
|
+
# other content types than JSON when `body` argument is
|
|
220
|
+
# provided in serialized form.
|
|
221
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
|
222
|
+
r = self.pool_manager.request(
|
|
223
|
+
method,
|
|
224
|
+
url,
|
|
225
|
+
body=body,
|
|
226
|
+
timeout=timeout,
|
|
227
|
+
headers=headers,
|
|
228
|
+
preload_content=False
|
|
229
|
+
)
|
|
230
|
+
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
|
|
231
|
+
request_body = "true" if body else "false"
|
|
232
|
+
r = self.pool_manager.request(
|
|
233
|
+
method,
|
|
234
|
+
url,
|
|
235
|
+
body=request_body,
|
|
236
|
+
preload_content=False,
|
|
237
|
+
timeout=timeout,
|
|
238
|
+
headers=headers)
|
|
239
|
+
else:
|
|
240
|
+
# Cannot generate the request from given parameters
|
|
241
|
+
msg = """Cannot prepare a request message for provided
|
|
242
|
+
arguments. Please check that your arguments match
|
|
243
|
+
declared content type."""
|
|
244
|
+
raise ApiException(status=0, reason=msg)
|
|
245
|
+
# For `GET`, `HEAD`
|
|
246
|
+
else:
|
|
247
|
+
r = self.pool_manager.request(
|
|
248
|
+
method,
|
|
249
|
+
url,
|
|
250
|
+
fields={},
|
|
251
|
+
timeout=timeout,
|
|
252
|
+
headers=headers,
|
|
253
|
+
preload_content=False
|
|
254
|
+
)
|
|
255
|
+
except urllib3.exceptions.SSLError as e:
|
|
256
|
+
msg = "\n".join([type(e).__name__, str(e)])
|
|
257
|
+
raise ApiException(status=0, reason=msg)
|
|
258
|
+
|
|
259
|
+
return RESTResponse(r)
|