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

Function _get_representation

core/src/stdlib/pyscript/display.py:111–127  ·  view source on GitHub ↗

Call the given representation `method` on an object (`obj`). Handles special cases like matplotlib's `savefig`. Returns `None` if the `method` doesn't exist.

(obj, method)

Source from the content-addressed store, hash-verified

109
110
111def _get_representation(obj, method):
112 """
113 Call the given representation `method` on an object (`obj`).
114
115 Handles special cases like matplotlib's `savefig`. Returns `None`
116 if the `method` doesn't exist.
117 """
118 if method == "__repr__":
119 return repr(obj)
120 if not hasattr(obj, method):
121 return None
122 if method == "savefig":
123 buf = io.BytesIO()
124 obj.savefig(buf, format="png")
125 buf.seek(0)
126 return base64.b64encode(buf.read()).decode("utf-8")
127 return getattr(obj, method)()
128
129
130def _get_content_and_mime(obj):

Callers 1

_get_content_and_mimeFunction · 0.85

Calls 2

decodeMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected