MCPcopy Index your code
hub / github.com/pyscript/pyscript / __getattr__

Method __getattr__

core/src/stdlib/pyscript/websocket.py:100–115  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
118class WebSocket:

Callers

nothing calls this directly

Calls 1

as_bytearrayFunction · 0.90

Tested by

no test coverage detected