MCPcopy Index your code
hub / github.com/dataforseo/PythonClient / deserialize

Method deserialize

dataforseo_client/api_client.py:362–392  ·  view source on GitHub ↗

Deserializes response into an object. :param response: RESTResponse object to be deserialized. :param response_type: class literal for deserialized object, or string of class name. :param content_type: content type of response. :return: deserialized obje

(self, response_text: str, response_type: str, content_type: Optional[str])

Source from the content-addressed store, hash-verified

360 }
361
362 def deserialize(self, response_text: str, response_type: str, content_type: Optional[str]):
363 """Deserializes response into an object.
364
365 :param response: RESTResponse object to be deserialized.
366 :param response_type: class literal for
367 deserialized object, or string of class name.
368 :param content_type: content type of response.
369
370 :return: deserialized object.
371 """
372
373 # fetch data from response object
374 if content_type is None:
375 try:
376 data = json.loads(response_text)
377 except ValueError:
378 data = response_text
379 elif content_type.startswith("application/json"):
380 if response_text == "":
381 data = ""
382 else:
383 data = json.loads(response_text)
384 elif content_type.startswith("text/plain"):
385 data = response_text
386 else:
387 raise ApiException(
388 status=0,
389 reason="Unsupported content type: {0}".format(content_type)
390 )
391
392 return self.__deserialize(data, response_type)
393
394 def __deserialize(self, data, klass):
395 """Deserializes dict, list, str into an object.

Callers 1

response_deserializeMethod · 0.95

Calls 2

__deserializeMethod · 0.95
ApiExceptionClass · 0.90

Tested by

no test coverage detected