Get an attribute `attr` from the underlying event object. Handles special conversion of binary data from JavaScript typed arrays to Python `memoryview` objects.
(self, attr)
| 98 | self._event = event |
| 99 | |
| 100 | def __getattr__(self, attr): |
| 101 | """ |
| 102 | Get an attribute `attr` from the underlying event object. |
| 103 | |
| 104 | Handles special conversion of binary data from JavaScript typed |
| 105 | arrays to Python `memoryview` objects. |
| 106 | """ |
| 107 | value = getattr(self._event, attr) |
| 108 | if attr == "data" and not isinstance(value, str): |
| 109 | if hasattr(value, "to_py"): |
| 110 | # Pyodide - convert JavaScript typed array to Python. |
| 111 | return value.to_py() |
| 112 | else: |
| 113 | # MicroPython - manually convert JS ArrayBuffer. |
| 114 | return memoryview(as_bytearray(value)) |
| 115 | return value |
| 116 | |
| 117 | |
| 118 | class WebSocket: |
nothing calls this directly
no test coverage detected