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: Ressources → Resources (and internal name childs) #2550

Merged
merged 5 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
from .constants import AnnotationDictionaryAttributes as ADA
from .constants import ImageAttributes as IA
from .constants import PageAttributes as PG
from .constants import Ressources as RES
from .constants import Resources as RES
from .errors import PageSizeNotDefinedError, PdfReadError
from .filters import _xobj_to_image
from .generic import (
Expand Down
13 changes: 9 additions & 4 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2675,10 +2675,15 @@ def _get_filtered_outline(
v = NullObject()
o[NameObject("/Page")] = v
if "/First" in node:
o.childs = self._get_filtered_outline(node["/First"], pages, reader)
o._filtered_children = self._get_filtered_outline(
node["/First"], pages, reader
)
else:
o.childs = []
if not isinstance(o["/Page"], NullObject) or len(o.childs) > 0:
o._filtered_children = []
if (
not isinstance(o["/Page"], NullObject)
or len(o._filtered_children) > 0
):
new_outline.append(o)
node = node.get("/Next", None)
return new_outline
Expand Down Expand Up @@ -2716,7 +2721,7 @@ def _insert_filtered_outline(
else:
np = self._clone_outline(dest)
cast(TreeObject, parent.get_object()).insert_child(np, before, self)
self._insert_filtered_outline(dest.childs, np, None)
self._insert_filtered_outline(dest._filtered_children, np, None)

def close(self) -> None:
"""To match the functions from Merger."""
Expand Down
67 changes: 64 additions & 3 deletions pypdf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from enum import IntFlag, auto
from typing import Dict, Tuple

from ._utils import deprecate_with_replacement


class Core:
"""Keywords that don't quite belong anywhere else."""
Expand Down Expand Up @@ -127,8 +129,11 @@ def all(cls) -> "UserAccessPermissions":
return cls((2**32 - 1) - cls.R1 - cls.R2)


class Ressources:
"""TABLE 3.30 Entries in a resource dictionary."""
class Resources:
"""
TABLE 3.30 Entries in a resource dictionary.
used to be Ressources
"""

EXT_G_STATE = "/ExtGState" # dictionary, optional
COLOR_SPACE = "/ColorSpace" # dictionary, optional
Expand All @@ -140,6 +145,62 @@ class Ressources:
PROPERTIES = "/Properties" # dictionary, optional


class Ressources: # deprecated
"""
Use :class: `Resources` instead.

.. deprecated:: 5.0.0
"""

@classmethod # type: ignore
@property
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works for python 3.9 and 3.10...

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

@classmethod # type: ignore
@property
def COLOR_SPACE(cls) -> str:
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/ColorSpace" # dictionary, optional

@classmethod # type: ignore
@property
def PATTERN(cls) -> str:
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/Pattern" # dictionary, optional

@classmethod # type: ignore
@property
def SHADING(cls) -> str:
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/Shading" # dictionary, optional

@classmethod # type: ignore
@property
def XOBJECT(cls) -> str:
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/XObject" # dictionary, optional

@classmethod # type: ignore
@property
def FONT(cls) -> str:
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/Font" # dictionary, optional

@classmethod # type: ignore
@property
def PROC_SET(cls) -> str:
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/ProcSet" # array, optional

@classmethod # type: ignore
@property
def PROPERTIES(cls) -> str:
deprecate_with_replacement("Ressources", "Resources", "5.0.0")
return "/Properties" # dictionary, optional


class PagesAttributes:
"""Page Attributes, Table 6.2, Page 52."""

Expand Down Expand Up @@ -629,7 +690,7 @@ class AnnotationFlag(IntFlag):
PageAttributes,
PageLayouts,
PagesAttributes,
Ressources,
Resources,
StreamAttributes,
TrailerKeys,
TypArguments,
Expand Down
5 changes: 2 additions & 3 deletions pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,16 +1416,15 @@ class Destination(TreeObject):
node: Optional[
DictionaryObject
] = None # node provide access to the original Object
childs: List[
Any
] = [] # used in PdfWriter - TODO: should be children # noqa: RUF012

def __init__(
self,
title: str,
page: Union[NumberObject, IndirectObject, NullObject, DictionaryObject],
fit: Fit,
) -> None:
self._filtered_children: List[Any] = [] # used in PdfWriter

typ = fit.fit_type
args = fit.fit_args

Expand Down
Loading