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 pathlib import Path
5from typing import IO, Any, Optional, Protocol, Union
7from ._utils import StrByteType, StreamType
10class PdfObjectProtocol(Protocol):
11 indirect_reference: Any
13 def clone(
14 self,
15 pdf_dest: Any,
16 force_duplicate: bool = False,
17 ignore_fields: Union[tuple[str, ...], list[str], None] = (),
18 ) -> Any:
19 ... # pragma: no cover
21 def _reference_clone(self, clone: Any, pdf_dest: Any) -> Any:
22 ... # pragma: no cover
24 def get_object(self) -> Optional["PdfObjectProtocol"]:
25 ... # pragma: no cover
27 def hash_value(self) -> bytes:
28 ... # pragma: no cover
30 def write_to_stream(
31 self, stream: StreamType, encryption_key: Union[None, str, bytes] = None
32 ) -> None:
33 ... # pragma: no cover
36class XmpInformationProtocol(PdfObjectProtocol):
37 pass
40class PdfCommonDocProtocol(Protocol):
41 @property
42 def pdf_header(self) -> str:
43 ... # pragma: no cover
45 @property
46 def pages(self) -> list[Any]:
47 ... # pragma: no cover
49 @property
50 def root_object(self) -> PdfObjectProtocol:
51 ... # pragma: no cover
53 def get_object(self, indirect_reference: Any) -> Optional[PdfObjectProtocol]:
54 ... # pragma: no cover
56 @property
57 def strict(self) -> bool:
58 ... # pragma: no cover
61class PdfReaderProtocol(PdfCommonDocProtocol, Protocol):
62 @property
63 @abstractmethod
64 def xref(self) -> dict[int, dict[int, Any]]:
65 ... # pragma: no cover
67 @property
68 @abstractmethod
69 def trailer(self) -> dict[str, Any]:
70 ... # pragma: no cover
73class PdfWriterProtocol(PdfCommonDocProtocol, Protocol):
74 _objects: list[Any]
75 _id_translated: dict[int, dict[int, int]]
77 incremental: bool
78 _reader: Any # PdfReader
80 @abstractmethod
81 def write(self, stream: Union[Path, StrByteType]) -> tuple[bool, IO[Any]]:
82 ... # pragma: no cover
84 @abstractmethod
85 def _add_object(self, obj: Any) -> Any:
86 ... # pragma: no cover