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)
| 109 | |
| 110 | |
| 111 | def _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 | |
| 130 | def _get_content_and_mime(obj): |
no test coverage detected