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
)
| 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. |