8000 Update fpdf2 stubs to 2.6.1 by srittau · Pull Request #9546 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Update fpdf2 stubs to 2.6.1 #9546

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

Merged
merged 11 commits into from
Jan 17, 2023
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
1 change: 1 addition & 0 deletions stubs/fpdf2/@tests/requirements-stubtest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cryptography
5 changes: 5 additions & 0 deletions stubs/fpdf2/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ fpdf.output.signer
# Argument has default at runtime, but using it raises a TypeError.
fpdf.FPDF.set_creation_date
fpdf.fpdf.FPDF.set_creation_date

# Checking the following function crashes stubtest 0.991, but seems to be
# fixed in later versions.
fpdf.FPDF.set_encryption
fpdf.fpdf.FPDF.set_encryption
4 changes: 2 additions & 2 deletions stubs/fpdf2/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version = "2.6.0"
requires = ["types-Pillow"]
version = "2.6.1"
requires = ["types-Pillow>=9.2.0"]

[tool.stubtest]
ignore_missing_stub = false
3 changes: 2 additions & 1 deletion stubs/fpdf2/fpdf/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from .enums import XPos as XPos, YPos as YPos
from .enums import Align as Align, XPos as XPos, YPos as YPos
from .fpdf import FPDF as FPDF, TitleStyle as TitleStyle
from .html import HTML2FPDF as HTML2FPDF, HTMLMixin as HTMLMixin
from .prefs import ViewerPreferences as ViewerPreferences
Expand All @@ -15,6 +15,7 @@ __all__ = [
"__version__",
"__license__",
"FPDF",
"Align",
"XPos",
"YPos",
"Template",
Expand Down
89 changes: 89 additions & 0 deletions stubs/fpdf2/fpdf/encryption.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from _typeshed import Incomplete, SupportsLenAndGetItem
from collections.abc import Generator, Iterable
from typing import ClassVar, Protocol, TypeVar
from typing_extensions import TypeAlias

from .enums import EncryptionMethod
from .fpdf import FPDF
from .syntax import Name, PDFObject

_Key: TypeAlias = SupportsLenAndGetItem[int]
_T_co = TypeVar("_T_co", covariant=True)

import_error: ImportError | None

class _SupportsGetItem(Protocol[_T_co]):
def __getitem__(self, __k: int) -> _T_co: ...

class ARC4:
MOD: ClassVar[int]
def KSA(self, key: _Key) -> list[int]: ...
def PRGA(self, S: _SupportsGetItem[int]) -> Generator[int, None, None]: ...
def encrypt(self, key: _Key, text: Iterable[int]) -> list[int]: ...

class CryptFilter:
type: Name
c_f_m: Name
length: int
def __init__(self, mode, length) -> None: ...
def serialize(self) -> str: ...

class EncryptionDictionary(PDFObject):
filter: Name
length: int
r: int
o: str
u: str
v: int
p: int
encrypt_metadata: str # not always defined
c_f: str # not always defined
stm_f: Name
str_f: Name
def __init__(self, security_handler: StandardSecurityHandler) -> None: ...

class StandardSecurityHandler:
DEFAULT_PADDING: ClassVar[bytes]
fpdf: FPDF
access_permission: int
owner_password: str
user_password: str
encryption_method: EncryptionMethod | None
cf: CryptFilter | None
key_length: int
v: int
r: int
encrypt_metadata: bool

# The following fields are only defined after a call to generate_passwords().
file_id: Incomplete
info_id: Incomplete
o: str
k: str
u: str

def __init__(
self,
fpdf: FPDF,
owner_password: str,
user_password: str | None = None,
permission: Incomplete | None = None,
encryption_method: EncryptionMethod | None = None,
encrypt_metadata: bool = False,
) -> None: ...
def generate_passwords(self, file_id) -> None: ...
def get_encryption_obj(self) -> EncryptionDictionary: ...
def encrypt(self, text: str | bytes | bytearray, obj_id) -> bytes: ...
def encrypt_string(self, string, obj_id): ...
def encrypt_stream(self, stream, obj_id): ...
def is_aes_algorithm(self) -> bool: ...
def encrypt_bytes(self, data, obj_id) -> list[int]: ...
def encrypt_AES_cryptography(self, key, data): ...
def get_initialization_vector(self, size: int) -> bytearray: ...
def padded_password(self, password: str) -> bytearray: ...
def generate_owner_password(self) -> str: ...
def generate_user_password(self) -> str: ...
def generate_encryption_key(self) -> bytes: ...

def md5(data: bytes) -> bytes: ...
def int32(n: int) -> int: ...
26 changes: 23 additions & 3 deletions stubs/fpdf2/fpdf/enums.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from _typeshed import Incomplete, Self
from enum import Enum, Flag, IntEnum
from _typeshed import Self
from enum import Enum, Flag, IntEnum, IntFlag
from typing_extensions import Literal

from .syntax import Name

Expand Down Expand Up @@ -182,4 +183,23 @@ class FontDescriptorFlags(Flag):
ITALIC: int
FORCE_BOLD: int

__pdoc__: Incomplete
class AccessPermission(IntFlag):
PRINT_LOW_RES: int
MODIFY: int
COPY: int
ANNOTATION: int
FILL_FORMS: int
COPY_FOR_ACCESSIBILITY: int
ASSEMBLE: int
PRINT_HIGH_RES: int
@classmethod
def all(cls) -> int: ...
@classmethod
def none(cls) -> Literal[0]: ...

class EncryptionMethod(Enum):
NO_ENCRYPTION: int
RC4: int
AES_128: int

__pdoc__: dict[str, bool]
35 changes: 26 additions & 9 deletions stubs/fpdf2/fpdf/fpdf.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from _typeshed import Incomplete, StrPath
from collections.abc import Callable, Iterable, Sequence
from contextlib import _GeneratorContextManager
from io import BytesIO
from re import Pattern
from typing import Any, ClassVar, NamedTuple, overload
from typing_extensions import Literal, TypeAlias

Expand Down Expand Up @@ -72,6 +73,8 @@ class FPDF:
MARKDOWN_BOLD_MARKER: ClassVar[str]
MARKDOWN_ITALICS_MARKER: ClassVar[str]
MARKDOWN_UNDERLINE_MARKER: ClassVar[str]
MARKDOWN_LINK_REGEX: ClassVar[Pattern[str]]
MARKDOWN_LINK_COLOR: ClassVar[Incomplete | None]

HTML2FPDF_CLASS: ClassVar[type[HTML2FPDF]]

Expand Down Expand Up @@ -144,6 +147,16 @@ class FPDF:
format: _Format | tuple[float, float] = ...,
font_cache_dir: Literal["DEPRECATED"] = ...,
) -> None: ...
# The following definition crashes stubtest 0.991, but seems to be fixed
# in later versions.
# def set_encryption(
# self,
# owner_password: str,
# user_password: str | None = None,
# encryption_method: EncryptionMethod | str = ...,
# permissions: AccessPermission = ...,
# encrypt_metadata: bool = False,
# ) -> None: ...
# args and kwargs are passed to HTML2FPDF_CLASS constructor.
def write_html(self, text: str, *args: Any, **kwargs: Any) -> None: ...
@property
Expand Down Expand Up @@ -288,8 +301,8 @@ class FPDF:
def set_font_size(self, size: float) -> None: ...
def set_char_spacing(self, spacing: float) -> None: ...
def set_stretching(self, stretching: float) -> None: ...
def add_link(self) -> int: ...
def set_link(self, link, y: int = ..., x: int = ..., page: int = ..., zoom: float | Literal["null"] = ...) -> None: ...
def add_link(self, y: float = 0, x: float = 0, page: int = -1, zoom: float | Literal["null"] = ...) -> int: ...
def set_link(self, link, y: float = 0, x: float = 0, page: int = -1, zoom: float | Literal["null"] = ...) -> None: ...
def link(
self, x: float, y: float, w: float, h: float, link: str | int, alt_text: str | None = ..., border_width: int = ...
) -> AnnotationDict: ...
Expand Down Expand Up @@ -364,6 +377,9 @@ class FPDF:
def text(self, x: float, y: float, txt: str = ...) -> None: ...
def rotate(self, angle: float, x: float | None = ..., y: float | None = ...) -> None: ...
def rotation(self, angle: float, x: float | None = ..., y: float | None = ...) -> _GeneratorContextManager[None]: ...
def skew(
self, ax: float = 0, ay: float = 0, x: float | None = None, y: float | None = None
) -> _GeneratorContextManager[None]: ...
def local_context(
self,
font_family: Incomplete | None = ...,
Expand Down Expand Up @@ -415,14 +431,15 @@ class FPDF:
def image(
self,
name: str | Image.Image | BytesIO | StrPath,
x: float | None = ...,
y: float | None = ...,
w: float = ...,
h: float = ...,
x: float | Align | None = None,
y: float | None = None,
w: float = 0,
h: float = 0,
type: str = ...,
link: str = ...,
title: str | None = ...,
alt_text: str | None = ...,
title: str | None = None,
alt_text: str | None = None,
dims: tuple[float, float] | None = None,
) -> _Image: ...
def ln(self, h: float | None = ...) -> None: ...
def get_x(self) -> float: ...
Expand Down Expand Up @@ -477,4 +494,4 @@ class FPDF:
level5: TitleStyle | None = ...,
level6: TitleStyle | None = ...,
) -> None: ...
def start_section(self, name: str, level: int = ...) -> None: ...
def start_section(self, name: str, level: int = 0, strict: bool = True) -> None: ...
14 changes: 9 additions & 5 deletions stubs/fpdf2/fpdf/html.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from collections.abc import Callable
from html.parser import HTMLParser
from logging import Logger
from re import Match, Pattern
from typing import ClassVar
from typing_extensions import Final

from fpdf import FPDF
Expand All @@ -24,6 +25,7 @@ def px2mm(px: float) -> float: ...
def color_as_decimal(color: str | None = ...) -> tuple[int, int, int] | None: ...

class HTML2FPDF(HTMLParser):
HTML_UNCLOSED_TAGS: ClassVar[tuple[str, ...]]
pdf: Incomplete
image_map: Incomplete
li_tag_indent: Incomplete
Expand Down Expand Up @@ -55,15 +57,17 @@ class HTML2FPDF(HTMLParser):
heading_sizes: Incomplete
heading_above: float
heading_below: float
warn_on_tags_not_matching: bool
def __init__(
self,
pdf: FPDF,
image_map: Callable[[str], str] | None = ...,
li_tag_indent: int = ...,
dd_tag_indent: int = ...,
table_line_separators: bool = ...,
image_map: Callable[[str], str] | None = None,
li_tag_indent: int = 5,
dd_tag_indent: int = 10,
table_line_separators: bool = False,
ul_bullet_char: str = ...,
heading_sizes: Incomplete | None = ...,
heading_sizes: Incomplete | None = None,
warn_on_tags_not_matching: bool = True,
**_: object,
): ...
def width2unit(self, length): ...
Expand Down
3 changes: 3 additions & 0 deletions stubs/fpdf2/fpdf/image_parsing.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from typing import Any
from typing_extensions import Literal, TypeAlias

from PIL.Image import Resampling

_ImageFilter: TypeAlias = Literal["AUTO", "FlateDecode", "DCTDecode", "JPXDecode"]

RESAMPLE: Resampling
SUPPORTED_IMAGE_FILTERS: tuple[_ImageFilter, ...]

def load_image(filename): ...
Expand Down
6 changes: 5 additions & 1 deletion stubs/fpdf2/fpdf/line_break.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class Fragment:
characters: list[str]
graphics_state: dict[str, Incomplete]
k: float
def __init__(self, characters: list[str] | str, graphics_st F42D ate: dict[str, Incomplete], k: float) -> None: ...
url: str | None
def __init__(
self, characters: list[str] | str, graphics_state: dict[str, Incomplete], k: float, url: str | None = None
) -> None: ...
@property
def font(self): ...
@font.setter
Expand Down Expand Up @@ -96,6 +99,7 @@ class CurrentLine:
k: float,
original_fragment_index: int,
original_character_index: int,
url: str | None = None,
): ...
def manual_break(self, justify: bool = ..., trailing_nl: bool = ...): ...
def automatic_break_possible(self): ...
Expand Down
3 changes: 2 additions & 1 deletion stubs/fpdf2/fpdf/linearization.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from _typeshed import Incomplete
from typing_extensions import Final

from .encryption import StandardSecurityHandler
from .output import ContentWithoutID, OutputProducer
from .syntax import PDFContentStream, PDFObject

Expand Down Expand Up @@ -34,7 +35,7 @@ class PDFXrefAndTrailer(ContentWithoutID):
def is_first_xref(self) -> bool: ...
@property
def is_main_xref(self) -> bool: ...
def serialize(self) -> str: ...
def serialize(self, _security_handler: StandardSecurityHandler | None = None) -> str: ...

class PDFHintStream(PDFContentStream):
s: Incomplete | None
Expand Down
13 changes: 8 additions & 5 deletions stubs/fpdf2/fpdf/output.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ from logging import Logger
from typing_extensions import Final

from .annotations import AnnotationDict
from .encryption import StandardSecurityHandler
from .syntax import Name, PDFArray, PDFContentStream, PDFObject

LOGGER: Logger
ZOOM_CONFIGS: Final[dict[str, tuple[str, ...]]]

class ContentWithoutID: ...
class ContentWithoutID:
def serialize(self, _security_handler: StandardSecurityHandler | None = None) -> str | None: ...

class PDFHeader(ContentWithoutID):
pdf_version: str
def __init__(self, pdf_version: str) -> None: ...
def serialize(self) -> str: ...
def serialize(self, _security_handler: StandardSecurityHandler | None = None) -> str: ...

class PDFFont(PDFObject):
type: Name
Expand Down Expand Up @@ -149,7 +151,8 @@ class PDFPage(PDFObject):
struct_parents: Incomplete | None
resources: Incomplete | None
parent: Incomplete | None
def __init__(self, duration: Incomplete | None, transition, contents) -> None: ...
def __init__(self, duration: Incomplete | None, transition, contents, index) -> None: ...
def index(self): ...
def dimensions(self) -> tuple[float | None, float | None]: ...
def set_dimensions(self, width_pt: float | None, height_pt: float | None) -> None: ...

Expand All @@ -162,15 +165,15 @@ class PDFPagesRoot(PDFObject):

class PDFExtGState(PDFObject):
def __init__(self, dict_as_str) -> None: ...
def serialize(self, obj_dict: object = ...) -> str: ...
def serialize(self, obj_dict: object = None, _security_handler: StandardSecurityHandler | None = None) -> str: ...

class PDFXrefAndTrailer(ContentWithoutID):
output_builder: Incomplete
count: int
catalog_obj: Incomplete | None
info_obj: Incomplete | None
def __init__(self, output_builder) -> None: ...
def serialize(self) -> str: ...
def serialize(self, _security_handler: StandardSecurityHandler | None = None) -> str: ...

class OutputProducer:
fpdf: Incomplete
Expand Down
3 changes: 2 additions & 1 deletion stubs/fpdf2/fpdf/structure_tree.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ from _typeshed import Incomplete
from collections import defaultdict
from collections.abc import Generator, Iterable

from .encryption import StandardSecurityHandler
from .syntax import PDFArray, PDFObject, PDFString

class NumberTree(PDFObject):
nums: defaultdict[Incomplete, list[Incomplete]]
def __init__(self) -> None: ...
def serialize(self, obj_dict: object = ...) -> str: ...
def serialize(self, obj_dict: object = ..., _security_handler: StandardSecurityHandler | None = None) -> str: ...

class StructTreeRoot(PDFObject):
type: str
Expand Down
Loading
0