Skip to content

Commit

Permalink
Add seek to pane.image
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Oct 27, 2020
1 parent b5cf692 commit af03e00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions panel/pane/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def _img(self):
with open(self.object, 'rb') as f:
return f.read()
if hasattr(self.object, 'read'):
if hasattr(self.object, 'seek'):
self.object.seek(0)
return self.object.read()
if isurl(self.object, None):
import requests
Expand Down
6 changes: 3 additions & 3 deletions panel/tests/pane/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_load_from_byteio():
path = os.path.dirname(__file__)
with open(os.path.join(path, '../test_data/logo.png'), 'rb') as image_file:
memory.write(image_file.read())
memory.seek(0)

image_pane = PNG(memory)
image_data = image_pane._img()
assert b'PNG' in image_data
Expand All @@ -79,11 +79,11 @@ def test_load_from_byteio():
def test_load_from_stringio():
"""Testing a loading a image from a StringIO"""
memory = StringIO()

path = os.path.dirname(__file__)
with open(os.path.join(path, '../test_data/logo.png'), 'rb') as image_file:
memory.write(str(image_file.read()))
memory.seek(0)

image_pane = PNG(memory)
image_data = image_pane._img()
assert 'PNG' in image_data
Expand Down

0 comments on commit af03e00

Please sign in to comment.