mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
move repeated code to private helper function
This commit is contained in:
parent
35a70e4b97
commit
cd76b48533
|
@ -2080,38 +2080,34 @@ class AppendingTiffWriter:
|
||||||
(value,) = struct.unpack(self.longFmt, self.f.read(4))
|
(value,) = struct.unpack(self.longFmt, self.f.read(4))
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _verify_bytes_written(bytes_written: int | None, expected: int) -> None:
|
||||||
|
if bytes_written is not None and bytes_written != expected:
|
||||||
|
msg = f"wrote only {bytes_written} bytes but wanted {expected}"
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
def rewriteLastShortToLong(self, value: int) -> None:
|
def rewriteLastShortToLong(self, value: int) -> None:
|
||||||
self.f.seek(-2, os.SEEK_CUR)
|
self.f.seek(-2, os.SEEK_CUR)
|
||||||
bytes_written = self.f.write(struct.pack(self.longFmt, value))
|
bytes_written = self.f.write(struct.pack(self.longFmt, value))
|
||||||
if bytes_written is not None and bytes_written != 4:
|
self._verify_bytes_written(bytes_written, 4)
|
||||||
msg = f"wrote only {bytes_written} bytes but wanted 4"
|
|
||||||
raise RuntimeError(msg)
|
|
||||||
|
|
||||||
def rewriteLastShort(self, value: int) -> None:
|
def rewriteLastShort(self, value: int) -> None:
|
||||||
self.f.seek(-2, os.SEEK_CUR)
|
self.f.seek(-2, os.SEEK_CUR)
|
||||||
bytes_written = self.f.write(struct.pack(self.shortFmt, value))
|
bytes_written = self.f.write(struct.pack(self.shortFmt, value))
|
||||||
if bytes_written is not None and bytes_written != 2:
|
self._verify_bytes_written(bytes_written, 2)
|
||||||
msg = f"wrote only {bytes_written} bytes but wanted 2"
|
|
||||||
raise RuntimeError(msg)
|
|
||||||
|
|
||||||
def rewriteLastLong(self, value: int) -> None:
|
def rewriteLastLong(self, value: int) -> None:
|
||||||
self.f.seek(-4, os.SEEK_CUR)
|
self.f.seek(-4, os.SEEK_CUR)
|
||||||
bytes_written = self.f.write(struct.pack(self.longFmt, value))
|
bytes_written = self.f.write(struct.pack(self.longFmt, value))
|
||||||
if bytes_written is not None and bytes_written != 4:
|
self._verify_bytes_written(bytes_written, 4)
|
||||||
msg = f"wrote only {bytes_written} bytes but wanted 4"
|
|
||||||
raise RuntimeError(msg)
|
|
||||||
|
|
||||||
def writeShort(self, value: int) -> None:
|
def writeShort(self, value: int) -> None:
|
||||||
bytes_written = self.f.write(struct.pack(self.shortFmt, value))
|
bytes_written = self.f.write(struct.pack(self.shortFmt, value))
|
||||||
if bytes_written is not None and bytes_written != 2:
|
self._verify_bytes_written(bytes_written, 2)
|
||||||
msg = f"wrote only {bytes_written} bytes but wanted 2"
|
|
||||||
raise RuntimeError(msg)
|
|
||||||
|
|
||||||
def writeLong(self, value: int) -> None:
|
def writeLong(self, value: int) -> None:
|
||||||
bytes_written = self.f.write(struct.pack(self.longFmt, value))
|
bytes_written = self.f.write(struct.pack(self.longFmt, value))
|
||||||
if bytes_written is not None and bytes_written != 4:
|
self._verify_bytes_written(bytes_written, 4)
|
||||||
msg = f"wrote only {bytes_written} bytes but wanted 4"
|
|
||||||
raise RuntimeError(msg)
|
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
self.finalize()
|
self.finalize()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user