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)
| 642 | ) |
| 643 | |
| 644 | def __deserialize_file(self, response): |
| 645 | """Deserializes body to file |
| 646 | |
| 647 | Saves response body into a file in a temporary folder, |
| 648 | using the filename from the `Content-Disposition` header if provided. |
| 649 | |
| 650 | handle file downloading |
| 651 | save response body into a tmp file and return the instance |
| 652 | |
| 653 | :param response: RESTResponse. |
| 654 | :return: file path. |
| 655 | """ |
| 656 | fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path) |
| 657 | os.close(fd) |
| 658 | os.remove(path) |
| 659 | |
| 660 | content_disposition = response.getheader("Content-Disposition") |
| 661 | if content_disposition: |
| 662 | m = re.search( |
| 663 | r'filename=[\'"]?([^\'"\s]+)[\'"]?', |
| 664 | content_disposition |
| 665 | ) |
| 666 | assert m is not None, "Unexpected 'content-disposition' header value" |
| 667 | filename = m.group(1) |
| 668 | path = os.path.join(os.path.dirname(path), filename) |
| 669 | |
| 670 | with open(path, "wb") as f: |
| 671 | f.write(response.data) |
| 672 | |
| 673 | return path |
| 674 | |
| 675 | def __deserialize_primitive(self, data, klass): |
| 676 | """Deserializes string to primitive type. |
no test coverage detected