Show More
@@ -801,9 +801,20 b' class Image(DisplayObject):' | |||||
801 | _FMT_GIF: 'image/gif', |
|
801 | _FMT_GIF: 'image/gif', | |
802 | } |
|
802 | } | |
803 |
|
803 | |||
804 | def __init__(self, data=None, url=None, filename=None, format=None, |
|
804 | def __init__( | |
805 | embed=None, width=None, height=None, retina=False, |
|
805 | self, | |
806 | unconfined=False, metadata=None, alt=None): |
|
806 | data=None, | |
|
807 | url=None, | |||
|
808 | filename=None, | |||
|
809 | format=None, | |||
|
810 | embed=None, | |||
|
811 | width=None, | |||
|
812 | height=None, | |||
|
813 | retina=False, | |||
|
814 | unconfined=False, | |||
|
815 | metadata=None, | |||
|
816 | alt=None, | |||
|
817 | ): | |||
807 | """Create a PNG/JPEG/GIF image object given raw data. |
|
818 | """Create a PNG/JPEG/GIF image object given raw data. | |
808 |
|
819 | |||
809 | When this object is returned by an input cell or passed to the |
|
820 | When this object is returned by an input cell or passed to the | |
@@ -937,8 +948,8 b' class Image(DisplayObject):' | |||||
937 | if self.height is None and self.metadata.get('height', {}): |
|
948 | if self.height is None and self.metadata.get('height', {}): | |
938 | self.height = metadata['height'] |
|
949 | self.height = metadata['height'] | |
939 |
|
950 | |||
940 |
if self.alt is None and self.metadata.get( |
|
951 | if self.alt is None and self.metadata.get("alt", {}): | |
941 |
self.alt = metadata[ |
|
952 | self.alt = metadata["alt"] | |
942 |
|
953 | |||
943 | if retina: |
|
954 | if retina: | |
944 | self._retina_shape() |
|
955 | self._retina_shape() | |
@@ -969,7 +980,7 b' class Image(DisplayObject):' | |||||
969 |
|
980 | |||
970 | def _repr_html_(self): |
|
981 | def _repr_html_(self): | |
971 | if not self.embed: |
|
982 | if not self.embed: | |
972 |
width = height = klass = alt = |
|
983 | width = height = klass = alt = "" | |
973 | if self.width: |
|
984 | if self.width: | |
974 | width = ' width="%d"' % self.width |
|
985 | width = ' width="%d"' % self.width | |
975 | if self.height: |
|
986 | if self.height: | |
@@ -978,7 +989,7 b' class Image(DisplayObject):' | |||||
978 | klass = ' class="unconfined"' |
|
989 | klass = ' class="unconfined"' | |
979 | if self.alt: |
|
990 | if self.alt: | |
980 | alt = ' alt="%s"' % html.escape(self.alt) |
|
991 | alt = ' alt="%s"' % html.escape(self.alt) | |
981 |
return |
|
992 | return '<img src="{url}"{width}{height}{klass}{alt}/>'.format( | |
982 | url=self.url, |
|
993 | url=self.url, | |
983 | width=width, |
|
994 | width=width, | |
984 | height=height, |
|
995 | height=height, | |
@@ -1017,7 +1028,7 b' class Image(DisplayObject):' | |||||
1017 | if self.unconfined: |
|
1028 | if self.unconfined: | |
1018 | md['unconfined'] = self.unconfined |
|
1029 | md['unconfined'] = self.unconfined | |
1019 | if self.alt: |
|
1030 | if self.alt: | |
1020 |
md[ |
|
1031 | md["alt"] = self.alt | |
1021 | if md or always_both: |
|
1032 | if md or always_both: | |
1022 | return b64_data, md |
|
1033 | return b64_data, md | |
1023 | else: |
|
1034 | else: |
@@ -94,9 +94,9 b' def test_embed_svg_url():' | |||||
94 |
|
94 | |||
95 | if args[0] == url: |
|
95 | if args[0] == url: | |
96 | return MockResponse(svg_data) |
|
96 | return MockResponse(svg_data) | |
97 |
elif args[0] == url + |
|
97 | elif args[0] == url + "z": | |
98 | ret= MockResponse(gzip_svg) |
|
98 | ret = MockResponse(gzip_svg) | |
99 |
ret.headers[ |
|
99 | ret.headers["content-encoding"] = "gzip" | |
100 | return ret |
|
100 | return ret | |
101 | return MockResponse(None) |
|
101 | return MockResponse(None) | |
102 |
|
102 | |||
@@ -459,19 +459,24 b' def test_display_handle():' | |||||
459 |
|
459 | |||
460 | def test_image_alt_tag(): |
|
460 | def test_image_alt_tag(): | |
461 | """Simple test for display.Image(args, alt=x,)""" |
|
461 | """Simple test for display.Image(args, alt=x,)""" | |
462 |
thisurl = |
|
462 | thisurl = "http://example.com/image.png" | |
463 |
img = display.Image(url=thisurl, alt= |
|
463 | img = display.Image(url=thisurl, alt="an image") | |
464 | nt.assert_equal(u'<img src="%s" alt="an image"/>' % (thisurl), img._repr_html_()) |
|
464 | nt.assert_equal(u'<img src="%s" alt="an image"/>' % (thisurl), img._repr_html_()) | |
465 |
img = display.Image(url=thisurl, unconfined=True, alt= |
|
465 | img = display.Image(url=thisurl, unconfined=True, alt="an image") | |
466 | nt.assert_equal(u'<img src="%s" class="unconfined" alt="an image"/>' % (thisurl), img._repr_html_()) |
|
466 | nt.assert_equal( | |
|
467 | u'<img src="%s" class="unconfined" alt="an image"/>' % (thisurl), | |||
|
468 | img._repr_html_(), | |||
|
469 | ) | |||
467 | img = display.Image(url=thisurl, alt='>"& <') |
|
470 | img = display.Image(url=thisurl, alt='>"& <') | |
468 | nt.assert_equal(u'<img src="%s" alt=">"& <"/>' % (thisurl), img._repr_html_()) |
|
471 | nt.assert_equal( | |
|
472 | u'<img src="%s" alt=">"& <"/>' % (thisurl), img._repr_html_() | |||
|
473 | ) | |||
469 |
|
474 | |||
470 |
img = display.Image(url=thisurl, metadata={ |
|
475 | img = display.Image(url=thisurl, metadata={"alt": "an image"}) | |
471 |
nt.assert_equal(img.alt, |
|
476 | nt.assert_equal(img.alt, "an image") | |
472 |
|
477 | |||
473 | here = os.path.dirname(__file__) |
|
478 | here = os.path.dirname(__file__) | |
474 |
img = display.Image(os.path.join(here, "2x2.png"), alt= |
|
479 | img = display.Image(os.path.join(here, "2x2.png"), alt="an image") | |
475 |
nt.assert_equal(img.alt, |
|
480 | nt.assert_equal(img.alt, "an image") | |
476 | _, md = img._repr_png_() |
|
481 | _, md = img._repr_png_() | |
477 |
nt.assert_equal(md[ |
|
482 | nt.assert_equal(md["alt"], "an image") |
General Comments 0
You need to be logged in to leave comments.
Login now