MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / __deserialize_file

Method __deserialize_file

sdks/python/src/e2a/v1/generated/api_client.py:691–720  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 1

response_deserializeMethod · 0.95

Calls 2

getheaderMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected