diff --git a/IPython/core/display.py b/IPython/core/display.py index 5411287..80f9f48 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -28,6 +28,8 @@ from .displaypub import ( publish_javascript, publish_jpeg ) +from IPython.utils.py3compat import string_types + #----------------------------------------------------------------------------- # Main functions #----------------------------------------------------------------------------- @@ -254,7 +256,7 @@ class DisplayObject(object): filename : unicode Path to a local file to load the data from. """ - if data is not None and data.startswith('http'): + if data is not None and isinstance(data, string_types) and data.startswith('http'): self.url = data self.filename = None self.data = None @@ -475,7 +477,7 @@ class Image(DisplayObject): ext = self._find_ext(url) elif data is None: raise ValueError("No image data found. Expecting filename, url, or data.") - elif data.startswith('http'): + elif isinstance(data, string_types) and data.startswith('http'): ext = self._find_ext(data) else: ext = None diff --git a/IPython/utils/py3compat.py b/IPython/utils/py3compat.py index b798271..6f7a19c 100644 --- a/IPython/utils/py3compat.py +++ b/IPython/utils/py3compat.py @@ -62,6 +62,8 @@ if sys.version_info[0] >= 3: bytes_to_str = decode cast_bytes_py2 = no_code + string_types = (str,) + def isidentifier(s, dotted=False): if dotted: return all(isidentifier(a) for a in s.split(".")) @@ -110,6 +112,8 @@ else: bytes_to_str = no_code cast_bytes_py2 = cast_bytes + string_types = (str, unicode) + import re _name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$") def isidentifier(s, dotted=False): diff --git a/examples/notebooks/Custom Display Logic.ipynb b/examples/notebooks/Custom Display Logic.ipynb index 79bb6cf..2c79875 100644 --- a/examples/notebooks/Custom Display Logic.ipynb +++ b/examples/notebooks/Custom Display Logic.ipynb @@ -143,7 +143,7 @@ "\n", " def _repr_svg_(self):\n", " if self._svg_data is None:\n", - " self._svg_data = self._figure_data('svg')\n", + " self._svg_data = self._figure_data('svg').decode('utf-8')\n", " return self._svg_data\n", " \n", " def _repr_latex_(self):\n", @@ -162,7 +162,7 @@ " \n", " @property\n", " def latex(self):\n", - " return Math(self._repr_svg_())\n", + " return Math(self._repr_latex_())\n", " \n", " # An example of using a property to display rich information, in this case\n", " # the histogram of the distribution. We've hardcoded the format to be png\n",