Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pypdf/_protocols.py: 100%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Helpers for working with PDF types."""
3from abc import abstractmethod
4from collections.abc import Sequence
5from pathlib import Path
6from typing import IO, Any, Literal, Optional, Protocol, Union
8from ._utils import StrByteType, StreamType
11class PdfObjectProtocol(Protocol):
12 indirect_reference: Any
14 def clone(
15 self,
16 pdf_dest: Any,
17 force_duplicate: bool = False,
18 ignore_fields: Union[tuple[str, ...], list[str], None] = (),
19 ) -> Any:
20 ... # pragma: no cover
22 def _reference_clone(self, clone: Any, pdf_dest: Any) -> Any:
23 ... # pragma: no cover
25 def get_object(self) -> Optional["PdfObjectProtocol"]:
26 ... # pragma: no cover
28 def hash_value(self) -> bytes:
29 ... # pragma: no cover
31 def write_to_stream(
32 self, stream: StreamType, encryption_key: Union[str, bytes, None] = None
33 ) -> None:
34 ... # pragma: no cover
37class XmpInformationProtocol(PdfObjectProtocol):
38 pass
41class PdfCommonDocProtocol(Protocol):
42 @property
43 def pdf_header(self) -> str:
44 ... # pragma: no cover
46 @property
47 def pages(self) -> Sequence[Any]:
48 ... # pragma: no cover
50 @property
51 def root_object(self) -> PdfObjectProtocol:
52 ... # pragma: no cover
54 def get_object(self, indirect_reference: Any) -> Optional[PdfObjectProtocol]:
55 ... # pragma: no cover
57 @property
58 def strict(self) -> bool:
59 ... # pragma: no cover
62class PdfReaderProtocol(PdfCommonDocProtocol, Protocol):
63 @property
64 @abstractmethod
65 def xref(self) -> dict[int, dict[int, Any]]:
66 ... # pragma: no cover
68 @property
69 @abstractmethod
70 def trailer(self) -> dict[str, Any]:
71 ... # pragma: no cover
74class PdfWriterProtocol(PdfCommonDocProtocol, Protocol):
75 _objects: list[Any]
76 # The "PreventGC" entry holds the source document, keeping it alive while
77 # the translation table is in use.
78 _id_translated: dict[int, dict[Union[int, Literal["PreventGC"]], Any]]
80 incremental: bool
81 # Only populated in incremental mode, None otherwise.
82 _reader: Optional[Any] # PdfReader
84 @abstractmethod
85 def write(self, stream: Union[Path, StrByteType]) -> tuple[bool, IO[Any]]:
86 ... # pragma: no cover
88 @abstractmethod
89 def _add_object(self, obj: Any) -> Any:
90 ... # pragma: no cover