Skip to content

Commit

Permalink
Remove PSFile class, deprecated in Pillow 9.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jun 29, 2024
1 parent b55d74b commit 204984e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 88 deletions.
40 changes: 0 additions & 40 deletions Tests/test_file_eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,46 +329,6 @@ def test_read_binary_preview() -> None:
pass


def test_readline_psfile(tmp_path: Path) -> None:
# check all the freaking line endings possible from the spec
# test_string = u'something\r\nelse\n\rbaz\rbif\n'
line_endings = ["\r\n", "\n", "\n\r", "\r"]
strings = ["something", "else", "baz", "bif"]

def _test_readline(t: EpsImagePlugin.PSFile, ending: str) -> None:
ending = f"Failure with line ending: {''.join(str(ord(s)) for s in ending)}"
assert t.readline().strip("\r\n") == "something", ending
assert t.readline().strip("\r\n") == "else", ending
assert t.readline().strip("\r\n") == "baz", ending
assert t.readline().strip("\r\n") == "bif", ending

def _test_readline_io_psfile(test_string: str, ending: str) -> None:
f = io.BytesIO(test_string.encode("latin-1"))
with pytest.warns(DeprecationWarning):
t = EpsImagePlugin.PSFile(f)
_test_readline(t, ending)

def _test_readline_file_psfile(test_string: str, ending: str) -> None:
f = str(tmp_path / "temp.txt")
with open(f, "wb") as w:
w.write(test_string.encode("latin-1"))

with open(f, "rb") as r:
with pytest.warns(DeprecationWarning):
t = EpsImagePlugin.PSFile(r)
_test_readline(t, ending)

for ending in line_endings:
s = ending.join(strings)
_test_readline_io_psfile(s, ending)
_test_readline_file_psfile(s, ending)


def test_psfile_deprecation() -> None:
with pytest.warns(DeprecationWarning):
EpsImagePlugin.PSFile(None)


@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
@pytest.mark.parametrize(
"line_ending",
Expand Down
21 changes: 11 additions & 10 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ Deprecated features
Below are features which are considered deprecated. Where appropriate,
a :py:exc:`DeprecationWarning` is issued.

PSFile
~~~~~~

.. deprecated:: 9.5.0

The :py:class:`~PIL.EpsImagePlugin.PSFile` class has been deprecated and will
be removed in Pillow 11 (2024-10-15). This class was only made as a helper to
be used internally, so there is no replacement. If you need this functionality
though, it is a very short class that can easily be recreated in your own code.

PyAccess and Image.USE_CFFI_ACCESS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -137,6 +127,17 @@ Removed features
Deprecated features are only removed in major releases after an appropriate
period of deprecation has passed.

PSFile
~~~~~~

.. deprecated:: 9.5.0
.. versionremoved:: 11.0.0

The :py:class:`~PIL.EpsImagePlugin.PSFile` class was removed in Pillow 11
(2024-10-15). This class was only made as a helper to be used internally,
so there is no replacement. If you need this functionality though, it is a very
short class that can easily be recreated in your own code.

Tk/Tcl 8.4
~~~~~~~~~~

Expand Down
38 changes: 0 additions & 38 deletions src/PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

from . import Image, ImageFile
from ._binary import i32le as i32
from ._deprecate import deprecate

# --------------------------------------------------------------------

Expand Down Expand Up @@ -159,43 +158,6 @@ def Ghostscript(tile, size, fp, scale=1, transparency=False):
return im


class PSFile:
"""
Wrapper for bytesio object that treats either CR or LF as end of line.
This class is no longer used internally, but kept for backwards compatibility.
"""

def __init__(self, fp):
deprecate(
"PSFile",
11,
action="If you need the functionality of this class "
"you will need to implement it yourself.",
)
self.fp = fp
self.char = None

def seek(self, offset, whence=io.SEEK_SET):
self.char = None
self.fp.seek(offset, whence)

def readline(self) -> str:
s = [self.char or b""]
self.char = None

c = self.fp.read(1)
while (c not in b"\r\n") and len(c):
s.append(c)
c = self.fp.read(1)

self.char = self.fp.read(1)
# line endings can be 1 or 2 of \r \n, in either order
if self.char in b"\r\n":
self.char = None

return b"".join(s).decode("latin-1")


def _accept(prefix: bytes) -> bool:
return prefix[:4] == b"%!PS" or (len(prefix) >= 4 and i32(prefix) == 0xC6D3D0C5)

Expand Down

0 comments on commit 204984e

Please sign in to comment.