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

41 statements  

1"""Helpers for working with PDF types.""" 

2 

3from abc import abstractmethod 

4from collections.abc import Sequence 

5from pathlib import Path 

6from typing import IO, Any, Literal, Optional, Protocol, Union 

7 

8from ._utils import StrByteType, StreamType 

9 

10 

11class PdfObjectProtocol(Protocol): 

12 indirect_reference: Any 

13 

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 

21 

22 def _reference_clone(self, clone: Any, pdf_dest: Any) -> Any: 

23 ... # pragma: no cover 

24 

25 def get_object(self) -> Optional["PdfObjectProtocol"]: 

26 ... # pragma: no cover 

27 

28 def hash_value(self) -> bytes: 

29 ... # pragma: no cover 

30 

31 def write_to_stream( 

32 self, stream: StreamType, encryption_key: Union[str, bytes, None] = None 

33 ) -> None: 

34 ... # pragma: no cover 

35 

36 

37class XmpInformationProtocol(PdfObjectProtocol): 

38 pass 

39 

40 

41class PdfCommonDocProtocol(Protocol): 

42 @property 

43 def pdf_header(self) -> str: 

44 ... # pragma: no cover 

45 

46 @property 

47 def pages(self) -> Sequence[Any]: 

48 ... # pragma: no cover 

49 

50 @property 

51 def root_object(self) -> PdfObjectProtocol: 

52 ... # pragma: no cover 

53 

54 def get_object(self, indirect_reference: Any) -> Optional[PdfObjectProtocol]: 

55 ... # pragma: no cover 

56 

57 @property 

58 def strict(self) -> bool: 

59 ... # pragma: no cover 

60 

61 

62class PdfReaderProtocol(PdfCommonDocProtocol, Protocol): 

63 @property 

64 @abstractmethod 

65 def xref(self) -> dict[int, dict[int, Any]]: 

66 ... # pragma: no cover 

67 

68 @property 

69 @abstractmethod 

70 def trailer(self) -> dict[str, Any]: 

71 ... # pragma: no cover 

72 

73 

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]] 

79 

80 incremental: bool 

81 # Only populated in incremental mode, None otherwise. 

82 _reader: Optional[Any] # PdfReader 

83 

84 @abstractmethod 

85 def write(self, stream: Union[Path, StrByteType]) -> tuple[bool, IO[Any]]: 

86 ... # pragma: no cover 

87 

88 @abstractmethod 

89 def _add_object(self, obj: Any) -> Any: 

90 ... # pragma: no cover