MCPcopy Index your code
hub / github.com/python-pillow/Pillow / close

Method close

src/PIL/ImageFile.py:610–638  ·  view source on GitHub ↗

(Consumer) Close the stream. :returns: An image object. :exception OSError: If the parser failed to parse the image file either because it cannot be identified or cannot be decoded.

(self)

Source from the content-addressed store, hash-verified

608 self.close()
609
610 def close(self) -> Image.Image:
611 """
612 (Consumer) Close the stream.
613
614 :returns: An image object.
615 :exception OSError: If the parser failed to parse the image file either
616 because it cannot be identified or cannot be
617 decoded.
618 """
619 # finish decoding
620 if self.decoder:
621 # get rid of what's left in the buffers
622 self.feed(b"")
623 self.data = self.decoder = None
624 if not self.finished:
625 msg = "image was incomplete"
626 raise OSError(msg)
627 if not self.image:
628 msg = "cannot parse this image"
629 raise OSError(msg)
630 if self.data:
631 # incremental parsing not possible; reopen the file
632 # not that we have all data
633 with io.BytesIO(self.data) as fp:
634 try:
635 self.image = Image.open(fp)
636 finally:
637 self.image.load()
638 return self.image
639
640
641# --------------------------------------------------------------------

Callers 8

roundtripMethod · 0.95
test_negative_strideMethod · 0.95
__exit__Method · 0.95
__init__Method · 0.45
_close_fpMethod · 0.45
closeMethod · 0.45
verifyMethod · 0.45
loadMethod · 0.45

Calls 3

feedMethod · 0.95
openMethod · 0.45
loadMethod · 0.45

Tested by 2

roundtripMethod · 0.76
test_negative_strideMethod · 0.76