Show More
@@ -23,6 +23,8 b' import os' | |||
|
23 | 23 | |
|
24 | 24 | from IPython.utils.py3compat import string_types |
|
25 | 25 | |
|
26 | from .displaypub import publish_display_data | |
|
27 | ||
|
26 | 28 | #----------------------------------------------------------------------------- |
|
27 | 29 | # utility functions |
|
28 | 30 | #----------------------------------------------------------------------------- |
@@ -34,13 +36,6 b' def _safe_exists(path):' | |||
|
34 | 36 | except Exception: |
|
35 | 37 | return False |
|
36 | 38 | |
|
37 | def _publish(data, metadata): | |
|
38 | """publish a display message""" | |
|
39 | from IPython.core.interactiveshell import InteractiveShell | |
|
40 | return InteractiveShell.instance().display_pub.publish( | |
|
41 | "display", data, metadata | |
|
42 | ) | |
|
43 | ||
|
44 | 39 | def _merge(d1, d2): |
|
45 | 40 | """Like update, but merges sub-dicts instead of clobbering at the top level. |
|
46 | 41 | |
@@ -53,6 +48,28 b' def _merge(d1, d2):' | |||
|
53 | 48 | d1[key] = _merge(d1.get(key), value) |
|
54 | 49 | return d1 |
|
55 | 50 | |
|
51 | def _display_mimetype(mimetype, objs, raw=False, metadata=None): | |
|
52 | """internal implementation of all display_foo methods | |
|
53 | ||
|
54 | Parameters | |
|
55 | ---------- | |
|
56 | mimetype : str | |
|
57 | The mimetype to be published (e.g. 'image/png') | |
|
58 | objs : tuple of objects | |
|
59 | The Python objects to display, or if raw=True raw text data to | |
|
60 | display. | |
|
61 | raw : bool | |
|
62 | Are the data objects raw data or Python objects that need to be | |
|
63 | formatted before display? [default: False] | |
|
64 | metadata : dict (optional) | |
|
65 | Metadata to be associated with the output. | |
|
66 | """ | |
|
67 | if raw: | |
|
68 | for obj in objs: | |
|
69 | publish_display_data('display', {mimetype : obj}, metadata) | |
|
70 | else: | |
|
71 | display(*objs, metadata=metadata, include=[mimetype]) | |
|
72 | ||
|
56 | 73 | #----------------------------------------------------------------------------- |
|
57 | 74 | # Main functions |
|
58 | 75 | #----------------------------------------------------------------------------- |
@@ -92,29 +109,7 b' def display(*objs, **kwargs):' | |||
|
92 | 109 | if metadata: |
|
93 | 110 | # kwarg-specified metadata gets precedence |
|
94 | 111 | _merge(md_dict, metadata) |
|
95 |
|
|
|
96 | ||
|
97 | def _display_mimetype(mimetype, objs, raw=False, metadata=None): | |
|
98 | """internal implementation of all display_foo methods | |
|
99 | ||
|
100 | Parameters | |
|
101 | ---------- | |
|
102 | mimetype : str | |
|
103 | The mimetype to be published (e.g. 'image/png') | |
|
104 | objs : tuple of objects | |
|
105 | The Python objects to display, or if raw=True raw text data to | |
|
106 | display. | |
|
107 | raw : bool | |
|
108 | Are the data objects raw data or Python objects that need to be | |
|
109 | formatted before display? [default: False] | |
|
110 | metadata : dict (optional) | |
|
111 | Metadata to be associated with the output. | |
|
112 | """ | |
|
113 | if raw: | |
|
114 | for obj in objs: | |
|
115 | _publish({mimetype : obj}, metadata) | |
|
116 | else: | |
|
117 | display(*objs, metadata=metadata, include=[mimetype]) | |
|
112 | publish_display_data('display', format_dict, md_dict) | |
|
118 | 113 | |
|
119 | 114 | |
|
120 | 115 | def display_pretty(*objs, **kwargs): |
General Comments 0
You need to be logged in to leave comments.
Login now