(self, msg: ParsedMessagePayload)
| 406 | return callback |
| 407 | |
| 408 | def dispatch(self, msg: ParsedMessagePayload) -> None: |
| 409 | if self._closed_error: |
| 410 | return |
| 411 | id = msg.get("id") |
| 412 | if id: |
| 413 | callback = self._callbacks.pop(id) |
| 414 | if callback.future.cancelled(): |
| 415 | return |
| 416 | # No reply messages are used to e.g. __waitInfo__(after) which returns exceptions on page close. |
| 417 | # To prevent 'Future exception was never retrieved' we just ignore such messages. |
| 418 | if callback.no_reply: |
| 419 | return |
| 420 | error = msg.get("error") |
| 421 | if error and not msg.get("result"): |
| 422 | parsed_error = parse_error( |
| 423 | error["error"], format_call_log(msg.get("log")) # type: ignore |
| 424 | ) |
| 425 | parsed_error._log = msg.get("log") |
| 426 | parsed_error._details = self._replace_guids_with_channels( |
| 427 | msg.get("errorDetails") |
| 428 | ) |
| 429 | parsed_error._stack = "".join(callback.stack_trace.format()) |
| 430 | callback.future.set_exception(parsed_error) |
| 431 | else: |
| 432 | result = self._replace_guids_with_channels(msg.get("result")) |
| 433 | callback.future.set_result(result) |
| 434 | return |
| 435 | |
| 436 | guid = msg["guid"] |
| 437 | method = msg["method"] |
| 438 | params = msg.get("params") |
| 439 | if method == "__create__": |
| 440 | assert params |
| 441 | parent = self._objects[guid] |
| 442 | self._create_remote_object( |
| 443 | parent, params["type"], params["guid"], params["initializer"] |
| 444 | ) |
| 445 | return |
| 446 | |
| 447 | object = self._objects.get(guid) |
| 448 | if not object: |
| 449 | raise Exception(f'Cannot find object to "{method}": {guid}') |
| 450 | |
| 451 | if method == "__adopt__": |
| 452 | child_guid = cast(Dict[str, str], params)["guid"] |
| 453 | child = self._objects.get(child_guid) |
| 454 | if not child: |
| 455 | raise Exception(f"Unknown new child: {child_guid}") |
| 456 | object._adopt(child) |
| 457 | return |
| 458 | |
| 459 | if method == "__dispose__": |
| 460 | assert isinstance(params, dict) |
| 461 | self._objects[guid]._dispose(cast(Optional[str], params.get("reason"))) |
| 462 | return |
| 463 | object = self._objects[guid] |
| 464 | should_replace_guids_with_channels = "jsonPipe@" not in guid |
| 465 | try: |
no test coverage detected