| 869 | return |
| 870 | |
| 871 | class _CompatTransaction: |
| 872 | def __init__(self, cdp_generator, tx_id: int): |
| 873 | method, *params = next(cdp_generator).values() |
| 874 | params = params.pop() if params else {} |
| 875 | self.id = tx_id |
| 876 | self.message = json.dumps({"method": method, "params": params, "id": tx_id}) |
| 877 | self._cdp_generator = cdp_generator |
| 878 | self._future = asyncio.get_running_loop().create_future() |
| 879 | |
| 880 | def __call__(self, **response): |
| 881 | if self._future.done(): |
| 882 | return |
| 883 | if "error" in response: |
| 884 | self._future.set_exception(RuntimeError(str(response["error"]))) |
| 885 | return |
| 886 | try: |
| 887 | self._cdp_generator.send(response.get("result")) |
| 888 | except StopIteration as e: |
| 889 | self._future.set_result(e.value) |
| 890 | except Exception as e: |
| 891 | self._future.set_exception(e) |
| 892 | |
| 893 | def __await__(self): |
| 894 | return self._future.__await__() |
| 895 | |
| 896 | def done(self) -> bool: |
| 897 | return self._future.done() |
| 898 | |
| 899 | def cancel(self): |
| 900 | self._future.cancel() |
| 901 | |
| 902 | async def patched_send(self, cdp_obj, _is_update=False): |
| 903 | if _is_nodriver_connection_closed(self): |