##// END OF EJS Templates
Allow passing pathlib Paths without keyword arg...
Alok Singh -
Show More
@@ -14,6 +14,7 b' import sys'
14 14 import warnings
15 15 from copy import deepcopy
16 16 from os.path import splitext
17 from pathlib import Path, PurePath
17 18
18 19 from IPython.utils.py3compat import cast_unicode
19 20 from IPython.testing.skipdoctest import skip_doctest
@@ -594,6 +595,9 b' class DisplayObject(object):'
594 595 metadata : dict
595 596 Dict of metadata associated to be the object when displayed
596 597 """
598 if isinstance(data, (Path, PurePath)):
599 data = str(data)
600
597 601 if data is not None and isinstance(data, str):
598 602 if data.startswith('http') and url is None:
599 603 url = data
@@ -864,6 +868,9 b' class JSON(DisplayObject):'
864 868
865 869 @data.setter
866 870 def data(self, data):
871 if isinstance(data, (Path, PurePath)):
872 data = str(data)
873
867 874 if isinstance(data, str):
868 875 if getattr(self, 'filename', None) is None:
869 876 warnings.warn("JSON expects JSONable dict or list, not JSON strings")
@@ -1134,6 +1141,9 b' class Image(DisplayObject):'
1134 1141 Image(url='http://www.google.fr/images/srpr/logo3w.png')
1135 1142
1136 1143 """
1144 if isinstance(data, (Path, PurePath)):
1145 data = str(data)
1146
1137 1147 if filename is not None:
1138 1148 ext = self._find_ext(filename)
1139 1149 elif url is not None:
@@ -1338,6 +1348,9 b' class Video(DisplayObject):'
1338 1348 Video('path/to/video.mp4', embed=True)
1339 1349 Video(b'raw-videodata', embed=True)
1340 1350 """
1351 if isinstance(data, (Path, PurePath)):
1352 data = str(data)
1353
1341 1354 if url is None and isinstance(data, str) and data.startswith(('http:', 'https:')):
1342 1355 url = data
1343 1356 data = None
General Comments 0
You need to be logged in to leave comments. Login now