Create a display object given raw data. When this object is returned by an expression or passed to the display function, it will result in the data being displayed in the frontend. The MIME type of the data should match the subclasses used, so the Png subclass should
(self, data=None, url=None, filename=None, metadata=None)
| 295 | metadata = None |
| 296 | |
| 297 | def __init__(self, data=None, url=None, filename=None, metadata=None): |
| 298 | """Create a display object given raw data. |
| 299 | |
| 300 | When this object is returned by an expression or passed to the |
| 301 | display function, it will result in the data being displayed |
| 302 | in the frontend. The MIME type of the data should match the |
| 303 | subclasses used, so the Png subclass should be used for 'image/png' |
| 304 | data. If the data is a URL, the data will first be downloaded |
| 305 | and then displayed. |
| 306 | |
| 307 | Parameters |
| 308 | ---------- |
| 309 | data : unicode, str or bytes |
| 310 | The raw data or a URL or file to load the data from |
| 311 | url : unicode |
| 312 | A URL to download the data from. |
| 313 | filename : unicode |
| 314 | Path to a local file to load the data from. |
| 315 | metadata : dict |
| 316 | Dict of metadata associated to be the object when displayed |
| 317 | """ |
| 318 | if isinstance(data, (Path, PurePath)): |
| 319 | data = str(data) |
| 320 | |
| 321 | if data is not None and isinstance(data, str): |
| 322 | if data.startswith('http') and url is None: |
| 323 | url = data |
| 324 | filename = None |
| 325 | data = None |
| 326 | elif _safe_exists(data) and filename is None: |
| 327 | url = None |
| 328 | filename = data |
| 329 | data = None |
| 330 | |
| 331 | self.url = url |
| 332 | self.filename = filename |
| 333 | # because of @data.setter methods in |
| 334 | # subclasses ensure url and filename are set |
| 335 | # before assigning to self.data |
| 336 | self.data = data |
| 337 | |
| 338 | if metadata is not None: |
| 339 | self.metadata = metadata |
| 340 | elif self.metadata is None: |
| 341 | self.metadata = {} |
| 342 | |
| 343 | self.reload() |
| 344 | self._check_data() |
| 345 | |
| 346 | def __repr__(self): |
| 347 | if not self._show_mem_addr: |
nothing calls this directly
no test coverage detected