Show More
@@ -304,6 +304,11 b' class DisplayObject(object):' | |||
|
304 | 304 | self.filename = None if filename is None else unicode_type(filename) |
|
305 | 305 | |
|
306 | 306 | self.reload() |
|
307 | self._check_data() | |
|
308 | ||
|
309 | def _check_data(self): | |
|
310 | """Override in subclasses if there's something to check.""" | |
|
311 | pass | |
|
307 | 312 | |
|
308 | 313 | def reload(self): |
|
309 | 314 | """Reload the raw data from file or URL.""" |
@@ -331,13 +336,19 b' class DisplayObject(object):' | |||
|
331 | 336 | except: |
|
332 | 337 | self.data = None |
|
333 | 338 | |
|
334 |
class |
|
|
339 | class TextDisplayObject(DisplayObject): | |
|
340 | """Validate that display data is text""" | |
|
341 | def _check_data(self): | |
|
342 | if self.data is not None and not isinstance(self.data, string_types): | |
|
343 | raise TypeError("%s xpects text, not %r" % (self.__class__.__name__, self.data)) | |
|
344 | ||
|
345 | class Pretty(TextDisplayObject): | |
|
335 | 346 | |
|
336 | 347 | def _repr_pretty_(self): |
|
337 | 348 | return self.data |
|
338 | 349 | |
|
339 | 350 | |
|
340 | class HTML(DisplayObject): | |
|
351 | class HTML(TextDisplayObject): | |
|
341 | 352 | |
|
342 | 353 | def _repr_html_(self): |
|
343 | 354 | return self.data |
@@ -351,14 +362,14 b' class HTML(DisplayObject):' | |||
|
351 | 362 | return self._repr_html_() |
|
352 | 363 | |
|
353 | 364 | |
|
354 | class Math(DisplayObject): | |
|
365 | class Math(TextDisplayObject): | |
|
355 | 366 | |
|
356 | 367 | def _repr_latex_(self): |
|
357 | 368 | s = self.data.strip('$') |
|
358 | 369 | return "$$%s$$" % s |
|
359 | 370 | |
|
360 | 371 | |
|
361 | class Latex(DisplayObject): | |
|
372 | class Latex(TextDisplayObject): | |
|
362 | 373 | |
|
363 | 374 | def _repr_latex_(self): |
|
364 | 375 | return self.data |
@@ -398,7 +409,7 b' class SVG(DisplayObject):' | |||
|
398 | 409 | return self.data |
|
399 | 410 | |
|
400 | 411 | |
|
401 | class JSON(DisplayObject): | |
|
412 | class JSON(TextDisplayObject): | |
|
402 | 413 | |
|
403 | 414 | def _repr_json_(self): |
|
404 | 415 | return self.data |
@@ -415,7 +426,7 b' lib_t1 = """$.getScript("%s", function () {' | |||
|
415 | 426 | lib_t2 = """}); |
|
416 | 427 | """ |
|
417 | 428 | |
|
418 | class Javascript(DisplayObject): | |
|
429 | class Javascript(TextDisplayObject): | |
|
419 | 430 | |
|
420 | 431 | def __init__(self, data=None, url=None, filename=None, lib=None, css=None): |
|
421 | 432 | """Create a Javascript display object given raw data. |
General Comments 0
You need to be logged in to leave comments.
Login now