diff --git a/IPython/core/display.py b/IPython/core/display.py index 8c043a1..e99a4fa 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -126,13 +126,13 @@ def display(*objs, **kwargs): else: continue if raw: - publish_display_data('display', obj, metadata) + publish_display_data(data=obj, metadata=metadata) else: format_dict, md_dict = format(obj, include=include, exclude=exclude) if metadata: # kwarg-specified metadata gets precedence _merge(md_dict, metadata) - publish_display_data('display', format_dict, md_dict) + publish_display_data(data=format_dict, metadata=md_dict) def display_pretty(*objs, **kwargs): diff --git a/IPython/core/displaypub.py b/IPython/core/displaypub.py index dedd9e9..99c4a61 100644 --- a/IPython/core/displaypub.py +++ b/IPython/core/displaypub.py @@ -10,22 +10,10 @@ There are two components of the display system: This module defines the logic display publishing. The display publisher uses the ``display_data`` message type that is defined in the IPython messaging spec. - -Authors: - -* Brian Granger """ -#----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. from __future__ import print_function @@ -45,29 +33,24 @@ class DisplayPublisher(Configurable): be accessed there. """ - def _validate_data(self, source, data, metadata=None): + def _validate_data(self, data, metadata=None): """Validate the display data. Parameters ---------- - source : str - The fully dotted name of the callable that created the data, like - :func:`foo.bar.my_formatter`. data : dict The formata data dictionary. metadata : dict Any metadata for the data. """ - if not isinstance(source, string_types): - raise TypeError('source must be a str, got: %r' % source) if not isinstance(data, dict): raise TypeError('data must be a dict, got: %r' % data) if metadata is not None: if not isinstance(metadata, dict): raise TypeError('metadata must be a dict, got: %r' % data) - def publish(self, source, data, metadata=None): + def publish(self, data, metadata=None, source=None): """Publish data and metadata to all frontends. See the ``display_data`` message in the messaging documentation for @@ -87,9 +70,6 @@ class DisplayPublisher(Configurable): Parameters ---------- - source : str - A string that give the function or method that created the data, - such as 'IPython.core.page'. data : dict A dictionary having keys that are valid MIME types (like 'text/plain' or 'image/svg+xml') and values that are the data for @@ -104,6 +84,8 @@ class DisplayPublisher(Configurable): the data. Metadata specific to each mime-type can be specified in the metadata dict with the same mime-type keys as the data itself. + source : str, deprecated + Unused. """ # The default is to simply write the plain text data using io.stdout. @@ -122,8 +104,8 @@ class CapturingDisplayPublisher(DisplayPublisher): """A DisplayPublisher that stores""" outputs = List() - def publish(self, source, data, metadata=None): - self.outputs.append((source, data, metadata)) + def publish(self, data, metadata=None, source=None): + self.outputs.append((data, metadata)) def clear_output(self, wait=False): super(CapturingDisplayPublisher, self).clear_output(wait) @@ -132,7 +114,7 @@ class CapturingDisplayPublisher(DisplayPublisher): del self.outputs[:] -def publish_display_data(source, data, metadata=None): +def publish_display_data(data, metadata=None, source=None): """Publish data and metadata to all frontends. See the ``display_data`` message in the messaging documentation for @@ -152,9 +134,6 @@ def publish_display_data(source, data, metadata=None): Parameters ---------- - source : str - A string that give the function or method that created the data, - such as 'IPython.core.page'. data : dict A dictionary having keys that are valid MIME types (like 'text/plain' or 'image/svg+xml') and values that are the data for @@ -168,12 +147,13 @@ def publish_display_data(source, data, metadata=None): arbitrary key, value pairs that frontends can use to interpret the data. mime-type keys matching those in data can be used to specify metadata about particular representations. + source : str, deprecated + Unused. """ from IPython.core.interactiveshell import InteractiveShell InteractiveShell.instance().display_pub.publish( - source, - data, - metadata + data=data, + metadata=metadata, ) diff --git a/IPython/kernel/tests/test_message_spec.py b/IPython/kernel/tests/test_message_spec.py index ad49285..f67f2f6 100644 --- a/IPython/kernel/tests/test_message_spec.py +++ b/IPython/kernel/tests/test_message_spec.py @@ -165,7 +165,7 @@ class Stream(Reference): class DisplayData(MimeBundle): - source = Unicode() + pass class ExecuteResult(MimeBundle): diff --git a/IPython/kernel/zmq/zmqshell.py b/IPython/kernel/zmq/zmqshell.py index 9ea1de1..cd1326d 100644 --- a/IPython/kernel/zmq/zmqshell.py +++ b/IPython/kernel/zmq/zmqshell.py @@ -73,13 +73,12 @@ class ZMQDisplayPublisher(DisplayPublisher): sys.stdout.flush() sys.stderr.flush() - def publish(self, source, data, metadata=None): + def publish(self, data, metadata=None, source=None): self._flush_streams() if metadata is None: metadata = {} - self._validate_data(source, data, metadata) + self._validate_data(data, metadata) content = {} - content['source'] = source content['data'] = encode_images(data) content['metadata'] = metadata self.session.send( diff --git a/IPython/parallel/client/client.py b/IPython/parallel/client/client.py index d4181fd..fe6203d 100644 --- a/IPython/parallel/client/client.py +++ b/IPython/parallel/client/client.py @@ -90,7 +90,7 @@ class ExecuteReply(RichOutput): def display(self): from IPython.display import publish_display_data - publish_display_data(self.source, self.data, self.metadata) + publish_display_data(self.data, self.metadata) def _repr_mime_(self, mime): if mime not in self.data: diff --git a/IPython/utils/capture.py b/IPython/utils/capture.py index 01ad4e8..1731bf2 100644 --- a/IPython/utils/capture.py +++ b/IPython/utils/capture.py @@ -1,19 +1,10 @@ # encoding: utf-8 -""" -IO capturing utilities. -""" +"""IO capturing utilities.""" -#----------------------------------------------------------------------------- -# Copyright (C) 2013 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- -from __future__ import print_function, absolute_import +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +from __future__ import print_function, absolute_import import sys @@ -30,14 +21,13 @@ else: class RichOutput(object): - def __init__(self, source="", data=None, metadata=None): - self.source = source + def __init__(self, data=None, metadata=None): self.data = data or {} self.metadata = metadata or {} def display(self): from IPython.display import publish_display_data - publish_display_data(self.source, self.data, self.metadata) + publish_display_data(data=self.data, metadata=self.metadata) def _repr_mime_(self, mime): if mime not in self.data: @@ -118,7 +108,7 @@ class CapturedIO(object): for o in c.outputs: display(o) """ - return [ RichOutput(s, d, md) for s, d, md in self._outputs ] + return [ RichOutput(d, md) for d, md in self._outputs ] def show(self): """write my output to sys.stdout/err as appropriate""" @@ -126,8 +116,8 @@ class CapturedIO(object): sys.stderr.write(self.stderr) sys.stdout.flush() sys.stderr.flush() - for source, data, metadata in self._outputs: - RichOutput(source, data, metadata).display() + for data, metadata in self._outputs: + RichOutput(data, metadata).display() __call__ = show diff --git a/IPython/utils/tests/test_capture.py b/IPython/utils/tests/test_capture.py index f3305d5..30345d7 100644 --- a/IPython/utils/tests/test_capture.py +++ b/IPython/utils/tests/test_capture.py @@ -78,8 +78,7 @@ def test_rich_output(): """test RichOutput basics""" data = basic_data metadata = basic_metadata - rich = capture.RichOutput(source="test", data=data, metadata=metadata) - yield nt.assert_equal, rich.source, "test" + rich = capture.RichOutput(data=data, metadata=metadata) yield nt.assert_equal, rich._repr_html_(), data['text/html'] yield nt.assert_equal, rich._repr_png_(), (data['image/png'], metadata['image/png']) yield nt.assert_equal, rich._repr_latex_(), None @@ -89,7 +88,7 @@ def test_rich_output(): def test_rich_output_no_metadata(): """test RichOutput with no metadata""" data = full_data - rich = capture.RichOutput(source="test", data=data) + rich = capture.RichOutput(data=data) for method, mime in _mime_map.items(): yield nt.assert_equal, getattr(rich, method)(), data[mime] @@ -97,7 +96,7 @@ def test_rich_output_metadata(): """test RichOutput with metadata""" data = full_data metadata = full_metadata - rich = capture.RichOutput(source="test", data=data, metadata=metadata) + rich = capture.RichOutput(data=data, metadata=metadata) for method, mime in _mime_map.items(): yield nt.assert_equal, getattr(rich, method)(), (data[mime], metadata[mime])