Deserializes body to file Saves response body into a file in a temporary folder, using the filename from the `Content-Disposition` header if provided. handle file downloading save response body into a tmp file and return the instance :param response: RESTR
(self, response)
| 689 | ) |
| 690 | |
| 691 | def __deserialize_file(self, response): |
| 692 | """Deserializes body to file |
| 693 | |
| 694 | Saves response body into a file in a temporary folder, |
| 695 | using the filename from the `Content-Disposition` header if provided. |
| 696 | |
| 697 | handle file downloading |
| 698 | save response body into a tmp file and return the instance |
| 699 | |
| 700 | :param response: RESTResponse. |
| 701 | :return: file path. |
| 702 | """ |
| 703 | fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path) |
| 704 | os.close(fd) |
| 705 | os.remove(path) |
| 706 | |
| 707 | content_disposition = response.getheader("Content-Disposition") |
| 708 | if content_disposition: |
| 709 | m = re.search( |
| 710 | r'filename=[\'"]?([^\'"\s]+)[\'"]?', |
| 711 | content_disposition |
| 712 | ) |
| 713 | assert m is not None, "Unexpected 'content-disposition' header value" |
| 714 | filename = m.group(1) |
| 715 | path = os.path.join(os.path.dirname(path), filename) |
| 716 | |
| 717 | with open(path, "wb") as f: |
| 718 | f.write(response.data) |
| 719 | |
| 720 | return path |
| 721 | |
| 722 | def __deserialize_primitive(self, data, klass): |
| 723 | """Deserializes string to primitive type. |
no test coverage detected