##// END OF EJS Templates
do't define redundant _publish in core.display
MinRK -
Show More
@@ -23,6 +23,8 b' import os'
23
23
24 from IPython.utils.py3compat import string_types
24 from IPython.utils.py3compat import string_types
25
25
26 from .displaypub import publish_display_data
27
26 #-----------------------------------------------------------------------------
28 #-----------------------------------------------------------------------------
27 # utility functions
29 # utility functions
28 #-----------------------------------------------------------------------------
30 #-----------------------------------------------------------------------------
@@ -34,13 +36,6 b' def _safe_exists(path):'
34 except Exception:
36 except Exception:
35 return False
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 def _merge(d1, d2):
39 def _merge(d1, d2):
45 """Like update, but merges sub-dicts instead of clobbering at the top level.
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 d1[key] = _merge(d1.get(key), value)
48 d1[key] = _merge(d1.get(key), value)
54 return d1
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 # Main functions
74 # Main functions
58 #-----------------------------------------------------------------------------
75 #-----------------------------------------------------------------------------
@@ -92,30 +109,8 b' def display(*objs, **kwargs):'
92 if metadata:
109 if metadata:
93 # kwarg-specified metadata gets precedence
110 # kwarg-specified metadata gets precedence
94 _merge(md_dict, metadata)
111 _merge(md_dict, metadata)
95 _publish(format_dict, md_dict)
112 publish_display_data('display', format_dict, md_dict)
96
97 def _display_mimetype(mimetype, objs, raw=False, metadata=None):
98 """internal implementation of all display_foo methods
99
113
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])
118
119
114
120 def display_pretty(*objs, **kwargs):
115 def display_pretty(*objs, **kwargs):
121 """Display the pretty (default) representation of an object.
116 """Display the pretty (default) representation of an object.
General Comments 0
You need to be logged in to leave comments. Login now