def test_html(): a = HTML.a(href='http://mostlysafe" <tag', c="Bad <script> tag") assert u'<a href="http://mostlysafe" <tag">Bad <script> tag</a>' == a img = HTML.img(src="http://some/image.jpg") assert u'<img src="http://some/image.jpg" />' == img br = HTML.br() assert u"<br />" == br
def display_image(self, page, post): img = HTML.img( alt="main image", class_="shm-main-image", id="main_image", src=post.image_url, data_width=post.width, data_height=post.height, ) context.page.add_block(Block("Image", img, "main", 10))
def test_html(): a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag") eq_(a, '<a href="http://mostlysafe" <tag">Bad <script> tag</a>') img = HTML.img(src='http://some/image.jpg') eq_(img, '<img src="http://some/image.jpg" />') br = HTML.br() eq_('<br />', br)
def test_html(): a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag") eq_(a, u'<a href="http://mostlysafe" <tag">Bad <script> tag</a>') img = HTML.img(src='http://some/image.jpg') eq_(img, u'<img src="http://some/image.jpg" />') br = HTML.br() eq_(u'<br />', br)
def image(url, alt, width=None, height=None, **attrs): """Return an image tag for the specified ``source``. ``url`` The URL of the image. (This must be the exact URL desired. A previous version of this helper added magic prefixes; this is no longer the case.) ``alt`` The img's alt tag. Non-graphical browsers and screen readers will output this instead of the image. If the image is pure decoration and uninteresting to non-graphical users, pass "". To omit the alt tag completely, pass None. ``width`` The width of the image, default is not included ``height`` The height of the image, default is not included Examples:: >>> image('/images/rss.png', 'rss syndication') literal(u'<img alt="rss syndication" src="/images/rss.png" />') >>> image('/images/xml.png', "") literal(u'<img alt="" src="/images/xml.png" />') >>> image("/images/icon.png", height=16, width=10, alt="Edit Entry") literal(u'<img alt="Edit Entry" height="16" src="/images/icon.png" width="10" />') >>> image("/icons/icon.gif", alt="Icon", width=16, height=16) literal(u'<img alt="Icon" height="16" src="/icons/icon.gif" width="16" />') >>> image("/icons/icon.gif", None, width=16) literal(u'<img alt="" src="/icons/icon.gif" width="16" />') """ if not alt: alt = "" if width is not None: attrs['width'] = width if height is not None: attrs['height'] = height return HTML.img(src=url, alt=alt, **attrs)
def image(url, alt, width=None, height=None, **attrs): """Return an image tag for the specified ``source``. ``url`` The URL of the image. (This must be the exact URL desired. A previous version of this helper added magic prefixes; this is no longer the case.) ``alt`` The img's alt tag. Non-graphical browsers and screen readers will output this instead of the image. If the image is pure decoration and uninteresting to non-graphical users, pass "". To omit the alt tag completely, pass None. ``width`` The width of the image, default is not included ``height`` The height of the image, default is not included Examples:: >>> image('/images/rss.png', 'rss syndication') literal(u'<img alt="rss syndication" src="/images/rss.png" />') >>> image('/images/xml.png', "") literal(u'<img alt="" src="/images/xml.png" />') >>> image("/images/icon.png", height=16, width=10, alt="Edit Entry") literal(u'<img alt="Edit Entry" height="16" src="/images/icon.png" width="10" />') >>> image("/icons/icon.gif", alt="Icon", width=16, height=16) literal(u'<img alt="Icon" height="16" src="/icons/icon.gif" width="16" />') >>> image("/icons/icon.gif", None, width=16) literal(u'<img alt="" src="/icons/icon.gif" width="16" />') """ if not alt: alt = "" if width is not None: attrs['width'] = width if height is not None: attrs['height'] = height return HTML.img(src=url, alt=alt, **attrs)
def image(url, alt, width=None, height=None, path=None, use_pil=False, **attrs): """Return an image tag for the specified ``source``. ``url`` The URL of the image. (This must be the exact URL desired. A previous version of this helper added magic prefixes; this is no longer the case.) ``alt`` The img's alt tag. Non-graphical browsers and screen readers will output this instead of the image. If the image is pure decoration and uninteresting to non-graphical users, pass "". To omit the alt tag completely, pass None. ``width`` The width of the image, default is not included. ``height`` The height of the image, default is not included. ``path`` Calculate the width and height based on the image file at ``path`` if possible. May not be specified if ``width`` or ``height`` is specified. The results are also written to the debug log for troubleshooting. ``use_pil`` If true, calcuate the image dimensions using the Python Imaging Library, which must be installed. Otherwise use a pure Python algorithm which understands fewer image formats and may be less accurate. This flag controls whether ``webhelpers.media.get_dimensions_pil`` or ``webhelpers.media.get_dimensions`` is called. It has no effect if ``path`` is not specified. Examples:: >>> image('/images/rss.png', 'rss syndication') literal(%(u)s'<img alt="rss syndication" src="/images/rss.png" />') >>> image('/images/xml.png', "") literal(%(u)s'<img alt="" src="/images/xml.png" />') >>> image("/images/icon.png", height=16, width=10, alt="Edit Entry") literal(%(u)s'<img alt="Edit Entry" height="16" src="/images/icon.png" width="10" />') >>> image("/icons/icon.gif", alt="Icon", width=16, height=16) literal(%(u)s'<img alt="Icon" height="16" src="/icons/icon.gif" width="16" />') >>> image("/icons/icon.gif", None, width=16) literal(%(u)s'<img alt="" src="/icons/icon.gif" width="16" />') """ if not alt: alt = "" if width is not None or height is not None: attrs['width'] = width attrs['height'] = height if path: raise TypeError( "can't specify path if width and height are specified") elif path: if use_pil: result = media.get_dimensions_pil(path) msg = "using PIL" else: result = media.get_dimensions(path) msg = "not using PIL" abspath = os.path.abspath(path) log.debug("image size is %s for '%s' (%s)", result, abspath, msg) attrs['width'] = result[0] attrs['height'] = result[1] return HTML.img(src=url, alt=alt, **attrs)
def image(url, alt, width=None, height=None, path=None, use_pil=False, **attrs): """Return an image tag for the specified ``source``. ``url`` The URL of the image. (This must be the exact URL desired. A previous version of this helper added magic prefixes; this is no longer the case.) ``alt`` The img's alt tag. Non-graphical browsers and screen readers will output this instead of the image. If the image is pure decoration and uninteresting to non-graphical users, pass "". To omit the alt tag completely, pass None. ``width`` The width of the image, default is not included. ``height`` The height of the image, default is not included. ``path`` Calculate the width and height based on the image file at ``path`` if possible. May not be specified if ``width`` or ``height`` is specified. The results are also written to the debug log for troubleshooting. ``use_pil`` If true, calcuate the image dimensions using the Python Imaging Library, which must be installed. Otherwise use a pure Python algorithm which understands fewer image formats and may be less accurate. This flag controls whether ``webhelpers.media.get_dimensions_pil`` or ``webhelpers.media.get_dimensions`` is called. It has no effect if ``path`` is not specified. Examples:: >>> image('/images/rss.png', 'rss syndication') literal(u'<img alt="rss syndication" src="/images/rss.png" />') >>> image('/images/xml.png', "") literal(u'<img alt="" src="/images/xml.png" />') >>> image("/images/icon.png", height=16, width=10, alt="Edit Entry") literal(u'<img alt="Edit Entry" height="16" src="/images/icon.png" width="10" />') >>> image("/icons/icon.gif", alt="Icon", width=16, height=16) literal(u'<img alt="Icon" height="16" src="/icons/icon.gif" width="16" />') >>> image("/icons/icon.gif", None, width=16) literal(u'<img alt="" src="/icons/icon.gif" width="16" />') """ if not alt: alt = "" if width is not None or height is not None: attrs['width'] = width attrs['height'] = height if path: raise TypeError( "can't specify path if width and height are specified") elif path: if use_pil: result = media.get_dimensions_pil(path) msg = "using PIL" else: result = media.get_dimensions(path) msg = "not using PIL" abspath = os.path.abspath(path) log.debug("image size is %s for '%s' (%s)", result, abspath, msg) attrs['width'] = result[0] attrs['height'] = result[1] return HTML.img(src=url, alt=alt, **attrs)
def get_avatar_html(self, size=80): av = self.get_avatar_url(size) if av: return HTML.img(src=av, width=size, height=size) else: return ""