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

Method format_mime

IPython/core/oinspect.py:613–649  ·  view source on GitHub ↗

Format a mimebundle being created by _make_info_unformatted into a real mimebundle

(self, bundle: UnformattedBundle)

Source from the content-addressed store, hash-verified

611 return dict(defaults, **formatted)
612
613 def format_mime(self, bundle: UnformattedBundle) -> Bundle:
614 """Format a mimebundle being created by _make_info_unformatted into a real mimebundle"""
615 # Format text/plain mimetype
616 assert isinstance(bundle["text/plain"], list)
617 for item in bundle["text/plain"]:
618 assert isinstance(item, tuple)
619
620 new_b: Bundle = {}
621 lines = []
622 _len = max(len(h) for h, _ in bundle["text/plain"])
623
624 for head, body in bundle["text/plain"]:
625 body = body.strip("\n")
626 delim = "\n" if "\n" in body else " "
627 lines.append(
628 f"{self.__head(head+':')}{(_len - len(head))*' '}{delim}{body}"
629 )
630
631 new_b["text/plain"] = "\n".join(lines)
632
633 if "text/html" in bundle:
634 assert isinstance(bundle["text/html"], list)
635 for item in bundle["text/html"]:
636 assert isinstance(item, tuple)
637 # Format the text/html mimetype
638 if isinstance(bundle["text/html"], (list, tuple)):
639 # bundle['text/html'] is a list of (head, formatted body) pairs
640 new_b["text/html"] = "\n".join(
641 f"<h1>{head}</h1>\n{body}" for (head, body) in bundle["text/html"]
642 )
643
644 for k in bundle.keys():
645 if k in ("text/html", "text/plain"):
646 continue
647 else:
648 new_b[k] = bundle[k] # type:ignore
649 return new_b
650
651 def _append_info_field(
652 self,

Callers 1

_get_infoMethod · 0.95

Calls 2

__headMethod · 0.95
keysMethod · 0.80

Tested by

no test coverage detected