Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes to display objects in Python 3

  • Loading branch information...
commit f70e8ef9243bb18ec962b0b926899214a4623c35 1 parent 39aa83d
Thomas Kluyver authored
6 IPython/core/display.py
@@ -28,6 +28,8 @@
28 28 publish_javascript, publish_jpeg
29 29 )
30 30
  31 +from IPython.utils.py3compat import string_types
  32 +
31 33 #-----------------------------------------------------------------------------
32 34 # Main functions
33 35 #-----------------------------------------------------------------------------
@@ -254,7 +256,7 @@ def __init__(self, data=None, url=None, filename=None):
254 256 filename : unicode
255 257 Path to a local file to load the data from.
256 258 """
257   - if data is not None and data.startswith('http'):
  259 + if data is not None and isinstance(data, string_types) and data.startswith('http'):
258 260 self.url = data
259 261 self.filename = None
260 262 self.data = None
@@ -475,7 +477,7 @@ def __init__(self, data=None, url=None, filename=None, format=u'png', embed=None
475 477 ext = self._find_ext(url)
476 478 elif data is None:
477 479 raise ValueError("No image data found. Expecting filename, url, or data.")
478   - elif data.startswith('http'):
  480 + elif isinstance(data, string_types) and data.startswith('http'):
479 481 ext = self._find_ext(data)
480 482 else:
481 483 ext = None
4 IPython/utils/py3compat.py
@@ -62,6 +62,8 @@ def wrapper(func_or_str):
62 62 bytes_to_str = decode
63 63 cast_bytes_py2 = no_code
64 64
  65 + string_types = (str,)
  66 +
65 67 def isidentifier(s, dotted=False):
66 68 if dotted:
67 69 return all(isidentifier(a) for a in s.split("."))
@@ -110,6 +112,8 @@ def u_format(s):
110 112 bytes_to_str = no_code
111 113 cast_bytes_py2 = cast_bytes
112 114
  115 + string_types = (str, unicode)
  116 +
113 117 import re
114 118 _name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$")
115 119 def isidentifier(s, dotted=False):
4 docs/examples/notebooks/display_protocol.ipynb
@@ -113,7 +113,7 @@
113 113 "\n",
114 114 " def _repr_svg_(self):\n",
115 115 " if self._svg_data is None:\n",
116   - " self._svg_data = self._figure_data('svg')\n",
  116 + " self._svg_data = self._figure_data('svg').decode('utf-8')\n",
117 117 " return self._svg_data\n",
118 118 " \n",
119 119 " def _repr_latex_(self):\n",
@@ -132,7 +132,7 @@
132 132 " \n",
133 133 " @property\n",
134 134 " def latex(self):\n",
135   - " return Math(self._repr_svg_())\n",
  135 + " return Math(self._repr_latex_())\n",
136 136 " \n",
137 137 " # An example of using a property to display rich information, in this case\n",
138 138 " # the histogram of the distribution. We've hardcoded the format to be png\n",

0 comments on commit f70e8ef

Please sign in to comment.
Something went wrong with that request. Please try again.