mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-22 15:24:37 +03:00
Moved file pointer handling into ImageFile close
This commit is contained in:
parent
cf7dd2f0e9
commit
4ff18e03b8
|
@ -619,8 +619,6 @@ class Image:
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
"""
|
"""
|
||||||
Closes the file pointer, if possible.
|
|
||||||
|
|
||||||
This operation will destroy the image core and release its memory.
|
This operation will destroy the image core and release its memory.
|
||||||
The image data will be unusable afterward.
|
The image data will be unusable afterward.
|
||||||
|
|
||||||
|
@ -629,13 +627,6 @@ class Image:
|
||||||
:py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for
|
:py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for
|
||||||
more information.
|
more information.
|
||||||
"""
|
"""
|
||||||
if hasattr(self, "fp"):
|
|
||||||
try:
|
|
||||||
self._close_fp()
|
|
||||||
self.fp = None
|
|
||||||
except Exception as msg:
|
|
||||||
logger.debug("Error closing: %s", msg)
|
|
||||||
|
|
||||||
if getattr(self, "map", None):
|
if getattr(self, "map", None):
|
||||||
self.map: mmap.mmap | None = None
|
self.map: mmap.mmap | None = None
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ from __future__ import annotations
|
||||||
import abc
|
import abc
|
||||||
import io
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
@ -43,6 +44,8 @@ from ._util import is_path
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ._typing import StrOrBytesPath
|
from ._typing import StrOrBytesPath
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
MAXBLOCK = 65536
|
MAXBLOCK = 65536
|
||||||
|
|
||||||
SAFEBLOCK = 1024 * 1024
|
SAFEBLOCK = 1024 * 1024
|
||||||
|
@ -163,6 +166,26 @@ class ImageFile(Image.Image):
|
||||||
def _open(self) -> None:
|
def _open(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def close(self) -> None:
|
||||||
|
"""
|
||||||
|
Closes the file pointer, if possible.
|
||||||
|
|
||||||
|
This operation will destroy the image core and release its memory.
|
||||||
|
The image data will be unusable afterward.
|
||||||
|
|
||||||
|
This function is required to close images that have multiple frames or
|
||||||
|
have not had their file read and closed by the
|
||||||
|
:py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for
|
||||||
|
more information.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self._close_fp()
|
||||||
|
self.fp = None
|
||||||
|
except Exception as msg:
|
||||||
|
logger.debug("Error closing: %s", msg)
|
||||||
|
|
||||||
|
super().close()
|
||||||
|
|
||||||
def get_child_images(self) -> list[ImageFile]:
|
def get_child_images(self) -> list[ImageFile]:
|
||||||
child_images = []
|
child_images = []
|
||||||
exif = self.getexif()
|
exif = self.getexif()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user