MCPcopy Create free account
hub / github.com/ipython/ipython / _repr_html_

Method _repr_html_

IPython/core/display.py:1412–1448  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1410 super(Video, self).__init__(data=data, url=url, filename=filename)
1411
1412 def _repr_html_(self):
1413 width = height = ''
1414 if self.width:
1415 width = ' width="%d"' % self.width
1416 if self.height:
1417 height = ' height="%d"' % self.height
1418
1419 # External URLs and potentially local files are not embedded into the
1420 # notebook output.
1421 if not self.embed:
1422 url = self.url if self.url is not None else self.filename
1423 output = """<video src="{0}" {1} {2} {3}>
1424 Your browser does not support the <code>video</code> element.
1425 </video>""".format(url, self.html_attributes, width, height)
1426 return output
1427
1428 # Embedded videos are base64-encoded.
1429 mimetype = self.mimetype
1430 if self.filename is not None:
1431 if not mimetype:
1432 mimetype, _ = mimetypes.guess_type(self.filename)
1433
1434 with open(self.filename, 'rb') as f:
1435 video = f.read()
1436 else:
1437 video = self.data
1438 if isinstance(video, str):
1439 # unicode input is already b64-encoded
1440 b64_video = video
1441 else:
1442 b64_video = b2a_base64(video).decode('ascii').rstrip()
1443
1444 output = """<video {0} {1} {2}>
1445 <source src="data:{3};base64,{4}" type="{3}">
1446 Your browser does not support the video tag.
1447 </video>""".format(self.html_attributes, width, height, mimetype, b64_video)
1448 return output
1449
1450 def reload(self):
1451 # TODO

Callers 1

test_video_embeddingFunction · 0.95

Calls 2

readMethod · 0.80
formatMethod · 0.45

Tested by 1

test_video_embeddingFunction · 0.76