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
)
| 255 | return response_data |
| 256 | |
| 257 | def response_deserialize( |
| 258 | self, |
| 259 | response_data: rest.RESTResponse, |
| 260 | response_types_map: Optional[Dict[str, ApiResponseT]]=None |
| 261 | ) -> ApiResponse[ApiResponseT]: |
| 262 | """Deserializes response into an object. |
| 263 | :param response_data: RESTResponse object to be deserialized. |
| 264 | :param response_types_map: dict of response types. |
| 265 | :return: ApiResponse |
| 266 | """ |
| 267 | |
| 268 | msg = "RESTResponse.read() must be called before passing it to response_deserialize()" |
| 269 | assert response_data.data is not None, msg |
| 270 | |
| 271 | response_type = response_types_map.get(str(response_data.status), None) |
| 272 | if not response_type and isinstance(response_data.status, int) and 100 <= response_data.status <= 599: |
| 273 | # if not found, look for '1XX', '2XX', etc. |
| 274 | response_type = response_types_map.get(str(response_data.status)[0] + "XX", None) |
| 275 | |
| 276 | # deserialize response data |
| 277 | response_text = None |
| 278 | return_data = None |
| 279 | try: |
| 280 | if response_type == "bytearray": |
| 281 | return_data = response_data.data |
| 282 | elif response_type == "file": |
| 283 | return_data = self.__deserialize_file(response_data) |
| 284 | elif response_type is not None: |
| 285 | match = None |
| 286 | content_type = response_data.getheader('content-type') |
| 287 | if content_type is not None: |
| 288 | match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) |
| 289 | encoding = match.group(1) if match else "utf-8" |
| 290 | response_text = response_data.data.decode(encoding) |
| 291 | return_data = self.deserialize(response_text, response_type, content_type) |
| 292 | finally: |
| 293 | if not 200 <= response_data.status <= 299: |
| 294 | raise ApiException.from_response( |
| 295 | http_resp=response_data, |
| 296 | body=response_text, |
| 297 | data=return_data, |
| 298 | ) |
| 299 | |
| 300 | return ApiResponse( |
| 301 | status_code = response_data.status, |
| 302 | data = return_data, |
| 303 | headers = response_data.getheaders(), |
| 304 | raw_data = response_data.data |
| 305 | ) |
| 306 | |
| 307 | def sanitize_for_serialization(self, obj): |
| 308 | """Builds a JSON POST object. |
no test coverage detected