Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_protocols.py87 linesDownload Raw Back to pypdf
1"""Helpers for working with PDF types."""2 3from abc import abstractmethod4from pathlib import Path5from typing import IO, Any, Optional, Protocol, Union6 7from ._utils import StrByteType, StreamType8 9 10class PdfObjectProtocol(Protocol):11    indirect_reference: Any12 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 cover20 21    def _reference_clone(self, clone: Any, pdf_dest: Any) -> Any:22        ...  # pragma: no cover23 24    def get_object(self) -> Optional["PdfObjectProtocol"]:25        ...  # pragma: no cover26 27    def hash_value(self) -> bytes:28        ...  # pragma: no cover29 30    def write_to_stream(31        self, stream: StreamType, encryption_key: Union[None, str, bytes] = None32    ) -> None:33        ...  # pragma: no cover34 35 36class XmpInformationProtocol(PdfObjectProtocol):37    pass38 39 40class PdfCommonDocProtocol(Protocol):41    @property42    def pdf_header(self) -> str:43        ...  # pragma: no cover44 45    @property46    def pages(self) -> list[Any]:47        ...  # pragma: no cover48 49    @property50    def root_object(self) -> PdfObjectProtocol:51        ...  # pragma: no cover52 53    def get_object(self, indirect_reference: Any) -> Optional[PdfObjectProtocol]:54        ...  # pragma: no cover55 56    @property57    def strict(self) -> bool:58        ...  # pragma: no cover59 60 61class PdfReaderProtocol(PdfCommonDocProtocol, Protocol):62    @property63    @abstractmethod64    def xref(self) -> dict[int, dict[int, Any]]:65        ...  # pragma: no cover66 67    @property68    @abstractmethod69    def trailer(self) -> dict[str, Any]:70        ...  # pragma: no cover71 72 73class PdfWriterProtocol(PdfCommonDocProtocol, Protocol):74    _objects: list[Any]75    _id_translated: dict[int, dict[int, int]]76 77    incremental: bool78    _reader: Any  # PdfReader79 80    @abstractmethod81    def write(self, stream: Union[Path, StrByteType]) -> tuple[bool, IO[Any]]:82        ...  # pragma: no cover83 84    @abstractmethod85    def _add_object(self, obj: Any) -> Any:86        ...  # pragma: no cover87 
codekingpro/portable-devtools · Team Ai