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