Skip to content

Commit

Permalink
work with upper case file extentions
Browse files Browse the repository at this point in the history
  • Loading branch information
RedBeardCode committed Oct 12, 2019
1 parent f553384 commit e850097
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions panel/pane/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ def applies(cls, obj):

@classmethod
def _is_url(cls, obj):
return (isinstance(obj, string_types) and
(obj.startswith('http://') or obj.startswith('https://'))
and obj.endswith('.'+cls.imgtype))
if isinstance(obj, string_types):
lower_string = obj.lower()
return (
lower_string.startswith('http://')
or lower_string.startswith('https://')
) and lower_string.endswith('.'+cls.imgtype)
return False

def _img(self):
if hasattr(self.object, '_repr_{}_'.format(self.imgtype)):
Expand Down
13 changes: 13 additions & 0 deletions panel/tests/pane/test_image.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import absolute_import, division, unicode_literals

import sys
import pytest

from base64 import b64decode, b64encode

from panel.pane import GIF, JPG, PNG, SVG
Expand Down Expand Up @@ -65,6 +68,7 @@ def test_load_from_byteio():
image_data = image_pane._img()
assert b'PNG' in image_data

@pytest.mark.skipif(sys.version_info.major < 2, reason="Doesn't work with python 2")
def test_load_from_stringio():
"""Testing a loading a image from a StringIO"""
memory = StringIO()
Expand All @@ -74,3 +78,12 @@ def test_load_from_stringio():
image_pane = PNG(memory)
image_data = image_pane._img()
assert 'PNG' in image_data

def test_loading_a_image_from_url():
"""Tests the loadiing of a image from a url"""
url = 'https://upload.wikimedia.org/wikipedia/commons/7/71/' \
'1700_CE_world_map.PNG'

image_pane = PNG(url)
image_data = image_pane._img()
assert b'PNG' in image_data

0 comments on commit e850097

Please sign in to comment.