Deserializes body to file Saves response body into a file in a temporary folder, using the filename from the `Content-Disposition` header if provided. :param response: RESTResponse. :return: file path.
(self, response)
| 585 | ) |
| 586 | |
| 587 | def __deserialize_file(self, response): |
| 588 | """Deserializes body to file |
| 589 | |
| 590 | Saves response body into a file in a temporary folder, |
| 591 | using the filename from the `Content-Disposition` header if provided. |
| 592 | |
| 593 | :param response: RESTResponse. |
| 594 | :return: file path. |
| 595 | """ |
| 596 | fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path) |
| 597 | os.close(fd) |
| 598 | os.remove(path) |
| 599 | |
| 600 | content_disposition = response.getheader("Content-Disposition") |
| 601 | if content_disposition: |
| 602 | filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', |
| 603 | content_disposition).group(1) |
| 604 | path = os.path.join(os.path.dirname(path), filename) |
| 605 | |
| 606 | with open(path, "wb") as f: |
| 607 | f.write(response.data) |
| 608 | |
| 609 | return path |
| 610 | |
| 611 | def __deserialize_primitive(self, data, klass): |
| 612 | """Deserializes string to primitive type. |