mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 10:16:17 +03:00
Added type hints
This commit is contained in:
parent
c9a56e6b0b
commit
18b87c8515
|
@ -37,7 +37,7 @@ class BufrStubImageFile(ImageFile.StubImageFile):
|
||||||
format = "BUFR"
|
format = "BUFR"
|
||||||
format_description = "BUFR"
|
format_description = "BUFR"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
offset = self.fp.tell()
|
offset = self.fp.tell()
|
||||||
|
|
||||||
if not _accept(self.fp.read(4)):
|
if not _accept(self.fp.read(4)):
|
||||||
|
|
|
@ -37,7 +37,7 @@ class CurImageFile(BmpImagePlugin.BmpImageFile):
|
||||||
format = "CUR"
|
format = "CUR"
|
||||||
format_description = "Windows Cursor"
|
format_description = "Windows Cursor"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
offset = self.fp.tell()
|
offset = self.fp.tell()
|
||||||
|
|
||||||
# check magic
|
# check magic
|
||||||
|
|
|
@ -237,7 +237,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
return ImageFile.ImageFile.load(self)
|
return ImageFile.ImageFile.load(self)
|
||||||
|
|
||||||
def close(self):
|
def close(self) -> None:
|
||||||
self.ole.close()
|
self.ole.close()
|
||||||
super().close()
|
super().close()
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ class FtexImageFile(ImageFile.ImageFile):
|
||||||
format = "FTEX"
|
format = "FTEX"
|
||||||
format_description = "Texture File Format (IW2:EOC)"
|
format_description = "Texture File Format (IW2:EOC)"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
if not _accept(self.fp.read(4)):
|
if not _accept(self.fp.read(4)):
|
||||||
msg = "not an FTEX file"
|
msg = "not an FTEX file"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
|
|
|
@ -41,7 +41,7 @@ class GbrImageFile(ImageFile.ImageFile):
|
||||||
format = "GBR"
|
format = "GBR"
|
||||||
format_description = "GIMP brush file"
|
format_description = "GIMP brush file"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
header_size = i32(self.fp.read(4))
|
header_size = i32(self.fp.read(4))
|
||||||
if header_size < 20:
|
if header_size < 20:
|
||||||
msg = "not a GIMP brush"
|
msg = "not a GIMP brush"
|
||||||
|
|
|
@ -37,7 +37,7 @@ class GribStubImageFile(ImageFile.StubImageFile):
|
||||||
format = "GRIB"
|
format = "GRIB"
|
||||||
format_description = "GRIB"
|
format_description = "GRIB"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
offset = self.fp.tell()
|
offset = self.fp.tell()
|
||||||
|
|
||||||
if not _accept(self.fp.read(8)):
|
if not _accept(self.fp.read(8)):
|
||||||
|
|
|
@ -119,7 +119,7 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
format_description = "IFUNC Image Memory"
|
format_description = "IFUNC Image Memory"
|
||||||
_close_exclusive_fp_after_loading = False
|
_close_exclusive_fp_after_loading = False
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
# Quick rejection: if there's not an LF among the first
|
# Quick rejection: if there's not an LF among the first
|
||||||
# 100 bytes, this is (probably) not a text header.
|
# 100 bytes, this is (probably) not a text header.
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ class PhotoImage:
|
||||||
if image:
|
if image:
|
||||||
self.paste(image)
|
self.paste(image)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self) -> None:
|
||||||
name = self.__photo.name
|
name = self.__photo.name
|
||||||
self.__photo.name = None
|
self.__photo.name = None
|
||||||
try:
|
try:
|
||||||
|
@ -219,7 +219,7 @@ class BitmapImage:
|
||||||
kw["data"] = image.tobitmap()
|
kw["data"] = image.tobitmap()
|
||||||
self.__photo = tkinter.BitmapImage(**kw)
|
self.__photo = tkinter.BitmapImage(**kw)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self) -> None:
|
||||||
name = self.__photo.name
|
name = self.__photo.name
|
||||||
self.__photo.name = None
|
self.__photo.name = None
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -215,7 +215,7 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
||||||
format = "JPEG2000"
|
format = "JPEG2000"
|
||||||
format_description = "JPEG 2000 (ISO 15444)"
|
format_description = "JPEG 2000 (ISO 15444)"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
sig = self.fp.read(4)
|
sig = self.fp.read(4)
|
||||||
if sig == b"\xff\x4f\xff\x51":
|
if sig == b"\xff\x4f\xff\x51":
|
||||||
self.codec = "j2k"
|
self.codec = "j2k"
|
||||||
|
@ -267,7 +267,7 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
def _parse_comment(self):
|
def _parse_comment(self) -> None:
|
||||||
hdr = self.fp.read(2)
|
hdr = self.fp.read(2)
|
||||||
length = _binary.i16be(hdr)
|
length = _binary.i16be(hdr)
|
||||||
self.fp.seek(length - 2, os.SEEK_CUR)
|
self.fp.seek(length - 2, os.SEEK_CUR)
|
||||||
|
|
|
@ -462,7 +462,7 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
box = (0, 0, original_size[0] / scale, original_size[1] / scale)
|
box = (0, 0, original_size[0] / scale, original_size[1] / scale)
|
||||||
return self.mode, box
|
return self.mode, box
|
||||||
|
|
||||||
def load_djpeg(self):
|
def load_djpeg(self) -> None:
|
||||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
||||||
|
|
||||||
f, path = tempfile.mkstemp()
|
f, path = tempfile.mkstemp()
|
||||||
|
|
|
@ -100,7 +100,7 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
|
||||||
format_description = "MPO (CIPA DC-007)"
|
format_description = "MPO (CIPA DC-007)"
|
||||||
_close_exclusive_fp_after_loading = False
|
_close_exclusive_fp_after_loading = False
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
self.fp.seek(0) # prep the fp in order to pass the JPEG test
|
self.fp.seek(0) # prep the fp in order to pass the JPEG test
|
||||||
JpegImagePlugin.JpegImageFile._open(self)
|
JpegImagePlugin.JpegImageFile._open(self)
|
||||||
self._after_jpeg_open()
|
self._after_jpeg_open()
|
||||||
|
|
|
@ -54,7 +54,7 @@ class PSDraw:
|
||||||
self.fp.write(b"%%EndProlog\n")
|
self.fp.write(b"%%EndProlog\n")
|
||||||
self.isofont = {}
|
self.isofont = {}
|
||||||
|
|
||||||
def end_document(self):
|
def end_document(self) -> None:
|
||||||
"""Ends printing. (Write PostScript DSC footer.)"""
|
"""Ends printing. (Write PostScript DSC footer.)"""
|
||||||
self.fp.write(b"%%EndDocument\nrestore showpage\n%%End\n")
|
self.fp.write(b"%%EndDocument\nrestore showpage\n%%End\n")
|
||||||
if hasattr(self.fp, "flush"):
|
if hasattr(self.fp, "flush"):
|
||||||
|
|
|
@ -409,28 +409,28 @@ class PdfParser:
|
||||||
self.close()
|
self.close()
|
||||||
return False # do not suppress exceptions
|
return False # do not suppress exceptions
|
||||||
|
|
||||||
def start_writing(self):
|
def start_writing(self) -> None:
|
||||||
self.close_buf()
|
self.close_buf()
|
||||||
self.seek_end()
|
self.seek_end()
|
||||||
|
|
||||||
def close_buf(self):
|
def close_buf(self) -> None:
|
||||||
try:
|
try:
|
||||||
self.buf.close()
|
self.buf.close()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
self.buf = None
|
self.buf = None
|
||||||
|
|
||||||
def close(self):
|
def close(self) -> None:
|
||||||
if self.should_close_buf:
|
if self.should_close_buf:
|
||||||
self.close_buf()
|
self.close_buf()
|
||||||
if self.f is not None and self.should_close_file:
|
if self.f is not None and self.should_close_file:
|
||||||
self.f.close()
|
self.f.close()
|
||||||
self.f = None
|
self.f = None
|
||||||
|
|
||||||
def seek_end(self):
|
def seek_end(self) -> None:
|
||||||
self.f.seek(0, os.SEEK_END)
|
self.f.seek(0, os.SEEK_END)
|
||||||
|
|
||||||
def write_header(self):
|
def write_header(self) -> None:
|
||||||
self.f.write(b"%PDF-1.4\n")
|
self.f.write(b"%PDF-1.4\n")
|
||||||
|
|
||||||
def write_comment(self, s):
|
def write_comment(self, s):
|
||||||
|
@ -450,7 +450,7 @@ class PdfParser:
|
||||||
)
|
)
|
||||||
return self.root_ref
|
return self.root_ref
|
||||||
|
|
||||||
def rewrite_pages(self):
|
def rewrite_pages(self) -> None:
|
||||||
pages_tree_nodes_to_delete = []
|
pages_tree_nodes_to_delete = []
|
||||||
for i, page_ref in enumerate(self.orig_pages):
|
for i, page_ref in enumerate(self.orig_pages):
|
||||||
page_info = self.cached_objects[page_ref]
|
page_info = self.cached_objects[page_ref]
|
||||||
|
@ -529,7 +529,7 @@ class PdfParser:
|
||||||
f.write(b"endobj\n")
|
f.write(b"endobj\n")
|
||||||
return ref
|
return ref
|
||||||
|
|
||||||
def del_root(self):
|
def del_root(self) -> None:
|
||||||
if self.root_ref is None:
|
if self.root_ref is None:
|
||||||
return
|
return
|
||||||
del self.xref_table[self.root_ref.object_id]
|
del self.xref_table[self.root_ref.object_id]
|
||||||
|
@ -547,7 +547,7 @@ class PdfParser:
|
||||||
except ValueError: # cannot mmap an empty file
|
except ValueError: # cannot mmap an empty file
|
||||||
return b""
|
return b""
|
||||||
|
|
||||||
def read_pdf_info(self):
|
def read_pdf_info(self) -> None:
|
||||||
self.file_size_total = len(self.buf)
|
self.file_size_total = len(self.buf)
|
||||||
self.file_size_this = self.file_size_total - self.start_offset
|
self.file_size_this = self.file_size_total - self.start_offset
|
||||||
self.read_trailer()
|
self.read_trailer()
|
||||||
|
|
|
@ -179,7 +179,7 @@ class ChunkStream:
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def close(self):
|
def close(self) -> None:
|
||||||
self.queue = self.fp = None
|
self.queue = self.fp = None
|
||||||
|
|
||||||
def push(self, cid, pos, length):
|
def push(self, cid, pos, length):
|
||||||
|
@ -370,14 +370,14 @@ class PngStream(ChunkStream):
|
||||||
)
|
)
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
def save_rewind(self):
|
def save_rewind(self) -> None:
|
||||||
self.rewind_state = {
|
self.rewind_state = {
|
||||||
"info": self.im_info.copy(),
|
"info": self.im_info.copy(),
|
||||||
"tile": self.im_tile,
|
"tile": self.im_tile,
|
||||||
"seq_num": self._seq_num,
|
"seq_num": self._seq_num,
|
||||||
}
|
}
|
||||||
|
|
||||||
def rewind(self):
|
def rewind(self) -> None:
|
||||||
self.im_info = self.rewind_state["info"].copy()
|
self.im_info = self.rewind_state["info"].copy()
|
||||||
self.im_tile = self.rewind_state["tile"]
|
self.im_tile = self.rewind_state["tile"]
|
||||||
self._seq_num = self.rewind_state["seq_num"]
|
self._seq_num = self.rewind_state["seq_num"]
|
||||||
|
|
|
@ -70,7 +70,7 @@ class PyAccess:
|
||||||
# logger.debug("%s", vals)
|
# logger.debug("%s", vals)
|
||||||
self._post_init()
|
self._post_init()
|
||||||
|
|
||||||
def _post_init(self):
|
def _post_init(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __setitem__(self, xy, color):
|
def __setitem__(self, xy, color):
|
||||||
|
|
|
@ -21,7 +21,7 @@ class QoiImageFile(ImageFile.ImageFile):
|
||||||
format = "QOI"
|
format = "QOI"
|
||||||
format_description = "Quite OK Image"
|
format_description = "Quite OK Image"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
if not _accept(self.fp.read(4)):
|
if not _accept(self.fp.read(4)):
|
||||||
msg = "not a QOI file"
|
msg = "not a QOI file"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
|
|
|
@ -43,7 +43,7 @@ class WebPImageFile(ImageFile.ImageFile):
|
||||||
__loaded = 0
|
__loaded = 0
|
||||||
__logical_frame = 0
|
__logical_frame = 0
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
if not _webp.HAVE_WEBPANIM:
|
if not _webp.HAVE_WEBPANIM:
|
||||||
# Legacy mode
|
# Legacy mode
|
||||||
data, width, height, self._mode, icc_profile, exif = _webp.WebPDecode(
|
data, width, height, self._mode, icc_profile, exif = _webp.WebPDecode(
|
||||||
|
|
|
@ -79,7 +79,7 @@ class WmfStubImageFile(ImageFile.StubImageFile):
|
||||||
format = "WMF"
|
format = "WMF"
|
||||||
format_description = "Windows Metafile"
|
format_description = "Windows Metafile"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
self._inch = None
|
self._inch = None
|
||||||
|
|
||||||
# check placable header
|
# check placable header
|
||||||
|
|
|
@ -36,7 +36,7 @@ class XpmImageFile(ImageFile.ImageFile):
|
||||||
format = "XPM"
|
format = "XPM"
|
||||||
format_description = "X11 Pixel Map"
|
format_description = "X11 Pixel Map"
|
||||||
|
|
||||||
def _open(self):
|
def _open(self) -> None:
|
||||||
if not _accept(self.fp.read(9)):
|
if not _accept(self.fp.read(9)):
|
||||||
msg = "not an XPM file"
|
msg = "not an XPM file"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user