Skip to content

Commit

Permalink
Fix to EmbeddedImage to prevent import error on non-Jupyter instances
Browse files Browse the repository at this point in the history
  • Loading branch information
JR Schmidt committed Feb 12, 2024
1 parent 22d9fcd commit ce9ce59
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions webmo/webmo_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,45 +706,45 @@ async def _process_callback_response(self):

return EmbeddedImage(data=decoded_image_data)

if has_ipython:
class EmbeddedImage(Image):
"""The EmbeddedImage class is a IPython-displayable image object with additional functionality.
class EmbeddedImage(Image):
"""The EmbeddedImage class is a IPython-displayable image object with additional functionality.
The EmbeddedImage class is a Jupyter-renderable image object, derived from IPython.display.image.
However, the EmbeddedImage also adds additional utility conversion methods.
"""
def __init__(self, data):
super().__init__(data)

The EmbeddedImage class is a Jupyter-renderable image object, derived from IPython.display.image.
However, the EmbeddedImage also adds additional utility conversion methods.
"""
def __init__(self, data):
super().__init__(data)
def save(self, filename):
"""Saves the EmbeddedImage to disk as a PNG-formatted image.
def save(self, filename):
"""Saves the EmbeddedImage to disk as a PNG-formatted image.
This call saves the EmbeddedImage object to disk as PNG-formatted image.
This call saves the EmbeddedImage object to disk as PNG-formatted image.
Arguments:
filename(str): The path to the target PNG file. A "png" extension is added, if not provided.
Arguments:
filename(str): The path to the target PNG file. A "png" extension is added, if not provided.
Returns:
None
"""
if not filename.endswith(".png"):
filename += ".png"
with open(filename, 'wb') as fp:
fp.write(self.data)

Returns:
None
"""
if not filename.endswith(".png"):
filename += ".png"
with open(filename, 'wb') as fp:
fp.write(self.data)
def to_pil_image(self):
"""Returns an equivalent Pillow (PIL) Image object.
def to_pil_image(self):
"""Returns an equivalent Pillow (PIL) Image object.
This call converts and returns and equivalent Pillow (PIL) Image representation of the
current EmbeddedImage object, for further manipulation.
This call converts and returns and equivalent Pillow (PIL) Image representation of the
current EmbeddedImage object, for further manipulation.
Arguments:
None
Arguments:
None
Returns:
A Pillow PIL.Image.Image object.
"""
from PIL import Image
from io import BytesIO
Returns:
A Pillow PIL.Image.Image object.
"""
from PIL import Image
from io import BytesIO

return Image.open(BytesIO(self.data))
return Image.open(BytesIO(self.data))

0 comments on commit ce9ce59

Please sign in to comment.