| 110 | |
| 111 | |
| 112 | def from_json(json_msg, update_ids_from_dap=False, on_dict_loaded=lambda dct: None): |
| 113 | if isinstance(json_msg, bytes): |
| 114 | json_msg = json_msg.decode("utf-8") |
| 115 | |
| 116 | as_dict = json.loads(json_msg) |
| 117 | on_dict_loaded(as_dict) |
| 118 | try: |
| 119 | return from_dict(as_dict, update_ids_from_dap=update_ids_from_dap) |
| 120 | except: |
| 121 | if as_dict.get("type") == "response" and not as_dict.get("success"): |
| 122 | # Error messages may not have required body (return as a generic Response). |
| 123 | Response = _all_messages["Response"] |
| 124 | return Response(**as_dict) |
| 125 | else: |
| 126 | raise |
| 127 | |
| 128 | |
| 129 | def get_response_class(request): |