Show More
@@ -667,7 +667,19 b' class Pretty(TextDisplayObject):' | |||||
667 | class HTML(TextDisplayObject): |
|
667 | class HTML(TextDisplayObject): | |
668 |
|
668 | |||
669 | def __init__(self, data=None, url=None, filename=None, metadata=None): |
|
669 | def __init__(self, data=None, url=None, filename=None, metadata=None): | |
670 | if data and data.startswith("<iframe ") and data.endswith("</iframe>"): |
|
670 | def warn(): | |
|
671 | if not data: | |||
|
672 | return False | |||
|
673 | ||||
|
674 | # | |||
|
675 | # Avoid calling lower() on the entire data, because it could be a | |||
|
676 | # long string and we're only interested in its beginning and end. | |||
|
677 | # | |||
|
678 | prefix = data[:10].lower() | |||
|
679 | suffix = data[-10:].lower() | |||
|
680 | return prefix.startswith("<iframe ") and suffix.endswith("</iframe>") | |||
|
681 | ||||
|
682 | if warn(): | |||
671 | warnings.warn("Consider using IPython.display.IFrame instead") |
|
683 | warnings.warn("Consider using IPython.display.IFrame instead") | |
672 | super(HTML, self).__init__(data=data, url=url, filename=filename, metadata=metadata) |
|
684 | super(HTML, self).__init__(data=data, url=url, filename=filename, metadata=metadata) | |
673 |
|
685 |
@@ -197,6 +197,9 b' def test_displayobject_repr():' | |||||
197 |
|
197 | |||
198 | @mock.patch('warnings.warn') |
|
198 | @mock.patch('warnings.warn') | |
199 | def test_encourage_iframe_over_html(m_warn): |
|
199 | def test_encourage_iframe_over_html(m_warn): | |
|
200 | display.HTML() | |||
|
201 | m_warn.assert_not_called() | |||
|
202 | ||||
200 | display.HTML('<br />') |
|
203 | display.HTML('<br />') | |
201 | m_warn.assert_not_called() |
|
204 | m_warn.assert_not_called() | |
202 |
|
205 | |||
@@ -206,6 +209,10 b' def test_encourage_iframe_over_html(m_warn):' | |||||
206 | display.HTML('<iframe src="http://a.com"></iframe>') |
|
209 | display.HTML('<iframe src="http://a.com"></iframe>') | |
207 | m_warn.assert_called_with('Consider using IPython.display.IFrame instead') |
|
210 | m_warn.assert_called_with('Consider using IPython.display.IFrame instead') | |
208 |
|
211 | |||
|
212 | m_warn.reset_mock() | |||
|
213 | display.HTML('<IFRAME SRC="http://a.com"></IFRAME>') | |||
|
214 | m_warn.assert_called_with('Consider using IPython.display.IFrame instead') | |||
|
215 | ||||
209 | def test_progress(): |
|
216 | def test_progress(): | |
210 | p = display.ProgressBar(10) |
|
217 | p = display.ProgressBar(10) | |
211 | nt.assert_in('0/10',repr(p)) |
|
218 | nt.assert_in('0/10',repr(p)) |
General Comments 0
You need to be logged in to leave comments.
Login now