Skip to content

Commit

Permalink
Various smaller places
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Dec 24, 2023
1 parent 0fc5440 commit 3b64cb4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 88 deletions.
14 changes: 1 addition & 13 deletions pypdf/_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def merge(
fileobj: A File Object or an object that supports the standard
read and seek methods similar to a File Object. Could also be a
string representing a path to a PDF file.
None as an argument is deprecated.
outline_item: Optionally, you may specify an outline item
(previously referred to as a 'bookmark') to be applied at the
beginning of the included file by supplying the text of the outline item.
Expand Down Expand Up @@ -380,7 +379,7 @@ def set_page_mode(self, mode: PagemodeType) -> None:
"""
if self.output is None:
raise RuntimeError(ERR_CLOSED_WRITER)
self.output.set_page_mode(mode)
self.output.page_mode = mode

def _trim_dests(
self,
Expand Down Expand Up @@ -589,17 +588,6 @@ def find_outline_item(

return None

def find_bookmark(
self,
outline_item: Dict[str, Any],
root: Optional[OutlineType] = None,
) -> Optional[List[int]]: # deprecated
"""
.. deprecated:: 2.9.0
Use :meth:`find_outline_item` instead.
"""
return self.find_outline_item(outline_item, root)

def add_outline_item(
self,
title: str,
Expand Down
16 changes: 0 additions & 16 deletions pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import math
import re
import warnings
from decimal import Decimal
from typing import (
Any,
Expand Down Expand Up @@ -1872,8 +1871,6 @@ def process_operation(operator: bytes, operands: List[Any]) -> None:
def extract_text(
self,
*args: Any,
Tj_sep: Optional[str] = None,
TJ_sep: Optional[str] = None,
orientations: Union[int, Tuple[int, ...]] = (0, 90, 180, 270),
space_width: float = 200.0,
visitor_operand_before: Optional[Callable[[Any, Any, Any, Any], None]] = None,
Expand All @@ -1899,8 +1896,6 @@ def extract_text(
For example in some PDF files this can be useful to parse tables.
Args:
Tj_sep: Deprecated. Kept for compatibility until pypdf 4.0.0
TJ_sep: Deprecated. Kept for compatibility until pypdf 4.0.0
orientations: list of orientations text_extraction will look for
default = (0, 90, 180, 270)
note: currently only 0(Up),90(turned Left), 180(upside Down),
Expand All @@ -1924,12 +1919,6 @@ def extract_text(
"""
if len(args) >= 1:
if isinstance(args[0], str):
Tj_sep = args[0]
if len(args) >= 2:
if isinstance(args[1], str):
TJ_sep = args[1]
else:
raise TypeError(f"Invalid positional parameter {args[1]}")
if len(args) >= 3:
if isinstance(args[2], (tuple, int)):
orientations = args[2]
Expand All @@ -1949,11 +1938,6 @@ def extract_text(
raise TypeError(f"Invalid positional parameter {args[1]}")
else:
raise TypeError(f"Invalid positional parameter {args[0]}")
if Tj_sep is not None or TJ_sep is not None:
warnings.warn(
"parameters Tj_Sep, TJ_sep depreciated, and will be removed in pypdf 4.0.0.",
DeprecationWarning,
)

if isinstance(orientations, int):
orientations = (orientations,)
Expand Down
34 changes: 0 additions & 34 deletions pypdf/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
StrByteType,
StreamType,
b_,
deprecate_no_replacement,
logger_warning,
parse_iso8824_date,
read_non_whitespace,
Expand Down Expand Up @@ -1755,39 +1754,6 @@ def _pairs(self, array: List[int]) -> Iterable[Tuple[int, int]]:
if (i + 1) >= len(array):
break

def read_next_end_line(
self, stream: StreamType, limit_offset: int = 0
) -> bytes: # deprecated
""".. deprecated:: 2.1.0"""
deprecate_no_replacement("read_next_end_line", removed_in="4.0.0")
line_parts = []
while True:
# Prevent infinite loops in malformed PDFs
if stream.tell() == 0 or stream.tell() == limit_offset:
raise PdfReadError("Could not read malformed PDF file")
x = stream.read(1)
if stream.tell() < 2:
raise PdfReadError("EOL marker not found")
stream.seek(-2, 1)
if x in (b"\n", b"\r"): # \n = LF; \r = CR
crlf = False
while x in (b"\n", b"\r"):
x = stream.read(1)
if x in (b"\n", b"\r"): # account for CR+LF
stream.seek(-1, 1)
crlf = True
if stream.tell() < 2:
raise PdfReadError("EOL marker not found")
stream.seek(-2, 1)
stream.seek(
2 if crlf else 1, 1
) # if using CR+LF, go back 2 bytes, else 1
break
else:
line_parts.append(x)
line_parts.reverse()
return b"".join(line_parts)

def decrypt(self, password: Union[str, bytes]) -> PasswordType:
"""
When using an encrypted / secured PDF file with the PDF Standard
Expand Down
34 changes: 10 additions & 24 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,6 @@ def remove_images(
Args:
to_delete : The type of images to be deleted
(default = all images types)
ignore_byte_string_object: deprecated
"""
if isinstance(to_delete, bool):
to_delete = ImageType.ALL
Expand All @@ -1869,12 +1868,7 @@ def remove_images(
self.remove_objects_from_page(page, i)

def remove_text(self) -> None:
"""
Remove text from this output.
Args:
ignore_byte_string_object: deprecated
"""
"""Remove text from this output."""
for page in self.pages:
self.remove_objects_from_page(page, ObjectDeletionFlag.TEXT)

Expand Down Expand Up @@ -2065,22 +2059,6 @@ def _get_page_mode(self) -> Optional[PagemodeType]:
except KeyError:
return None

def set_page_mode(self, mode: PagemodeType) -> None:
"""
Use :py:attr:`page_mode` instead.
.. deprecated:: 1.28.0
"""
if isinstance(mode, NameObject):
mode_name: NameObject = mode
else:
if mode not in self._valid_modes:
logger_warning(
f"Mode should be one of: {', '.join(self._valid_modes)}", __name__
)
mode_name = NameObject(mode)
self._root_object.update({NameObject("/PageMode"): mode_name})

@property
def page_mode(self) -> Optional[PagemodeType]:
"""
Expand All @@ -2106,7 +2084,15 @@ def page_mode(self) -> Optional[PagemodeType]:

@page_mode.setter
def page_mode(self, mode: PagemodeType) -> None:
self.set_page_mode(mode)
if isinstance(mode, NameObject):
mode_name: NameObject = mode
else:
if mode not in self._valid_modes:
logger_warning(
f"Mode should be one of: {', '.join(self._valid_modes)}", __name__
)
mode_name = NameObject(mode)
self._root_object.update({NameObject("/PageMode"): mode_name})

def add_annotation(
self,
Expand Down
2 changes: 1 addition & 1 deletion pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def write_to_stream(
stream.write(b"\nendstream")

@staticmethod
def initializeFromDictionary(
def initializeFromDictionary( # TODO: mention when to deprecate
data: Dict[str, Any]
) -> Union["EncodedStreamObject", "DecodedStreamObject"]: # deprecated
return StreamObject.initialize_from_dictionary(data)
Expand Down

0 comments on commit 3b64cb4

Please sign in to comment.