MCPcopy Create free account
hub / github.com/ipython/ipython / write_format_data

Method write_format_data

IPython/core/displayhook.py:156–195  ·  view source on GitHub ↗

Write the format data dict to the frontend. This default version of this method simply writes the plain text representation of the object to ``sys.stdout``. Subclasses should override this method to send the entire `format_dict` to the frontends. Parameters

(self, format_dict, md_dict=None)

Source from the content-addressed store, hash-verified

154 prompt_end_newline = False
155
156 def write_format_data(self, format_dict, md_dict=None) -> None:
157 """Write the format data dict to the frontend.
158
159 This default version of this method simply writes the plain text
160 representation of the object to ``sys.stdout``. Subclasses should
161 override this method to send the entire `format_dict` to the
162 frontends.
163
164 Parameters
165 ----------
166 format_dict : dict
167 The format dict for the object passed to `sys.displayhook`.
168 md_dict : dict (optional)
169 The metadata dict to be associated with the display data.
170 """
171 if 'text/plain' not in format_dict:
172 # nothing to do
173 return
174 # We want to print because we want to always make sure we have a
175 # newline, even if all the prompt separators are ''. This is the
176 # standard IPython behavior.
177 result_repr = format_dict['text/plain']
178 if '\n' in result_repr:
179 # So that multi-line strings line up with the left column of
180 # the screen, instead of having the output prompt mess up
181 # their first line.
182 # We use the prompt template instead of the expanded prompt
183 # because the expansion may add ANSI escapes that will interfere
184 # with our ability to determine whether or not we should add
185 # a newline.
186 if not self.prompt_end_newline:
187 # But avoid extraneous empty lines.
188 result_repr = '\n' + result_repr
189
190 try:
191 print(result_repr)
192 except UnicodeEncodeError:
193 # If a character is not supported by the terminal encoding replace
194 # it with its \u or \x representation
195 print(result_repr.encode(sys.stdout.encoding,'backslashreplace').decode(sys.stdout.encoding))
196
197 def update_user_ns(self, result):
198 """Update user_ns with various things like _, __, _1, etc."""

Callers 1

__call__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected