|
17 | 17 | import re |
18 | 18 | import json |
19 | 19 | import mimetypes |
20 | | -import tempfile |
21 | 20 | import threading |
22 | 21 | import base64 |
23 | 22 | import math |
@@ -188,7 +187,11 @@ def __call_api(self, resource_path, method, |
188 | 187 | r.data = r.data.decode('utf8', 'replace') |
189 | 188 | except (UnicodeDecodeError, AttributeError): |
190 | 189 | pass |
191 | | - return_data = self.deserialize(r, response_type) |
| 190 | + |
| 191 | + if response_type == "file": |
| 192 | + return_data = r.data |
| 193 | + else: |
| 194 | + return_data = self.deserialize(r, response_type) |
192 | 195 | else: |
193 | 196 | return_data = None |
194 | 197 |
|
@@ -255,10 +258,9 @@ def deserialize(self, response, response_type): |
255 | 258 |
|
256 | 259 | :return: deserialized object. |
257 | 260 | """ |
258 | | - # handle file downloading |
259 | | - # save response body into a tmp file and return the instance |
| 261 | + # handle file type response |
260 | 262 | if response_type == "file": |
261 | | - return self.__deserialize_file(response) |
| 263 | + return response.data |
262 | 264 |
|
263 | 265 | # fetch data from response object |
264 | 266 | try: |
@@ -551,35 +553,6 @@ def update_params_for_auth(self, headers, querys, auth_settings): |
551 | 553 | 'Authentication token must be in `query` or `header`' |
552 | 554 | ) |
553 | 555 |
|
554 | | - def __deserialize_file(self, response): |
555 | | - """ |
556 | | - Saves response body into a file in a temporary folder, |
557 | | - using the filename from the `Content-Disposition` header if provided. |
558 | | -
|
559 | | - :param response: RESTResponse. |
560 | | - :return: file path. |
561 | | - """ |
562 | | - config = Configuration() |
563 | | - |
564 | | - fd, path = tempfile.mkstemp(dir=config.temp_folder_path) |
565 | | - os.close(fd) |
566 | | - os.remove(path) |
567 | | - |
568 | | - content_disposition = response.getheader("Content-Disposition") |
569 | | - if content_disposition: |
570 | | - filename = re.\ |
571 | | - search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition).\ |
572 | | - group(1) |
573 | | - curr_time = datetime.now() |
574 | | - formatted_time = curr_time.strftime('%m%d%Y_%H%M%S_%f') |
575 | | - filename = "{}_{}".format(formatted_time, filename) |
576 | | - path = os.path.join(os.path.dirname(path), filename) |
577 | | - |
578 | | - with open(path, "wb") as f: |
579 | | - f.write(response.data) |
580 | | - |
581 | | - return path |
582 | | - |
583 | 556 | def __deserialize_primitive(self, data, klass): |
584 | 557 | """ |
585 | 558 | Deserializes string to primitive type. |
@@ -671,9 +644,9 @@ def request_jwt_user_token(self, client_id, user_id, oauth_host_name, private_ke |
671 | 644 | scopes=(OAuth.SCOPE_SIGNATURE,)): |
672 | 645 | """ |
673 | 646 | Request JWT User Token |
674 | | - :param client_id: DocuSign OAuth Client Id(AKA Integrator Key) |
675 | | - :param user_id: DocuSign user Id to be impersonated |
676 | | - :param oauth_host_name: DocuSign OAuth host name |
| 647 | + :param client_id: Docusign OAuth Client Id(AKA Integrator Key) |
| 648 | + :param user_id: Docusign user Id to be impersonated |
| 649 | + :param oauth_host_name: Docusign OAuth host name |
677 | 650 | :param private_key_bytes: the byte contents of the RSA private key |
678 | 651 | :param expires_in: number of seconds remaining before the JWT assertion is considered as invalid |
679 | 652 | :param scopes: Optional. The list of requested scopes may include (but not limited to) You can also pass any |
@@ -714,8 +687,8 @@ def request_jwt_application_token(self, client_id, oauth_host_name, private_key_ |
714 | 687 | scopes=(OAuth.SCOPE_SIGNATURE,)): |
715 | 688 | """ |
716 | 689 | Request JWT Application Token |
717 | | - :param client_id: DocuSign OAuth Client Id(AKA Integrator Key) |
718 | | - :param oauth_host_name: DocuSign OAuth host name |
| 690 | + :param client_id: Docusign OAuth Client Id(AKA Integrator Key) |
| 691 | + :param oauth_host_name: Docusign OAuth host name |
719 | 692 | :param private_key_bytes: the byte contents of the RSA private key |
720 | 693 | :param expires_in: number of seconds remaining before the JWT assertion is considered as invalid |
721 | 694 | :param scopes: Optional. The list of requested scopes may include (but not limited to) You can also pass any |
@@ -772,8 +745,8 @@ def get_user_info(self, access_token): |
772 | 745 | def generate_access_token(self, client_id, client_secret, code): |
773 | 746 | """ |
774 | 747 | GenerateAccessToken will exchange the authorization code for an access token and refresh tokens. |
775 | | - :param client_id: DocuSign OAuth Client Id(AKA Integrator Key) |
776 | | - :param client_secret: The secret key you generated when you set up the integration in DocuSign Admin console. |
| 748 | + :param client_id: Docusign OAuth Client Id(AKA Integrator Key) |
| 749 | + :param client_secret: The secret key you generated when you set up the integration in Docusign Admin console. |
777 | 750 | :param code: The authorization code |
778 | 751 | :return: OAuthToken object |
779 | 752 | """ |
@@ -828,7 +801,7 @@ def set_access_token(self, token_obj): |
828 | 801 | def get_authorization_uri(self, client_id, scopes, redirect_uri, response_type, state=None): |
829 | 802 | """ |
830 | 803 | Helper method to configure the OAuth accessCode/implicit flow parameters |
831 | | - :param client_id: DocuSign OAuth Client Id(AKA Integrator Key) |
| 804 | + :param client_id: Docusign OAuth Client Id(AKA Integrator Key) |
832 | 805 | :param scopes: The list of requested scopes. Client applications may be scoped to a limited set of system access. |
833 | 806 | :param redirect_uri: This determines where to deliver the response containing the authorization code |
834 | 807 | :param response_type: Determines the response type of the authorization request, NOTE: these response types are |
|
0 commit comments