From af03e001a23d1e1cea065f85abfb4e0176d0d688 Mon Sep 17 00:00:00 2001 From: Simon Hoxbro Date: Tue, 27 Oct 2020 20:26:31 +0100 Subject: [PATCH] Add seek to pane.image --- panel/pane/image.py | 2 ++ panel/tests/pane/test_image.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/panel/pane/image.py b/panel/pane/image.py index d151239d35..4d2317d9f9 100644 --- a/panel/pane/image.py +++ b/panel/pane/image.py @@ -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 diff --git a/panel/tests/pane/test_image.py b/panel/tests/pane/test_image.py index 52ccb23283..c67a3785cd 100644 --- a/panel/tests/pane/test_image.py +++ b/panel/tests/pane/test_image.py @@ -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 @@ -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