##// END OF EJS Templates
Fix 'Custom Display Logic' example notebook for Python 3
Thomas Kluyver -
Show More
@@ -28,6 +28,8 b' from .displaypub import ('
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 b' class DisplayObject(object):'
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 b' class Image(DisplayObject):'
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
@@ -62,6 +62,8 b' if sys.version_info[0] >= 3:'
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 b' else:'
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):
@@ -143,7 +143,7 b''
143 143 "\n",
144 144 " def _repr_svg_(self):\n",
145 145 " if self._svg_data is None:\n",
146 " self._svg_data = self._figure_data('svg')\n",
146 " self._svg_data = self._figure_data('svg').decode('utf-8')\n",
147 147 " return self._svg_data\n",
148 148 " \n",
149 149 " def _repr_latex_(self):\n",
@@ -162,7 +162,7 b''
162 162 " \n",
163 163 " @property\n",
164 164 " def latex(self):\n",
165 " return Math(self._repr_svg_())\n",
165 " return Math(self._repr_latex_())\n",
166 166 " \n",
167 167 " # An example of using a property to display rich information, in this case\n",
168 168 " # the histogram of the distribution. We've hardcoded the format to be png\n",
General Comments 0
You need to be logged in to leave comments. Login now