Show More
@@ -28,6 +28,8 b' from .displaypub import (' | |||||
28 | publish_javascript, publish_jpeg |
|
28 | publish_javascript, publish_jpeg | |
29 | ) |
|
29 | ) | |
30 |
|
30 | |||
|
31 | from IPython.utils.py3compat import string_types | |||
|
32 | ||||
31 | #----------------------------------------------------------------------------- |
|
33 | #----------------------------------------------------------------------------- | |
32 | # Main functions |
|
34 | # Main functions | |
33 | #----------------------------------------------------------------------------- |
|
35 | #----------------------------------------------------------------------------- | |
@@ -254,7 +256,7 b' class DisplayObject(object):' | |||||
254 | filename : unicode |
|
256 | filename : unicode | |
255 | Path to a local file to load the data from. |
|
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 | self.url = data |
|
260 | self.url = data | |
259 | self.filename = None |
|
261 | self.filename = None | |
260 | self.data = None |
|
262 | self.data = None | |
@@ -475,7 +477,7 b' class Image(DisplayObject):' | |||||
475 | ext = self._find_ext(url) |
|
477 | ext = self._find_ext(url) | |
476 | elif data is None: |
|
478 | elif data is None: | |
477 | raise ValueError("No image data found. Expecting filename, url, or data.") |
|
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 | ext = self._find_ext(data) |
|
481 | ext = self._find_ext(data) | |
480 | else: |
|
482 | else: | |
481 | ext = None |
|
483 | ext = None |
@@ -62,6 +62,8 b' if sys.version_info[0] >= 3:' | |||||
62 | bytes_to_str = decode |
|
62 | bytes_to_str = decode | |
63 | cast_bytes_py2 = no_code |
|
63 | cast_bytes_py2 = no_code | |
64 |
|
64 | |||
|
65 | string_types = (str,) | |||
|
66 | ||||
65 | def isidentifier(s, dotted=False): |
|
67 | def isidentifier(s, dotted=False): | |
66 | if dotted: |
|
68 | if dotted: | |
67 | return all(isidentifier(a) for a in s.split(".")) |
|
69 | return all(isidentifier(a) for a in s.split(".")) | |
@@ -110,6 +112,8 b' else:' | |||||
110 | bytes_to_str = no_code |
|
112 | bytes_to_str = no_code | |
111 | cast_bytes_py2 = cast_bytes |
|
113 | cast_bytes_py2 = cast_bytes | |
112 |
|
114 | |||
|
115 | string_types = (str, unicode) | |||
|
116 | ||||
113 | import re |
|
117 | import re | |
114 | _name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$") |
|
118 | _name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$") | |
115 | def isidentifier(s, dotted=False): |
|
119 | def isidentifier(s, dotted=False): |
@@ -143,7 +143,7 b'' | |||||
143 | "\n", |
|
143 | "\n", | |
144 | " def _repr_svg_(self):\n", |
|
144 | " def _repr_svg_(self):\n", | |
145 | " if self._svg_data is None:\n", |
|
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 | " return self._svg_data\n", |
|
147 | " return self._svg_data\n", | |
148 | " \n", |
|
148 | " \n", | |
149 | " def _repr_latex_(self):\n", |
|
149 | " def _repr_latex_(self):\n", | |
@@ -162,7 +162,7 b'' | |||||
162 | " \n", |
|
162 | " \n", | |
163 | " @property\n", |
|
163 | " @property\n", | |
164 | " def latex(self):\n", |
|
164 | " def latex(self):\n", | |
165 |
" return Math(self._repr_ |
|
165 | " return Math(self._repr_latex_())\n", | |
166 | " \n", |
|
166 | " \n", | |
167 | " # An example of using a property to display rich information, in this case\n", |
|
167 | " # An example of using a property to display rich information, in this case\n", | |
168 | " # the histogram of the distribution. We've hardcoded the format to be png\n", |
|
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