Skip to content

Commit 7b848b4

Browse files
authored
Update fpdf2 stubs to 2.6.1 (#9546)
1 parent 2b9f200 commit 7b848b4

14 files changed

+184
-30
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cryptography

stubs/fpdf2/@tests/stubtest_allowlist.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ fpdf.output.signer
1212
# Argument has default at runtime, but using it raises a TypeError.
1313
fpdf.FPDF.set_creation_date
1414
fpdf.fpdf.FPDF.set_creation_date
15+
16+
# Checking the following function crashes stubtest 0.991, but seems to be
17+
# fixed in later versions.
18+
fpdf.FPDF.set_encryption
19+
fpdf.fpdf.FPDF.set_encryption

stubs/fpdf2/METADATA.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
version = "2.6.0"
2-
requires = ["types-Pillow"]
1+
version = "2.6.1"
2+
requires = ["types-Pillow>=9.2.0"]
33

44
[tool.stubtest]
55
ignore_missing_stub = false

stubs/fpdf2/fpdf/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pathlib import Path
22

3-
from .enums import XPos as XPos, YPos as YPos
3+
from .enums import Align as Align, XPos as XPos, YPos as YPos
44
from .fpdf import FPDF as FPDF, TitleStyle as TitleStyle
55
from .html import HTML2FPDF as HTML2FPDF, HTMLMixin as HTMLMixin
66
from .prefs import ViewerPreferences as ViewerPreferences
@@ -15,6 +15,7 @@ __all__ = [
1515
"__version__",
1616
"__license__",
1717
"FPDF",
18+
"Align",
1819
"XPos",
1920
"YPos",
2021
"Template",

stubs/fpdf2/fpdf/encryption.pyi

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
from _typeshed import Incomplete, SupportsLenAndGetItem
2+
from collections.abc import Generator, Iterable
3+
from typing import ClassVar, Protocol, TypeVar
4+
from typing_extensions import TypeAlias
5+
6+
from .enums import EncryptionMethod
7+
from .fpdf import FPDF
8+
from .syntax import Name, PDFObject
9+
10+
_Key: TypeAlias = SupportsLenAndGetItem[int]
11+
_T_co = TypeVar("_T_co", covariant=True)
12+
13+
import_error: ImportError | None
14+
15+
class _SupportsGetItem(Protocol[_T_co]):
16+
def __getitem__(self, __k: int) -> _T_co: ...
17+
18+
class ARC4:
19+
MOD: ClassVar[int]
20+
def KSA(self, key: _Key) -> list[int]: ...
21+
def PRGA(self, S: _SupportsGetItem[int]) -> Generator[int, None, None]: ...
22+
def encrypt(self, key: _Key, text: Iterable[int]) -> list[int]: ...
23+
24+
class CryptFilter:
25+
type: Name
26+
c_f_m: Name
27+
length: int
28+
def __init__(self, mode, length) -> None: ...
29+
def serialize(self) -> str: ...
30+
31+
class EncryptionDictionary(PDFObject):
32+
filter: Name
33+
length: int
34+
r: int
35+
o: str
36+
u: str
37+
v: int
38+
p: int
39+
encrypt_metadata: str # not always defined
40+
c_f: str # not always defined
41+
stm_f: Name
42+
str_f: Name
43+
def __init__(self, security_handler: StandardSecurityHandler) -> None: ...
44+
45+
class StandardSecurityHandler:
46+
DEFAULT_PADDING: ClassVar[bytes]
47+
fpdf: FPDF
48+
access_permission: int
49+
owner_password: str
50+
user_password: str
51+
encryption_method: EncryptionMethod | None
52+
cf: CryptFilter | None
53+
key_length: int
54+
v: int
55+
r: int
56+
encrypt_metadata: bool
57+
58+
# The following fields are only defined after a call to generate_passwords().
59+
file_id: Incomplete
60+
info_id: Incomplete
61+
o: str
62+
k: str
63+
u: str
64+
65+
def __init__(
66+
self,
67+
fpdf: FPDF,
68+
owner_password: str,
69+
user_password: str | None = None,
70+
permission: Incomplete | None = None,
71+
encryption_method: EncryptionMethod | None = None,
72+
encrypt_metadata: bool = False,
73+
) -> None: ...
74+
def generate_passwords(self, file_id) -> None: ...
75+
def get_encryption_obj(self) -> EncryptionDictionary: ...
76+
def encrypt(self, text: str | bytes | bytearray, obj_id) -> bytes: ...
77+
def encrypt_string(self, string, obj_id): ...
78+
def encrypt_stream(self, stream, obj_id): ...
79+
def is_aes_algorithm(self) -> bool: ...
80+
def encrypt_bytes(self, data, obj_id) -> list[int]: ...
81+
def encrypt_AES_cryptography(self, key, data): ...
82+
def get_initialization_vector(self, size: int) -> bytearray: ...
83+
def padded_password(self, password: str) -> bytearray: ...
84+
def generate_owner_password(self) -> str: ...
85+
def generate_user_password(self) -> str: ...
86+
def generate_encryption_key(self) -> bytes: ...
87+
88+
def md5(data: bytes) -> bytes: ...
89+
def int32(n: int) -> int: ...

stubs/fpdf2/fpdf/enums.pyi

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from _typeshed import Incomplete, Self
2-
from enum import Enum, Flag, IntEnum
1+
from _typeshed import Self
2+
from enum import Enum, Flag, IntEnum, IntFlag
3+
from typing_extensions import Literal
34

45
from .syntax import Name
56

@@ -182,4 +183,23 @@ class FontDescriptorFlags(Flag):
182183
ITALIC: int
183184
FORCE_BOLD: int
184185

185-
__pdoc__: Incomplete
186+
class AccessPermission(IntFlag):
187+
PRINT_LOW_RES: int
188+
MODIFY: int
189+
COPY: int
190+
ANNOTATION: int
191+
FILL_FORMS: int
192+
COPY_FOR_ACCESSIBILITY: int
193+
ASSEMBLE: int
194+
PRINT_HIGH_RES: int
195+
@classmethod
196+
def all(cls) -> int: ...
197+
@classmethod
198+
def none(cls) -> Literal[0]: ...
199+
200+
class EncryptionMethod(Enum):
201+
NO_ENCRYPTION: int
202+
RC4: int
203+
AES_128: int
204+
205+
__pdoc__: dict[str, bool]

stubs/fpdf2/fpdf/fpdf.pyi

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from _typeshed import Incomplete, StrPath
33
from collections.abc import Callable, Iterable, Sequence
44
from contextlib import _GeneratorContextManager
55
from io import BytesIO
6+
from re import Pattern
67
from typing import Any, ClassVar, NamedTuple, overload
78
from typing_extensions import Literal, TypeAlias
89

@@ -72,6 +73,8 @@ class FPDF:
7273
MARKDOWN_BOLD_MARKER: ClassVar[str]
7374
MARKDOWN_ITALICS_MARKER: ClassVar[str]
7475
MARKDOWN_UNDERLINE_MARKER: ClassVar[str]
76+
MARKDOWN_LINK_REGEX: ClassVar[Pattern[str]]
77+
MARKDOWN_LINK_COLOR: ClassVar[Incomplete | None]
7578

7679
HTML2FPDF_CLASS: ClassVar[type[HTML2FPDF]]
7780

@@ -144,6 +147,16 @@ class FPDF:
144147
format: _Format | tuple[float, float] = ...,
145148
font_cache_dir: Literal["DEPRECATED"] = ...,
146149
) -> None: ...
150+
# The following definition crashes stubtest 0.991, but seems to be fixed
151+
# in later versions.
152+
# def set_encryption(
153+
# self,
154+
# owner_password: str,
155+
# user_password: str | None = None,
156+
# encryption_method: EncryptionMethod | str = ...,
157+
# permissions: AccessPermission = ...,
158+
# encrypt_metadata: bool = False,
159+
# ) -> None: ...
147160
# args and kwargs are passed to HTML2FPDF_CLASS constructor.
148161
def write_html(self, text: str, *args: Any, **kwargs: Any) -> None: ...
149162
@property
@@ -288,8 +301,8 @@ class FPDF:
288301
def set_font_size(self, size: float) -> None: ...
289302
def set_char_spacing(self, spacing: float) -> None: ...
290303
def set_stretching(self, stretching: float) -> None: ...
291-
def add_link(self) -> int: ...
292-
def set_link(self, link, y: int = ..., x: int = ..., page: int = ..., zoom: float | Literal["null"] = ...) -> None: ...
304+
def add_link(self, y: float = 0, x: float = 0, page: int = -1, zoom: float | Literal["null"] = ...) -> int: ...
305+
def set_link(self, link, y: float = 0, x: float = 0, page: int = -1, zoom: float | Literal["null"] = ...) -> None: ...
293306
def link(
294307
self, x: float, y: float, w: float, h: float, link: str | int, alt_text: str | None = ..., border_width: int = ...
295308
) -> AnnotationDict: ...
@@ -364,6 +377,9 @@ class FPDF:
364377
def text(self, x: float, y: float, txt: str = ...) -> None: ...
365378
def rotate(self, angle: float, x: float | None = ..., y: float | None = ...) -> None: ...
366379
def rotation(self, angle: float, x: float | None = ..., y: float | None = ...) -> _GeneratorContextManager[None]: ...
380+
def skew(
381+
self, ax: float = 0, ay: float = 0, x: float | None = None, y: float | None = None
382+
) -> _GeneratorContextManager[None]: ...
367383
def local_context(
368384
self,
369385
font_family: Incomplete | None = ...,
@@ -415,14 +431,15 @@ class FPDF:
415431
def image(
416432
self,
417433
name: str | Image.Image | BytesIO | StrPath,
418-
x: float | None = ...,
419-
y: float | None = ...,
420-
w: float = ...,
421-
h: float = ...,
434+
x: float | Align | None = None,
435+
y: float | None = None,
436+
w: float = 0,
437+
h: float = 0,
422438
type: str = ...,
423439
link: str = ...,
424-
title: str | None = ...,
425-
alt_text: str | None = ...,
440+
title: str | None = None,
441+
alt_text: str | None = None,
442+
dims: tuple[float, float] | None = None,
426443
) -> _Image: ...
427444
def ln(self, h: float | None = ...) -> None: ...
428445
def get_x(self) -> float: ...
@@ -477,4 +494,4 @@ class FPDF:
477494
level5: TitleStyle | None = ...,
478495
level6: TitleStyle | None = ...,
479496
) -> None: ...
480-
def start_section(self, name: str, level: int = ...) -> None: ...
497+
def start_section(self, name: str, level: int = 0, strict: bool = True) -> None: ...

stubs/fpdf2/fpdf/html.pyi

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from collections.abc import Callable
33
from html.parser import HTMLParser
44
from logging import Logger
55
from re import Match, Pattern
6+
from typing import ClassVar
67
from typing_extensions import Final
78

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

2627
class HTML2FPDF(HTMLParser):
28+
HTML_UNCLOSED_TAGS: ClassVar[tuple[str, ...]]
2729
pdf: Incomplete
2830
image_map: Incomplete
2931
li_tag_indent: Incomplete
@@ -55,15 +57,17 @@ class HTML2FPDF(HTMLParser):
5557
heading_sizes: Incomplete
5658
heading_above: float
5759
heading_below: float
60+
warn_on_tags_not_matching: bool
5861
def __init__(
5962
self,
6063
pdf: FPDF,
61-
image_map: Callable[[str], str] | None = ...,
62-
li_tag_indent: int = ...,
63-
dd_tag_indent: int = ...,
64-
table_line_separators: bool = ...,
64+
image_map: Callable[[str], str] | None = None,
65+
li_tag_indent: int = 5,
66+
dd_tag_indent: int = 10,
67+
table_line_separators: bool = False,
6568
ul_bullet_char: str = ...,
66-
heading_sizes: Incomplete | None = ...,
69+
heading_sizes: Incomplete | None = None,
70+
warn_on_tags_not_matching: bool = True,
6771
**_: object,
6872
): ...
6973
def width2unit(self, length): ...

stubs/fpdf2/fpdf/image_parsing.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from typing import Any
22
from typing_extensions import Literal, TypeAlias
33

4+
from PIL.Image import Resampling
5+
46
_ImageFilter: TypeAlias = Literal["AUTO", "FlateDecode", "DCTDecode", "JPXDecode"]
57

8+
RESAMPLE: Resampling
69
SUPPORTED_IMAGE_FILTERS: tuple[_ImageFilter, ...]
710

811
def load_image(filename): ...

stubs/fpdf2/fpdf/line_break.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class Fragment:
1111
characters: list[str]
1212
graphics_state: dict[str, Incomplete]
1313
k: float
14-
def __init__(self, characters: list[str] | str, graphics_state: dict[str, Incomplete], k: float) -> None: ...
14+
url: str | None
15+
def __init__(
16+
self, characters: list[str] | str, graphics_state: dict[str, Incomplete], k: float, url: str | None = None
17+
) -> None: ...
1518
@property
1619
def font(self): ...
1720
@font.setter
@@ -96,6 +99,7 @@ class CurrentLine:
9699
k: float,
97100
original_fragment_index: int,
98101
original_character_index: int,
102+
url: str | None = None,
99103
): ...
100104
def manual_break(self, justify: bool = ..., trailing_nl: bool = ...): ...
101105
def automatic_break_possible(self): ...

stubs/fpdf2/fpdf/linearization.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from _typeshed import Incomplete
22
from typing_extensions import Final
33

4+
from .encryption import StandardSecurityHandler
45
from .output import ContentWithoutID, OutputProducer
56
from .syntax import PDFContentStream, PDFObject
67

@@ -34,7 +35,7 @@ class PDFXrefAndTrailer(ContentWithoutID):
3435
def is_first_xref(self) -> bool: ...
3536
@property
3637
def is_main_xref(self) -> bool: ...
37-
def serialize(self) -> str: ...
38+
def serialize(self, _security_handler: StandardSecurityHandler | None = None) -> str: ...
3839

3940
class PDFHintStream(PDFContentStream):
4041
s: Incomplete | None

stubs/fpdf2/fpdf/output.pyi

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ from logging import Logger
44
from typing_extensions import Final
55

66
from .annotations import AnnotationDict
7+
from .encryption import StandardSecurityHandler
78
from .syntax import Name, PDFArray, PDFContentStream, PDFObject
89

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

12-
class ContentWithoutID: ...
13+
class ContentWithoutID:
14+
def serialize(self, _security_handler: StandardSecurityHandler | None = None) -> str | None: ...
1315

1416
class PDFHeader(ContentWithoutID):
1517
pdf_version: str
1618
def __init__(self, pdf_version: str) -> None: ...
17-
def serialize(self) -> str: ...
19+
def serialize(self, _security_handler: StandardSecurityHandler | None = None) -> str: ...
1820

1921
class PDFFont(PDFObject):
2022
type: Name
@@ -149,7 +151,8 @@ class PDFPage(PDFObject):
149151
struct_parents: Incomplete | None
150152
resources: Incomplete | None
151153
parent: Incomplete | None
152-
def __init__(self, duration: Incomplete | None, transition, contents) -> None: ...
154+
def __init__(self, duration: Incomplete | None, transition, contents, index) -> None: ...
155+
def index(self): ...
153156
def dimensions(self) -> tuple[float | None, float | None]: ...
154157
def set_dimensions(self, width_pt: float | None, height_pt: float | None) -> None: ...
155158

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

163166
class PDFExtGState(PDFObject):
164167
def __init__(self, dict_as_str) -> None: ...
165-
def serialize(self, obj_dict: object = ...) -> str: ...
168+
def serialize(self, obj_dict: object = None, _security_handler: StandardSecurityHandler | None = None) -> str: ...
166169

167170
class PDFXrefAndTrailer(ContentWithoutID):
168171
output_builder: Incomplete
169172
count: int
170173
catalog_obj: Incomplete | None
171174
info_obj: Incomplete | None
172175
def __init__(self, output_builder) -> None: ...
173-
def serialize(self) -> str: ...
176+
def serialize(self, _security_handler: StandardSecurityHandler | None = None) -> str: ...
174177

175178
class OutputProducer:
176179
fpdf: Incomplete

stubs/fpdf2/fpdf/structure_tree.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ from _typeshed import Incomplete
22
from collections import defaultdict
33
from collections.abc import Generator, Iterable
44

5+
from .encryption import StandardSecurityHandler
56
from .syntax import PDFArray, PDFObject, PDFString
67

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

1213
class StructTreeRoot(PDFObject):
1314
type: str

0 commit comments

Comments
 (0)