Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: deprecate PdfMerger,AnnotationBuilder and other depreciations cleanup #2813

Merged
merged 21 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
650 changes: 3 additions & 647 deletions pypdf/_merger.py

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
StreamType,
_get_max_pdf_version_header,
deprecate,
deprecate_with_replacement,
deprecation_with_replacement,
logger_warning,
)
from .constants import AnnotationDictionaryAttributes as AA
Expand Down Expand Up @@ -1806,14 +1806,15 @@ def add_outline_item_dict(
outline_item_object = TreeObject()
outline_item_object.update(outline_item)

"""code currently unreachable
pubpub-zz marked this conversation as resolved.
Show resolved Hide resolved
if "/A" in outline_item:
action = DictionaryObject()
a_dict = cast(DictionaryObject, outline_item["/A"])
for k, v in list(a_dict.items()):
action[NameObject(str(k))] = v
action_ref = self._add_object(action)
outline_item_object[NameObject("/A")] = action_ref

"""
return self.add_outline_item_destination(
outline_item_object, parent, before, is_open
)
Expand Down Expand Up @@ -2500,7 +2501,7 @@ def _create_stream(
stream = BytesIO(filecontent)
else:
raise NotImplementedError(
"PdfMerger.merge requires an object that PdfReader can parse. "
"Merging requires an object that PdfReader can parse. "
"Typically, that is a Path or a string representing a Path, "
"a file object, or an object implementing .seek and .read. "
"Passing a PdfReader directly works as well."
Expand Down Expand Up @@ -2853,14 +2854,12 @@ def add_filtered_articles(

def _get_cloned_page(
self,
page: Union[None, int, IndirectObject, PageObject, NullObject],
page: Union[None, IndirectObject, PageObject, NullObject],
pages: Dict[int, PageObject],
reader: PdfReader,
) -> Optional[IndirectObject]:
if isinstance(page, NullObject):
return None
if isinstance(page, int):
_i = reader.pages[page].indirect_reference
elif isinstance(page, DictionaryObject) and page.get("/Type", "") == "/Page":
_i = page.indirect_reference
elif isinstance(page, IndirectObject):
Expand Down Expand Up @@ -3043,13 +3042,12 @@ def find_bookmark(
self,
outline_item: Dict[str, Any],
root: Optional[OutlineType] = None,
) -> Optional[List[int]]: # deprecated
) -> None: # deprecated
"""
.. deprecated:: 2.9.0
Use :meth:`find_outline_item` instead.
"""
deprecate_with_replacement("find_bookmark", "find_outline_item", "5.0.0")
return self.find_outline_item(outline_item, root)
deprecation_with_replacement("find_bookmark", "find_outline_item", "5.0.0")

def reset_translation(
self, reader: Union[None, PdfReader, IndirectObject] = None
Expand Down
2 changes: 1 addition & 1 deletion pypdf/annotations/_markup_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MarkupAnnotation(AnnotationDictionary, ABC):

def __init__(self, *, title_bar: Optional[str] = None):
if title_bar is not None:
self[NameObject("T")] = TextStringObject(title_bar)
self[NameObject("/T")] = TextStringObject(title_bar)


class Text(MarkupAnnotation):
Expand Down
44 changes: 1 addition & 43 deletions pypdf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from enum import IntFlag, auto
from typing import Dict, Tuple

from ._utils import classproperty, deprecate_with_replacement


class Core:
"""Keywords that don't quite belong anywhere else."""
Expand Down Expand Up @@ -162,46 +160,6 @@ class Ressources: # deprecated
.. deprecated:: 5.0.0
"""

@classproperty
def EXT_G_STATE(cls) -> str: # noqa: N805
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/ExtGState" # dictionary, optional

@classproperty
def COLOR_SPACE(cls) -> str: # noqa: N805
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/ColorSpace" # dictionary, optional

@classproperty
def PATTERN(cls) -> str: # noqa: N805
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/Pattern" # dictionary, optional

@classproperty
def SHADING(cls) -> str: # noqa: N805
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/Shading" # dictionary, optional

@classproperty
def XOBJECT(cls) -> str: # noqa: N805
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/XObject" # dictionary, optional

@classproperty
def FONT(cls) -> str: # noqa: N805
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/Font" # dictionary, optional

@classproperty
def PROC_SET(cls) -> str: # noqa: N805
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/ProcSet" # array, optional

@classproperty
def PROPERTIES(cls) -> str: # noqa: N805
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/Properties" # dictionary, optional


class PagesAttributes:
"""§7.7.3.2 of the 1.7 and 2.0 reference."""
Expand All @@ -210,7 +168,7 @@ class PagesAttributes:
PARENT = "/Parent" # dictionary, required; indirect reference to pages object
KIDS = "/Kids" # array, required; List of indirect references
COUNT = "/Count" # integer, required; the number of leaf nodes (page objects)
# that are descendants of this node within the page tree
# that are descendants of this node within the page tree
stefan6419846 marked this conversation as resolved.
Show resolved Hide resolved


class PageAttributes:
Expand Down
13 changes: 0 additions & 13 deletions pypdf/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from ._utils import (
WHITESPACES_AS_BYTES,
deprecate,
deprecate_with_replacement,
deprecation_no_replacement,
logger_warning,
ord_,
Expand Down Expand Up @@ -118,9 +117,6 @@ def decode(
Raises:
PdfReadError:
"""
if "decodeParms" in kwargs: # deprecated
deprecate_with_replacement("decodeParms", "parameters", "4.0.0")
decode_parms = kwargs["decodeParms"]
if isinstance(decode_parms, ArrayObject):
raise DeprecationError("decode_parms as ArrayObject is depreciated")

Expand Down Expand Up @@ -611,9 +607,6 @@ def decode(
**kwargs: Any,
) -> bytes:
# decode_parms is unused here
if "decodeParms" in kwargs: # deprecated
deprecate_with_replacement("decodeParms", "parameters", "4.0.0")
decode_parms = kwargs["decodeParms"]
if isinstance(decode_parms, ArrayObject): # deprecated
deprecation_no_replacement(
"decode_parms being an ArrayObject", removed_in="3.15.5"
Expand Down Expand Up @@ -729,12 +722,6 @@ def decode_stream_data(stream: Any) -> bytes: # utils.StreamObject
return data


def decodeStreamData(stream: Any) -> Union[str, bytes]: # deprecated
"""Deprecated. Use decode_stream_data."""
deprecate_with_replacement("decodeStreamData", "decode_stream_data", "4.0.0")
return decode_stream_data(stream)


def _xobj_to_image(x_object_obj: Dict[str, Any]) -> Tuple[Optional[str], bytes, Any]:
"""
Users need to have the pillow package installed.
Expand Down
Loading
Loading