MCPcopy Index your code
hub / github.com/ipython/ipython / write_format_data

Method write_format_data

IPython/core/displayhook.py:169–208  ·  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

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