restpki-ng-python-client 0.9.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.
- restpki_ng_python_client/__init__.py +200 -0
- restpki_ng_python_client/api/__init__.py +17 -0
- restpki_ng_python_client/api/authentication_api.py +2041 -0
- restpki_ng_python_client/api/cades_signature_api.py +2376 -0
- restpki_ng_python_client/api/document_keys_api.py +1199 -0
- restpki_ng_python_client/api/documents_api.py +868 -0
- restpki_ng_python_client/api/pades_signature_api.py +1797 -0
- restpki_ng_python_client/api/pades_visual_positioning_presets_api.py +869 -0
- restpki_ng_python_client/api/pdf_api.py +334 -0
- restpki_ng_python_client/api/signature_api.py +624 -0
- restpki_ng_python_client/api/signature_inspection_api.py +337 -0
- restpki_ng_python_client/api/signature_sessions_api.py +891 -0
- restpki_ng_python_client/api/timestamp_api.py +654 -0
- restpki_ng_python_client/api/upload_api.py +1124 -0
- restpki_ng_python_client/api/xml_signature_api.py +1781 -0
- restpki_ng_python_client/api_client.py +741 -0
- restpki_ng_python_client/api_response.py +21 -0
- restpki_ng_python_client/configuration.py +426 -0
- restpki_ng_python_client/exceptions.py +166 -0
- restpki_ng_python_client/file_utils.py +122 -0
- restpki_ng_python_client/models/__init__.py +165 -0
- restpki_ng_python_client/models/allocate_document_key_batch_request.py +96 -0
- restpki_ng_python_client/models/allocate_document_key_request.py +93 -0
- restpki_ng_python_client/models/attribute_certificate_model.py +141 -0
- restpki_ng_python_client/models/audit_package_options.py +90 -0
- restpki_ng_python_client/models/authentication_failures.py +45 -0
- restpki_ng_python_client/models/authentication_get_response.py +92 -0
- restpki_ng_python_client/models/authentication_post_request.py +116 -0
- restpki_ng_python_client/models/authentication_post_response.py +98 -0
- restpki_ng_python_client/models/authentications_post_request.py +95 -0
- restpki_ng_python_client/models/authentications_post_response.py +114 -0
- restpki_ng_python_client/models/authentications_post_signed_bytes_request.py +99 -0
- restpki_ng_python_client/models/authentications_post_signed_bytes_response.py +98 -0
- restpki_ng_python_client/models/auto_positioning_horizontal_directions.py +45 -0
- restpki_ng_python_client/models/auto_positioning_vertical_directions.py +45 -0
- restpki_ng_python_client/models/blockchains.py +45 -0
- restpki_ng_python_client/models/cades_signature_model.py +123 -0
- restpki_ng_python_client/models/cades_signature_post_request_v1.py +137 -0
- restpki_ng_python_client/models/cades_signature_post_request_v2.py +152 -0
- restpki_ng_python_client/models/cades_signature_post_request_v3.py +149 -0
- restpki_ng_python_client/models/cades_signature_post_response.py +120 -0
- restpki_ng_python_client/models/cades_signature_post_signed_bytes_request.py +92 -0
- restpki_ng_python_client/models/cades_signature_post_signed_bytes_response.py +106 -0
- restpki_ng_python_client/models/cades_signer_model.py +159 -0
- restpki_ng_python_client/models/cades_timestamp_model.py +140 -0
- restpki_ng_python_client/models/certificate_model.py +197 -0
- restpki_ng_python_client/models/certificate_reference_model.py +99 -0
- restpki_ng_python_client/models/certificate_requirement.py +95 -0
- restpki_ng_python_client/models/certificate_requirement_types.py +45 -0
- restpki_ng_python_client/models/certificate_summary.py +142 -0
- restpki_ng_python_client/models/certified_attribute_model.py +94 -0
- restpki_ng_python_client/models/certified_attribute_types.py +44 -0
- restpki_ng_python_client/models/cms_content_types.py +50 -0
- restpki_ng_python_client/models/cms_signature_options.py +109 -0
- restpki_ng_python_client/models/color_model.py +98 -0
- restpki_ng_python_client/models/commitment_type_model.py +99 -0
- restpki_ng_python_client/models/complete_authentication_request.py +93 -0
- restpki_ng_python_client/models/complete_authentication_response.py +103 -0
- restpki_ng_python_client/models/complete_signature_request.py +95 -0
- restpki_ng_python_client/models/complete_signature_request_v2.py +91 -0
- restpki_ng_python_client/models/create_signature_session_request.py +161 -0
- restpki_ng_python_client/models/create_signature_session_response.py +95 -0
- restpki_ng_python_client/models/digest_algorithm_and_value_model.py +103 -0
- restpki_ng_python_client/models/digest_algorithms.py +49 -0
- restpki_ng_python_client/models/document_file_model.py +137 -0
- restpki_ng_python_client/models/document_key_model.py +100 -0
- restpki_ng_python_client/models/document_key_query_response.py +110 -0
- restpki_ng_python_client/models/document_key_summary.py +100 -0
- restpki_ng_python_client/models/document_model.py +150 -0
- restpki_ng_python_client/models/document_query_response.py +93 -0
- restpki_ng_python_client/models/document_status.py +47 -0
- restpki_ng_python_client/models/document_summary.py +128 -0
- restpki_ng_python_client/models/error_model_v2.py +120 -0
- restpki_ng_python_client/models/file_model.py +114 -0
- restpki_ng_python_client/models/file_reference_model.py +137 -0
- restpki_ng_python_client/models/full_xml_signature_post_request.py +136 -0
- restpki_ng_python_client/models/general_name_choices.py +52 -0
- restpki_ng_python_client/models/general_name_model.py +108 -0
- restpki_ng_python_client/models/holder_types.py +45 -0
- restpki_ng_python_client/models/inspect_signature_failures.py +44 -0
- restpki_ng_python_client/models/inspect_signature_request.py +127 -0
- restpki_ng_python_client/models/inspect_signature_response.py +131 -0
- restpki_ng_python_client/models/multipart_upload_begin_response.py +95 -0
- restpki_ng_python_client/models/multipart_upload_end_request.py +95 -0
- restpki_ng_python_client/models/name_model.py +205 -0
- restpki_ng_python_client/models/namespace_model.py +99 -0
- restpki_ng_python_client/models/open_cades_signature_request_model.py +147 -0
- restpki_ng_python_client/models/open_signature_request_model.py +145 -0
- restpki_ng_python_client/models/open_xml_signature_request_model.py +151 -0
- restpki_ng_python_client/models/other_name_model.py +107 -0
- restpki_ng_python_client/models/pades_certification_level.py +47 -0
- restpki_ng_python_client/models/pades_horizontal_align.py +46 -0
- restpki_ng_python_client/models/pades_measurement_units.py +45 -0
- restpki_ng_python_client/models/pades_page_optimization_model.py +98 -0
- restpki_ng_python_client/models/pades_signature_model.py +113 -0
- restpki_ng_python_client/models/pades_signature_post_request_v1.py +167 -0
- restpki_ng_python_client/models/pades_signature_post_request_v2.py +171 -0
- restpki_ng_python_client/models/pades_signature_post_response.py +120 -0
- restpki_ng_python_client/models/pades_signature_post_signed_bytes_request.py +92 -0
- restpki_ng_python_client/models/pades_signature_post_signed_bytes_response.py +106 -0
- restpki_ng_python_client/models/pades_signer_model.py +168 -0
- restpki_ng_python_client/models/pades_size_model.py +89 -0
- restpki_ng_python_client/models/pades_text_horizontal_align.py +45 -0
- restpki_ng_python_client/models/pades_vertical_align.py +46 -0
- restpki_ng_python_client/models/pades_visual_auto_positioning_model.py +106 -0
- restpki_ng_python_client/models/pades_visual_image_model.py +105 -0
- restpki_ng_python_client/models/pades_visual_positioning_model.py +109 -0
- restpki_ng_python_client/models/pades_visual_rectangle_model.py +127 -0
- restpki_ng_python_client/models/pades_visual_representation_model.py +103 -0
- restpki_ng_python_client/models/pades_visual_text_model.py +111 -0
- restpki_ng_python_client/models/page_orientations.py +46 -0
- restpki_ng_python_client/models/paper_sizes.py +56 -0
- restpki_ng_python_client/models/pdf_add_marks_request.py +117 -0
- restpki_ng_python_client/models/pdf_add_marks_response.py +91 -0
- restpki_ng_python_client/models/pdf_container_definition.py +208 -0
- restpki_ng_python_client/models/pdf_helper.py +43 -0
- restpki_ng_python_client/models/pdf_mark_element_model.py +230 -0
- restpki_ng_python_client/models/pdf_mark_element_type.py +46 -0
- restpki_ng_python_client/models/pdf_mark_image_model.py +98 -0
- restpki_ng_python_client/models/pdf_mark_model.py +168 -0
- restpki_ng_python_client/models/pdf_mark_page_options.py +47 -0
- restpki_ng_python_client/models/pdf_signature_options.py +101 -0
- restpki_ng_python_client/models/pdf_text_section_model.py +125 -0
- restpki_ng_python_client/models/pdf_text_style.py +46 -0
- restpki_ng_python_client/models/pki_brazil_certificate_model.py +159 -0
- restpki_ng_python_client/models/pki_brazil_certificate_types.py +54 -0
- restpki_ng_python_client/models/pki_italy_certificate_model.py +103 -0
- restpki_ng_python_client/models/pki_italy_certificate_types.py +46 -0
- restpki_ng_python_client/models/prepare_authentication_request.py +100 -0
- restpki_ng_python_client/models/prepare_authentication_response.py +99 -0
- restpki_ng_python_client/models/prepare_signature_failures.py +46 -0
- restpki_ng_python_client/models/prepare_signature_request.py +133 -0
- restpki_ng_python_client/models/prepare_signature_response.py +116 -0
- restpki_ng_python_client/models/resource_content_or_reference.py +107 -0
- restpki_ng_python_client/models/role_attribute_model.py +114 -0
- restpki_ng_python_client/models/session_completion_status.py +89 -0
- restpki_ng_python_client/models/signature_algorithm_and_value_model.py +106 -0
- restpki_ng_python_client/models/signature_algorithm_identifier.py +88 -0
- restpki_ng_python_client/models/signature_algorithms.py +48 -0
- restpki_ng_python_client/models/signature_b_stamp_model.py +135 -0
- restpki_ng_python_client/models/signature_policy_identifier_model.py +105 -0
- restpki_ng_python_client/models/signature_result_model.py +105 -0
- restpki_ng_python_client/models/signature_session_document_data.py +128 -0
- restpki_ng_python_client/models/signature_session_document_summary.py +138 -0
- restpki_ng_python_client/models/signature_session_model.py +126 -0
- restpki_ng_python_client/models/signature_session_status.py +49 -0
- restpki_ng_python_client/models/signature_types.py +46 -0
- restpki_ng_python_client/models/signer_b_stamp_model.py +132 -0
- restpki_ng_python_client/models/signer_model.py +187 -0
- restpki_ng_python_client/models/signer_summary.py +94 -0
- restpki_ng_python_client/models/timestamp_issue_response.py +99 -0
- restpki_ng_python_client/models/validation_item_model.py +111 -0
- restpki_ng_python_client/models/validation_item_types.py +91 -0
- restpki_ng_python_client/models/validation_results_model.py +131 -0
- restpki_ng_python_client/models/webhook_event_model.py +94 -0
- restpki_ng_python_client/models/webhook_event_types.py +44 -0
- restpki_ng_python_client/models/xml_attribute_model.py +107 -0
- restpki_ng_python_client/models/xml_element_location_model.py +111 -0
- restpki_ng_python_client/models/xml_element_model.py +115 -0
- restpki_ng_python_client/models/xml_element_signature_post_request.py +145 -0
- restpki_ng_python_client/models/xml_id_attribute_model.py +96 -0
- restpki_ng_python_client/models/xml_id_resolution_table_model.py +123 -0
- restpki_ng_python_client/models/xml_insertion_options.py +47 -0
- restpki_ng_python_client/models/xml_node_name_model.py +96 -0
- restpki_ng_python_client/models/xml_signature_model.py +154 -0
- restpki_ng_python_client/models/xml_signature_options.py +102 -0
- restpki_ng_python_client/models/xml_signature_post_response.py +120 -0
- restpki_ng_python_client/models/xml_signature_post_signed_bytes_request.py +92 -0
- restpki_ng_python_client/models/xml_signature_post_signed_bytes_response.py +106 -0
- restpki_ng_python_client/models/xml_signature_response_model.py +113 -0
- restpki_ng_python_client/models/xml_signature_types.py +47 -0
- restpki_ng_python_client/models/xml_signed_entity_types.py +46 -0
- restpki_ng_python_client/py.typed +0 -0
- restpki_ng_python_client/rest.py +231 -0
- restpki_ng_python_client/restpki_ng_client.py +458 -0
- restpki_ng_python_client/standard_signature_policies.py +24 -0
- restpki_ng_python_client/utils.py +80 -0
- restpki_ng_python_client-0.9.0.dist-info/METADATA +16 -0
- restpki_ng_python_client-0.9.0.dist-info/RECORD +181 -0
- restpki_ng_python_client-0.9.0.dist-info/WHEEL +5 -0
- restpki_ng_python_client-0.9.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Rest PKI Core API
|
|
5
|
+
|
|
6
|
+
<b><i>Para Português, <a href=\"https://docs.lacunasoftware.com/pt-br/articles/rest-pki/core/integration/get-started\">clique aqui</a></i></b> <p> <a href=\"https://docs.lacunasoftware.com/en-us/articles/rest-pki/core/\">Rest PKI Core</a> is an upcoming version of <a href=\"https://docs.lacunasoftware.com/en-us/articles/rest-pki/\">Rest PKI</a> that will have extended compatibility with environments and databases. </p> <p> In addition to Windows Server (which is already supported by Rest PKI), Rest PKI Core will also run on <b>Linux</b> (Debian- and RedHat-based distributions) and on <b>Docker</b>. As for database servers, in addition to SQL Server, <b>PostgreSQL</b> will also be supported. </p> <p> <b>Before getting started, see the integration overview on the <a href=\"https://docs.lacunasoftware.com/en-us/articles/rest-pki/core/integration/\">Integration Guide</a></b> </p> <p> For questions regarding the usage of this API, please reach us at <a href=\"https://lacuna.help/\">lacuna.help</a> </p> <h2>Parameters</h2> <p> You will need the following parameters: </p> <ul> <li><b>Endpoint</b>: address of the Rest PKI Core instance that will be used</li> <li><b>API Key</b>: authorization key for using the API</li> </ul> <p> The <span class=\"model\">endpoint</span> must be prefixed to all relative URLs mentioned here. As for the <span class=\"model\">API Key</span>, see how to use it below. </p> <h2>Authentication</h2> <p> The API key must be sent on the <span class=\"model\">X-Api-Key</span> header on each request: </p> <!-- unfortunately, class \"example microlight\" doesn't seem to work here --> <pre style=\"font-size: 12px; padding: 10px; border-radius: 4px; background: #41444e; font-weight: 600; color: #fff;\"> X-Api-Key: yourapp|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </pre> <h2>HTTP Codes</h2> <p> The APIs will return the following HTTP codes: </p> <table> <thead> <tr> <th>Code</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><strong class=\"model-title\">200 (OK)</strong></td> <td>Request processed successfully. The response is different for each API, please refer to the operation's documentation</td> </tr> <tr> <td><strong class=\"model-title\">400 (Bad Request)</strong></td> <td>Syntax error. For instance, when a required field was not provided</td> </tr> <tr> <td><strong class=\"model-title\">401 (Unauthorized)</strong></td> <td>API key not provided or invalid</td> </tr> <tr> <td><strong class=\"model-title\">403 (Forbidden)</strong></td> <td>API key is valid, but the application has insufficient permissions to complete the requested operation</td> </tr> <tr> <td><strong class=\"model-title\">422 (Unprocessable Entity)</strong></td> <td>API error. The response body is an <a href=\"#model-ErrorModelV2\" class=\"model\">ErrorModelV2</a> </tr> <tr> <td><strong class=\"model-title\">500 (Internal Server Error)</strong></td> <td>An unexpected error occurred. The <span class=\"model\">exceptionCode</span> contained on the response body may be of help for our support team during diagnostic.</td> </tr> </tbody> </table> <h3>Error Codes</h3> <p> Some of the error codes returned in the <span class=\"model\">code</span> field of an <a href=\"#model-ErrorModelV2\" class=\"model\">ErrorModelV2</a> (body of responses with HTTP status code 422) are provided below*: </p> <table> <thead> <tr> <th>Code</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td class=\"model\">DocumentNotFound</td> <td>A referenced document was not found (check the document ID)</td> </tr> <tr> <td class=\"model\">SecurityContextNotFound</td> <td>A referenced security context was not found (check the security context ID)</td> </tr> <tr> <td class=\"model\">SignatureSessionNotFound</td> <td>A referenced signature session was not found (check the signature session ID)</td> </tr> <tr> <td class=\"model\">BadSignatureSessionOperation</td> <td>The operation is invalid for the current signature session or document status. For instance, trying to await the session's completion if it is still <span class=\"model\">Pending</span> results in this error</td> </tr> <tr> <td class=\"model\">BackgroundProcessing</td> <td>The operation cannot be completed at this time because the resource is being processed in background</td> </tr> <tr> <td class=\"model\">SignatureSessionTokenRequired</td> <td>The signature session token was not passed on the <span class=\"model\">X-Signature-Session-Token</span> request header</td> </tr> <tr> <td class=\"model\">BadSignatureSessionToken</td> <td>An invalid signature session token was passed on the <span class=\"model\">X-Signature-Session-Token</span> request header. Check your application for possible corruption of the session token, which may contain characters <span class=\"code\">-</span> (hyphen) and <span class=\"code\">_</span> (underscore)</td> </tr> <tr> <td class=\"model\">ExpiredSignatureSessionToken</td> <td>An expired signature session token was passed on the <span class=\"model\">X-Signature-Session-Token</span> request header. Signature session tokens are normally valid for 4 hours.</td> </tr> </tbody> </table> <p style=\"font-size: 0.9em\"> *The codes shown above are the most common error codes. Nonetheless, this list is not comprehensive. New codes may be added anytime without previous warning. </p> <h2>Culture / Internationalization (i18n)</h2> <p>The <span class=\"model\">Accept-Language</span> request header is observed by this API. The following cultures are supported:</p> <ul> <li><span class=\"code\">en-US</span> (or simply <span class=\"code\">en</span>)</li> <li><span class=\"code\">pt-BR</span> (or simply <span class=\"code\">pt</span>)</li> </ul> <p><i>Notice: error messages are not affected by this header and therefore should not be displayed to users, being better suited for logging.</i></p>
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 2.1.2
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import atexit
|
|
16
|
+
import datetime
|
|
17
|
+
from dateutil.parser import parse
|
|
18
|
+
import json
|
|
19
|
+
import mimetypes
|
|
20
|
+
import os
|
|
21
|
+
import re
|
|
22
|
+
import tempfile
|
|
23
|
+
|
|
24
|
+
from urllib.parse import quote
|
|
25
|
+
from typing import Tuple, Optional, List
|
|
26
|
+
|
|
27
|
+
from restpki_ng_python_client.configuration import Configuration
|
|
28
|
+
from restpki_ng_python_client.api_response import ApiResponse
|
|
29
|
+
import restpki_ng_python_client.models
|
|
30
|
+
from restpki_ng_python_client import rest
|
|
31
|
+
from restpki_ng_python_client.exceptions import (
|
|
32
|
+
ApiValueError,
|
|
33
|
+
ApiException,
|
|
34
|
+
BadRequestException,
|
|
35
|
+
UnauthorizedException,
|
|
36
|
+
ForbiddenException,
|
|
37
|
+
NotFoundException,
|
|
38
|
+
ServiceException
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ApiClient:
|
|
43
|
+
"""Generic API client for OpenAPI client library builds.
|
|
44
|
+
|
|
45
|
+
OpenAPI generic API client. This client handles the client-
|
|
46
|
+
server communication, and is invariant across implementations. Specifics of
|
|
47
|
+
the methods and models for each application are generated from the OpenAPI
|
|
48
|
+
templates.
|
|
49
|
+
|
|
50
|
+
:param configuration: .Configuration object for this client
|
|
51
|
+
:param header_name: a header to pass when making calls to the API.
|
|
52
|
+
:param header_value: a header value to pass when making calls to
|
|
53
|
+
the API.
|
|
54
|
+
:param cookie: a cookie to include in the header when making calls
|
|
55
|
+
to the API
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
PRIMITIVE_TYPES = (float, bool, bytes, str, int)
|
|
59
|
+
NATIVE_TYPES_MAPPING = {
|
|
60
|
+
'int': int,
|
|
61
|
+
'long': int, # TODO remove as only py3 is supported?
|
|
62
|
+
'float': float,
|
|
63
|
+
'str': str,
|
|
64
|
+
'bool': bool,
|
|
65
|
+
'date': datetime.date,
|
|
66
|
+
'datetime': datetime.datetime,
|
|
67
|
+
'object': object,
|
|
68
|
+
}
|
|
69
|
+
_pool = None
|
|
70
|
+
|
|
71
|
+
def __init__(
|
|
72
|
+
self,
|
|
73
|
+
configuration=None,
|
|
74
|
+
header_name=None,
|
|
75
|
+
header_value=None,
|
|
76
|
+
cookie=None
|
|
77
|
+
) -> None:
|
|
78
|
+
# use default configuration if none is provided
|
|
79
|
+
if configuration is None:
|
|
80
|
+
configuration = Configuration.get_default()
|
|
81
|
+
self.configuration = configuration
|
|
82
|
+
|
|
83
|
+
self.rest_client = rest.RESTClientObject(configuration)
|
|
84
|
+
self.default_headers = {}
|
|
85
|
+
if header_name is not None:
|
|
86
|
+
self.default_headers[header_name] = header_value
|
|
87
|
+
self.cookie = cookie
|
|
88
|
+
# Set default User-Agent.
|
|
89
|
+
self.user_agent = 'OpenAPI-Generator/0.9.0/python'
|
|
90
|
+
self.client_side_validation = configuration.client_side_validation
|
|
91
|
+
|
|
92
|
+
def __enter__(self):
|
|
93
|
+
return self
|
|
94
|
+
|
|
95
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
96
|
+
pass
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def user_agent(self):
|
|
100
|
+
"""User agent for this API client"""
|
|
101
|
+
return self.default_headers['User-Agent']
|
|
102
|
+
|
|
103
|
+
@user_agent.setter
|
|
104
|
+
def user_agent(self, value):
|
|
105
|
+
self.default_headers['User-Agent'] = value
|
|
106
|
+
|
|
107
|
+
def set_default_header(self, header_name, header_value):
|
|
108
|
+
self.default_headers[header_name] = header_value
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
_default = None
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def get_default(cls):
|
|
115
|
+
"""Return new instance of ApiClient.
|
|
116
|
+
|
|
117
|
+
This method returns newly created, based on default constructor,
|
|
118
|
+
object of ApiClient class or returns a copy of default
|
|
119
|
+
ApiClient.
|
|
120
|
+
|
|
121
|
+
:return: The ApiClient object.
|
|
122
|
+
"""
|
|
123
|
+
if cls._default is None:
|
|
124
|
+
cls._default = ApiClient()
|
|
125
|
+
return cls._default
|
|
126
|
+
|
|
127
|
+
@classmethod
|
|
128
|
+
def set_default(cls, default):
|
|
129
|
+
"""Set default instance of ApiClient.
|
|
130
|
+
|
|
131
|
+
It stores default ApiClient.
|
|
132
|
+
|
|
133
|
+
:param default: object of ApiClient.
|
|
134
|
+
"""
|
|
135
|
+
cls._default = default
|
|
136
|
+
|
|
137
|
+
def param_serialize(
|
|
138
|
+
self,
|
|
139
|
+
method,
|
|
140
|
+
resource_path,
|
|
141
|
+
path_params=None,
|
|
142
|
+
query_params=None,
|
|
143
|
+
header_params=None,
|
|
144
|
+
body=None,
|
|
145
|
+
post_params=None,
|
|
146
|
+
files=None, auth_settings=None,
|
|
147
|
+
collection_formats=None,
|
|
148
|
+
_host=None,
|
|
149
|
+
_request_auth=None
|
|
150
|
+
) -> Tuple:
|
|
151
|
+
|
|
152
|
+
"""Builds the HTTP request params needed by the request.
|
|
153
|
+
:param method: Method to call.
|
|
154
|
+
:param resource_path: Path to method endpoint.
|
|
155
|
+
:param path_params: Path parameters in the url.
|
|
156
|
+
:param query_params: Query parameters in the url.
|
|
157
|
+
:param header_params: Header parameters to be
|
|
158
|
+
placed in the request header.
|
|
159
|
+
:param body: Request body.
|
|
160
|
+
:param post_params dict: Request post form parameters,
|
|
161
|
+
for `application/x-www-form-urlencoded`, `multipart/form-data`.
|
|
162
|
+
:param auth_settings list: Auth Settings names for the request.
|
|
163
|
+
:param files dict: key -> filename, value -> filepath,
|
|
164
|
+
for `multipart/form-data`.
|
|
165
|
+
:param collection_formats: dict of collection formats for path, query,
|
|
166
|
+
header, and post parameters.
|
|
167
|
+
:param _request_auth: set to override the auth_settings for an a single
|
|
168
|
+
request; this effectively ignores the authentication
|
|
169
|
+
in the spec for a single request.
|
|
170
|
+
:return: tuple of form (path, http_method, query_params, header_params,
|
|
171
|
+
body, post_params, files)
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
config = self.configuration
|
|
175
|
+
|
|
176
|
+
# header parameters
|
|
177
|
+
header_params = header_params or {}
|
|
178
|
+
header_params.update(self.default_headers)
|
|
179
|
+
if self.cookie:
|
|
180
|
+
header_params['Cookie'] = self.cookie
|
|
181
|
+
if header_params:
|
|
182
|
+
header_params = self.sanitize_for_serialization(header_params)
|
|
183
|
+
header_params = dict(
|
|
184
|
+
self.parameters_to_tuples(header_params,collection_formats)
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# path parameters
|
|
188
|
+
if path_params:
|
|
189
|
+
path_params = self.sanitize_for_serialization(path_params)
|
|
190
|
+
path_params = self.parameters_to_tuples(
|
|
191
|
+
path_params,
|
|
192
|
+
collection_formats
|
|
193
|
+
)
|
|
194
|
+
for k, v in path_params:
|
|
195
|
+
# specified safe chars, encode everything
|
|
196
|
+
resource_path = resource_path.replace(
|
|
197
|
+
'{%s}' % k,
|
|
198
|
+
quote(str(v), safe=config.safe_chars_for_path_param)
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
# post parameters
|
|
202
|
+
if post_params or files:
|
|
203
|
+
post_params = post_params if post_params else []
|
|
204
|
+
post_params = self.sanitize_for_serialization(post_params)
|
|
205
|
+
post_params = self.parameters_to_tuples(
|
|
206
|
+
post_params,
|
|
207
|
+
collection_formats
|
|
208
|
+
)
|
|
209
|
+
post_params.extend(self.files_parameters(files))
|
|
210
|
+
|
|
211
|
+
# auth setting
|
|
212
|
+
self.update_params_for_auth(
|
|
213
|
+
header_params,
|
|
214
|
+
query_params,
|
|
215
|
+
auth_settings,
|
|
216
|
+
resource_path,
|
|
217
|
+
method,
|
|
218
|
+
body,
|
|
219
|
+
request_auth=_request_auth
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
# body
|
|
223
|
+
if body:
|
|
224
|
+
body = self.sanitize_for_serialization(body)
|
|
225
|
+
|
|
226
|
+
# request url
|
|
227
|
+
if _host is None:
|
|
228
|
+
url = self.configuration.host + resource_path
|
|
229
|
+
else:
|
|
230
|
+
# use server/host defined in path or operation instead
|
|
231
|
+
url = _host + resource_path
|
|
232
|
+
|
|
233
|
+
# query parameters
|
|
234
|
+
if query_params:
|
|
235
|
+
query_params = self.sanitize_for_serialization(query_params)
|
|
236
|
+
url_query = self.parameters_to_url_query(
|
|
237
|
+
query_params,
|
|
238
|
+
collection_formats
|
|
239
|
+
)
|
|
240
|
+
url += "?" + url_query
|
|
241
|
+
|
|
242
|
+
return method, url, header_params, body, post_params
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def call_api(
|
|
246
|
+
self,
|
|
247
|
+
method,
|
|
248
|
+
url,
|
|
249
|
+
header_params=None,
|
|
250
|
+
body=None,
|
|
251
|
+
post_params=None,
|
|
252
|
+
_request_timeout=None
|
|
253
|
+
) -> rest.RESTResponse:
|
|
254
|
+
"""Makes the HTTP request (synchronous)
|
|
255
|
+
:param method: Method to call.
|
|
256
|
+
:param url: Path to method endpoint.
|
|
257
|
+
:param header_params: Header parameters to be
|
|
258
|
+
placed in the request header.
|
|
259
|
+
:param body: Request body.
|
|
260
|
+
:param post_params dict: Request post form parameters,
|
|
261
|
+
for `application/x-www-form-urlencoded`, `multipart/form-data`.
|
|
262
|
+
:param _request_timeout: timeout setting for this request.
|
|
263
|
+
:return: RESTResponse
|
|
264
|
+
"""
|
|
265
|
+
|
|
266
|
+
try:
|
|
267
|
+
# perform request and return response
|
|
268
|
+
response_data = self.rest_client.request(
|
|
269
|
+
method, url,
|
|
270
|
+
headers=header_params,
|
|
271
|
+
body=body, post_params=post_params,
|
|
272
|
+
_request_timeout=_request_timeout
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
except ApiException as e:
|
|
276
|
+
if e.body:
|
|
277
|
+
e.body = e.body.decode('utf-8')
|
|
278
|
+
raise e
|
|
279
|
+
|
|
280
|
+
return response_data
|
|
281
|
+
|
|
282
|
+
def response_deserialize(
|
|
283
|
+
self,
|
|
284
|
+
response_data=None,
|
|
285
|
+
response_types_map=None
|
|
286
|
+
) -> ApiResponse:
|
|
287
|
+
"""Deserializes response into an object.
|
|
288
|
+
:param response_data: RESTResponse object to be deserialized.
|
|
289
|
+
:param response_types_map: dict of response types.
|
|
290
|
+
:return: ApiResponse
|
|
291
|
+
"""
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
response_type = response_types_map.get(str(response_data.status), None)
|
|
295
|
+
if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599:
|
|
296
|
+
# if not found, look for '1XX', '2XX', etc.
|
|
297
|
+
response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
|
|
298
|
+
|
|
299
|
+
if not 200 <= response_data.status <= 299:
|
|
300
|
+
if response_data.status == 400:
|
|
301
|
+
raise BadRequestException(http_resp=response_data)
|
|
302
|
+
|
|
303
|
+
if response_data.status == 401:
|
|
304
|
+
raise UnauthorizedException(http_resp=response_data)
|
|
305
|
+
|
|
306
|
+
if response_data.status == 403:
|
|
307
|
+
raise ForbiddenException(http_resp=response_data)
|
|
308
|
+
|
|
309
|
+
if response_data.status == 404:
|
|
310
|
+
raise NotFoundException(http_resp=response_data)
|
|
311
|
+
|
|
312
|
+
if 500 <= response_data.status <= 599:
|
|
313
|
+
raise ServiceException(http_resp=response_data)
|
|
314
|
+
raise ApiException(http_resp=response_data)
|
|
315
|
+
|
|
316
|
+
# deserialize response data
|
|
317
|
+
|
|
318
|
+
if response_type == "bytearray":
|
|
319
|
+
return_data = response_data.data
|
|
320
|
+
elif response_type is None:
|
|
321
|
+
return_data = None
|
|
322
|
+
elif response_type == "file":
|
|
323
|
+
return_data = self.__deserialize_file(response_data)
|
|
324
|
+
else:
|
|
325
|
+
match = None
|
|
326
|
+
content_type = response_data.getheader('content-type')
|
|
327
|
+
if content_type is not None:
|
|
328
|
+
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
|
|
329
|
+
encoding = match.group(1) if match else "utf-8"
|
|
330
|
+
response_text = response_data.data.decode(encoding)
|
|
331
|
+
return_data = self.deserialize(response_text, response_type)
|
|
332
|
+
|
|
333
|
+
return ApiResponse(
|
|
334
|
+
status_code = response_data.status,
|
|
335
|
+
data = return_data,
|
|
336
|
+
headers = response_data.getheaders(),
|
|
337
|
+
raw_data = response_data.data
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
def sanitize_for_serialization(self, obj):
|
|
341
|
+
"""Builds a JSON POST object.
|
|
342
|
+
|
|
343
|
+
If obj is None, return None.
|
|
344
|
+
If obj is str, int, long, float, bool, return directly.
|
|
345
|
+
If obj is datetime.datetime, datetime.date
|
|
346
|
+
convert to string in iso8601 format.
|
|
347
|
+
If obj is list, sanitize each element in the list.
|
|
348
|
+
If obj is dict, return the dict.
|
|
349
|
+
If obj is OpenAPI model, return the properties dict.
|
|
350
|
+
|
|
351
|
+
:param obj: The data to serialize.
|
|
352
|
+
:return: The serialized form of data.
|
|
353
|
+
"""
|
|
354
|
+
if obj is None:
|
|
355
|
+
return None
|
|
356
|
+
elif isinstance(obj, self.PRIMITIVE_TYPES):
|
|
357
|
+
return obj
|
|
358
|
+
elif isinstance(obj, list):
|
|
359
|
+
return [
|
|
360
|
+
self.sanitize_for_serialization(sub_obj) for sub_obj in obj
|
|
361
|
+
]
|
|
362
|
+
elif isinstance(obj, tuple):
|
|
363
|
+
return tuple(
|
|
364
|
+
self.sanitize_for_serialization(sub_obj) for sub_obj in obj
|
|
365
|
+
)
|
|
366
|
+
elif isinstance(obj, (datetime.datetime, datetime.date)):
|
|
367
|
+
return obj.isoformat()
|
|
368
|
+
|
|
369
|
+
elif isinstance(obj, dict):
|
|
370
|
+
obj_dict = obj
|
|
371
|
+
else:
|
|
372
|
+
# Convert model obj to dict except
|
|
373
|
+
# attributes `openapi_types`, `attribute_map`
|
|
374
|
+
# and attributes which value is not None.
|
|
375
|
+
# Convert attribute name to json key in
|
|
376
|
+
# model definition for request.
|
|
377
|
+
obj_dict = obj.to_dict()
|
|
378
|
+
|
|
379
|
+
return {
|
|
380
|
+
key: self.sanitize_for_serialization(val)
|
|
381
|
+
for key, val in obj_dict.items()
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
def deserialize(self, response_text, response_type):
|
|
385
|
+
"""Deserializes response into an object.
|
|
386
|
+
|
|
387
|
+
:param response: RESTResponse object to be deserialized.
|
|
388
|
+
:param response_type: class literal for
|
|
389
|
+
deserialized object, or string of class name.
|
|
390
|
+
|
|
391
|
+
:return: deserialized object.
|
|
392
|
+
"""
|
|
393
|
+
|
|
394
|
+
# fetch data from response object
|
|
395
|
+
try:
|
|
396
|
+
data = json.loads(response_text)
|
|
397
|
+
except ValueError:
|
|
398
|
+
data = response_text
|
|
399
|
+
|
|
400
|
+
return self.__deserialize(data, response_type)
|
|
401
|
+
|
|
402
|
+
def __deserialize(self, data, klass):
|
|
403
|
+
"""Deserializes dict, list, str into an object.
|
|
404
|
+
|
|
405
|
+
:param data: dict, list or str.
|
|
406
|
+
:param klass: class literal, or string of class name.
|
|
407
|
+
|
|
408
|
+
:return: object.
|
|
409
|
+
"""
|
|
410
|
+
if data is None:
|
|
411
|
+
return None
|
|
412
|
+
|
|
413
|
+
if isinstance(klass, str):
|
|
414
|
+
if klass.startswith('List['):
|
|
415
|
+
sub_kls = re.match(r'List\[(.*)]', klass).group(1)
|
|
416
|
+
return [self.__deserialize(sub_data, sub_kls)
|
|
417
|
+
for sub_data in data]
|
|
418
|
+
|
|
419
|
+
if klass.startswith('Dict['):
|
|
420
|
+
sub_kls = re.match(r'Dict\[([^,]*), (.*)]', klass).group(2)
|
|
421
|
+
return {k: self.__deserialize(v, sub_kls)
|
|
422
|
+
for k, v in data.items()}
|
|
423
|
+
|
|
424
|
+
# convert str to class
|
|
425
|
+
if klass in self.NATIVE_TYPES_MAPPING:
|
|
426
|
+
klass = self.NATIVE_TYPES_MAPPING[klass]
|
|
427
|
+
else:
|
|
428
|
+
klass = getattr(restpki_ng_python_client.models, klass)
|
|
429
|
+
|
|
430
|
+
if klass in self.PRIMITIVE_TYPES:
|
|
431
|
+
return self.__deserialize_primitive(data, klass)
|
|
432
|
+
elif klass == object:
|
|
433
|
+
return self.__deserialize_object(data)
|
|
434
|
+
elif klass == datetime.date:
|
|
435
|
+
return self.__deserialize_date(data)
|
|
436
|
+
elif klass == datetime.datetime:
|
|
437
|
+
return self.__deserialize_datetime(data)
|
|
438
|
+
else:
|
|
439
|
+
return self.__deserialize_model(data, klass)
|
|
440
|
+
|
|
441
|
+
def parameters_to_tuples(self, params, collection_formats):
|
|
442
|
+
"""Get parameters as list of tuples, formatting collections.
|
|
443
|
+
|
|
444
|
+
:param params: Parameters as dict or list of two-tuples
|
|
445
|
+
:param dict collection_formats: Parameter collection formats
|
|
446
|
+
:return: Parameters as list of tuples, collections formatted
|
|
447
|
+
"""
|
|
448
|
+
new_params = []
|
|
449
|
+
if collection_formats is None:
|
|
450
|
+
collection_formats = {}
|
|
451
|
+
for k, v in params.items() if isinstance(params, dict) else params:
|
|
452
|
+
if k in collection_formats:
|
|
453
|
+
collection_format = collection_formats[k]
|
|
454
|
+
if collection_format == 'multi':
|
|
455
|
+
new_params.extend((k, value) for value in v)
|
|
456
|
+
else:
|
|
457
|
+
if collection_format == 'ssv':
|
|
458
|
+
delimiter = ' '
|
|
459
|
+
elif collection_format == 'tsv':
|
|
460
|
+
delimiter = '\t'
|
|
461
|
+
elif collection_format == 'pipes':
|
|
462
|
+
delimiter = '|'
|
|
463
|
+
else: # csv is the default
|
|
464
|
+
delimiter = ','
|
|
465
|
+
new_params.append(
|
|
466
|
+
(k, delimiter.join(str(value) for value in v)))
|
|
467
|
+
else:
|
|
468
|
+
new_params.append((k, v))
|
|
469
|
+
return new_params
|
|
470
|
+
|
|
471
|
+
def parameters_to_url_query(self, params, collection_formats):
|
|
472
|
+
"""Get parameters as list of tuples, formatting collections.
|
|
473
|
+
|
|
474
|
+
:param params: Parameters as dict or list of two-tuples
|
|
475
|
+
:param dict collection_formats: Parameter collection formats
|
|
476
|
+
:return: URL query string (e.g. a=Hello%20World&b=123)
|
|
477
|
+
"""
|
|
478
|
+
new_params = []
|
|
479
|
+
if collection_formats is None:
|
|
480
|
+
collection_formats = {}
|
|
481
|
+
for k, v in params.items() if isinstance(params, dict) else params:
|
|
482
|
+
if isinstance(v, bool):
|
|
483
|
+
v = str(v).lower()
|
|
484
|
+
if isinstance(v, (int, float)):
|
|
485
|
+
v = str(v)
|
|
486
|
+
if isinstance(v, dict):
|
|
487
|
+
v = json.dumps(v)
|
|
488
|
+
|
|
489
|
+
if k in collection_formats:
|
|
490
|
+
collection_format = collection_formats[k]
|
|
491
|
+
if collection_format == 'multi':
|
|
492
|
+
new_params.extend((k, value) for value in v)
|
|
493
|
+
else:
|
|
494
|
+
if collection_format == 'ssv':
|
|
495
|
+
delimiter = ' '
|
|
496
|
+
elif collection_format == 'tsv':
|
|
497
|
+
delimiter = '\t'
|
|
498
|
+
elif collection_format == 'pipes':
|
|
499
|
+
delimiter = '|'
|
|
500
|
+
else: # csv is the default
|
|
501
|
+
delimiter = ','
|
|
502
|
+
new_params.append(
|
|
503
|
+
(k, delimiter.join(quote(str(value)) for value in v))
|
|
504
|
+
)
|
|
505
|
+
else:
|
|
506
|
+
new_params.append((k, quote(str(v))))
|
|
507
|
+
|
|
508
|
+
return "&".join(["=".join(item) for item in new_params])
|
|
509
|
+
|
|
510
|
+
def files_parameters(self, files=None):
|
|
511
|
+
"""Builds form parameters.
|
|
512
|
+
|
|
513
|
+
:param files: File parameters.
|
|
514
|
+
:return: Form parameters with files.
|
|
515
|
+
"""
|
|
516
|
+
params = []
|
|
517
|
+
|
|
518
|
+
if files:
|
|
519
|
+
for k, v in files.items():
|
|
520
|
+
if not v:
|
|
521
|
+
continue
|
|
522
|
+
file_names = v if type(v) is list else [v]
|
|
523
|
+
for n in file_names:
|
|
524
|
+
with open(n, 'rb') as f:
|
|
525
|
+
filename = os.path.basename(f.name)
|
|
526
|
+
filedata = f.read()
|
|
527
|
+
mimetype = (
|
|
528
|
+
mimetypes.guess_type(filename)[0]
|
|
529
|
+
or 'application/octet-stream'
|
|
530
|
+
)
|
|
531
|
+
params.append(
|
|
532
|
+
tuple([k, tuple([filename, filedata, mimetype])])
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
return params
|
|
536
|
+
|
|
537
|
+
def select_header_accept(self, accepts: List[str]) -> Optional[str]:
|
|
538
|
+
"""Returns `Accept` based on an array of accepts provided.
|
|
539
|
+
|
|
540
|
+
:param accepts: List of headers.
|
|
541
|
+
:return: Accept (e.g. application/json).
|
|
542
|
+
"""
|
|
543
|
+
if not accepts:
|
|
544
|
+
return None
|
|
545
|
+
|
|
546
|
+
for accept in accepts:
|
|
547
|
+
if re.search('json', accept, re.IGNORECASE):
|
|
548
|
+
return accept
|
|
549
|
+
|
|
550
|
+
return accepts[0]
|
|
551
|
+
|
|
552
|
+
def select_header_content_type(self, content_types):
|
|
553
|
+
"""Returns `Content-Type` based on an array of content_types provided.
|
|
554
|
+
|
|
555
|
+
:param content_types: List of content-types.
|
|
556
|
+
:return: Content-Type (e.g. application/json).
|
|
557
|
+
"""
|
|
558
|
+
if not content_types:
|
|
559
|
+
return None
|
|
560
|
+
|
|
561
|
+
for content_type in content_types:
|
|
562
|
+
if re.search('json', content_type, re.IGNORECASE):
|
|
563
|
+
return content_type
|
|
564
|
+
|
|
565
|
+
return content_types[0]
|
|
566
|
+
|
|
567
|
+
def update_params_for_auth(
|
|
568
|
+
self,
|
|
569
|
+
headers,
|
|
570
|
+
queries,
|
|
571
|
+
auth_settings,
|
|
572
|
+
resource_path,
|
|
573
|
+
method,
|
|
574
|
+
body,
|
|
575
|
+
request_auth=None
|
|
576
|
+
) -> None:
|
|
577
|
+
"""Updates header and query params based on authentication setting.
|
|
578
|
+
|
|
579
|
+
:param headers: Header parameters dict to be updated.
|
|
580
|
+
:param queries: Query parameters tuple list to be updated.
|
|
581
|
+
:param auth_settings: Authentication setting identifiers list.
|
|
582
|
+
:resource_path: A string representation of the HTTP request resource path.
|
|
583
|
+
:method: A string representation of the HTTP request method.
|
|
584
|
+
:body: A object representing the body of the HTTP request.
|
|
585
|
+
The object type is the return value of sanitize_for_serialization().
|
|
586
|
+
:param request_auth: if set, the provided settings will
|
|
587
|
+
override the token in the configuration.
|
|
588
|
+
"""
|
|
589
|
+
if not auth_settings:
|
|
590
|
+
return
|
|
591
|
+
|
|
592
|
+
if request_auth:
|
|
593
|
+
self._apply_auth_params(
|
|
594
|
+
headers,
|
|
595
|
+
queries,
|
|
596
|
+
resource_path,
|
|
597
|
+
method,
|
|
598
|
+
body,
|
|
599
|
+
request_auth
|
|
600
|
+
)
|
|
601
|
+
else:
|
|
602
|
+
for auth in auth_settings:
|
|
603
|
+
auth_setting = self.configuration.auth_settings().get(auth)
|
|
604
|
+
if auth_setting:
|
|
605
|
+
self._apply_auth_params(
|
|
606
|
+
headers,
|
|
607
|
+
queries,
|
|
608
|
+
resource_path,
|
|
609
|
+
method,
|
|
610
|
+
body,
|
|
611
|
+
auth_setting
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
def _apply_auth_params(
|
|
615
|
+
self,
|
|
616
|
+
headers,
|
|
617
|
+
queries,
|
|
618
|
+
resource_path,
|
|
619
|
+
method,
|
|
620
|
+
body,
|
|
621
|
+
auth_setting
|
|
622
|
+
) -> None:
|
|
623
|
+
"""Updates the request parameters based on a single auth_setting
|
|
624
|
+
|
|
625
|
+
:param headers: Header parameters dict to be updated.
|
|
626
|
+
:param queries: Query parameters tuple list to be updated.
|
|
627
|
+
:resource_path: A string representation of the HTTP request resource path.
|
|
628
|
+
:method: A string representation of the HTTP request method.
|
|
629
|
+
:body: A object representing the body of the HTTP request.
|
|
630
|
+
The object type is the return value of sanitize_for_serialization().
|
|
631
|
+
:param auth_setting: auth settings for the endpoint
|
|
632
|
+
"""
|
|
633
|
+
if auth_setting['in'] == 'cookie':
|
|
634
|
+
headers['Cookie'] = auth_setting['value']
|
|
635
|
+
elif auth_setting['in'] == 'header':
|
|
636
|
+
if auth_setting['type'] != 'http-signature':
|
|
637
|
+
headers[auth_setting['key']] = auth_setting['value']
|
|
638
|
+
elif auth_setting['in'] == 'query':
|
|
639
|
+
queries.append((auth_setting['key'], auth_setting['value']))
|
|
640
|
+
else:
|
|
641
|
+
raise ApiValueError(
|
|
642
|
+
'Authentication token must be in `query` or `header`'
|
|
643
|
+
)
|
|
644
|
+
|
|
645
|
+
def __deserialize_file(self, response):
|
|
646
|
+
"""Deserializes body to file
|
|
647
|
+
|
|
648
|
+
Saves response body into a file in a temporary folder,
|
|
649
|
+
using the filename from the `Content-Disposition` header if provided.
|
|
650
|
+
|
|
651
|
+
handle file downloading
|
|
652
|
+
save response body into a tmp file and return the instance
|
|
653
|
+
|
|
654
|
+
:param response: RESTResponse.
|
|
655
|
+
:return: file path.
|
|
656
|
+
"""
|
|
657
|
+
fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
|
|
658
|
+
os.close(fd)
|
|
659
|
+
os.remove(path)
|
|
660
|
+
|
|
661
|
+
content_disposition = response.getheader("Content-Disposition")
|
|
662
|
+
if content_disposition:
|
|
663
|
+
filename = re.search(
|
|
664
|
+
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
|
|
665
|
+
content_disposition
|
|
666
|
+
).group(1)
|
|
667
|
+
path = os.path.join(os.path.dirname(path), filename)
|
|
668
|
+
|
|
669
|
+
with open(path, "wb") as f:
|
|
670
|
+
f.write(response.data)
|
|
671
|
+
|
|
672
|
+
return path
|
|
673
|
+
|
|
674
|
+
def __deserialize_primitive(self, data, klass):
|
|
675
|
+
"""Deserializes string to primitive type.
|
|
676
|
+
|
|
677
|
+
:param data: str.
|
|
678
|
+
:param klass: class literal.
|
|
679
|
+
|
|
680
|
+
:return: int, long, float, str, bool.
|
|
681
|
+
"""
|
|
682
|
+
try:
|
|
683
|
+
return klass(data)
|
|
684
|
+
except UnicodeEncodeError:
|
|
685
|
+
return str(data)
|
|
686
|
+
except TypeError:
|
|
687
|
+
return data
|
|
688
|
+
|
|
689
|
+
def __deserialize_object(self, value):
|
|
690
|
+
"""Return an original value.
|
|
691
|
+
|
|
692
|
+
:return: object.
|
|
693
|
+
"""
|
|
694
|
+
return value
|
|
695
|
+
|
|
696
|
+
def __deserialize_date(self, string):
|
|
697
|
+
"""Deserializes string to date.
|
|
698
|
+
|
|
699
|
+
:param string: str.
|
|
700
|
+
:return: date.
|
|
701
|
+
"""
|
|
702
|
+
try:
|
|
703
|
+
return parse(string).date()
|
|
704
|
+
except ImportError:
|
|
705
|
+
return string
|
|
706
|
+
except ValueError:
|
|
707
|
+
raise rest.ApiException(
|
|
708
|
+
status=0,
|
|
709
|
+
reason="Failed to parse `{0}` as date object".format(string)
|
|
710
|
+
)
|
|
711
|
+
|
|
712
|
+
def __deserialize_datetime(self, string):
|
|
713
|
+
"""Deserializes string to datetime.
|
|
714
|
+
|
|
715
|
+
The string should be in iso8601 datetime format.
|
|
716
|
+
|
|
717
|
+
:param string: str.
|
|
718
|
+
:return: datetime.
|
|
719
|
+
"""
|
|
720
|
+
try:
|
|
721
|
+
return parse(string)
|
|
722
|
+
except ImportError:
|
|
723
|
+
return string
|
|
724
|
+
except ValueError:
|
|
725
|
+
raise rest.ApiException(
|
|
726
|
+
status=0,
|
|
727
|
+
reason=(
|
|
728
|
+
"Failed to parse `{0}` as datetime object"
|
|
729
|
+
.format(string)
|
|
730
|
+
)
|
|
731
|
+
)
|
|
732
|
+
|
|
733
|
+
def __deserialize_model(self, data, klass):
|
|
734
|
+
"""Deserializes list or dict to model.
|
|
735
|
+
|
|
736
|
+
:param data: dict, list.
|
|
737
|
+
:param klass: class literal.
|
|
738
|
+
:return: model object.
|
|
739
|
+
"""
|
|
740
|
+
|
|
741
|
+
return klass.from_dict(data)
|