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

Method response_deserialize

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

Deserializes response into an object. :param response_data: RESTResponse object to be deserialized. :param response_types_map: dict of response types. :return: ApiResponse

(
        self,
        response_data: rest.RESTResponse,
        response_types_map: Optional[Dict[str, ApiResponseT]]=None
    )

Source from the content-addressed store, hash-verified

287 return response_data
288
289 def response_deserialize(
290 self,
291 response_data: rest.RESTResponse,
292 response_types_map: Optional[Dict[str, ApiResponseT]]=None
293 ) -> ApiResponse[ApiResponseT]:
294 """Deserializes response into an object.
295 :param response_data: RESTResponse object to be deserialized.
296 :param response_types_map: dict of response types.
297 :return: ApiResponse
298 """
299
300 msg = "RESTResponse.read() must be called before passing it to response_deserialize()"
301 assert response_data.data is not None, msg
302
303 response_type = response_types_map.get(str(response_data.status), None)
304 if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599:
305 # if not found, look for '1XX', '2XX', etc.
306 response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
307
308 # deserialize response data
309 response_text = None
310 return_data = None
311 try:
312 if response_type == "bytearray":
313 return_data = response_data.data
314 elif response_type == "file":
315 return_data = self.__deserialize_file(response_data)
316 elif response_type is not None:
317 match = None
318 content_type = response_data.getheader('content-type')
319 if content_type is not None:
320 match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
321 encoding = match.group(1) if match else "utf-8"
322 response_text = response_data.data.decode(encoding)
323 return_data = self.deserialize(response_text, response_type, content_type)
324 finally:
325 if not 200 <= response_data.status <= 299:
326 raise ApiException.from_response(
327 http_resp=response_data,
328 body=response_text,
329 data=return_data,
330 )
331
332 return ApiResponse(
333 status_code = response_data.status,
334 data = return_data,
335 headers = response_data.getheaders(),
336 raw_data = response_data.data
337 )
338
339 def sanitize_for_serialization(self, obj):
340 """Builds a JSON POST object.

Callers 15

create_agentMethod · 0.80
delete_agentMethod · 0.80
get_agentMethod · 0.80
get_agent_protectionMethod · 0.80
list_agentsMethod · 0.80
put_agent_protectionMethod · 0.80

Calls 7

__deserialize_fileMethod · 0.95
deserializeMethod · 0.95
ApiResponseClass · 0.90
getheaderMethod · 0.80
from_responseMethod · 0.80
getheadersMethod · 0.80
getMethod · 0.45

Tested by 4

test_agentMethod · 0.64
test_webhookMethod · 0.64