Skip to content

Commit 761e32f

Browse files
committed
chore: Add initial typehint support for opc submodule
1 parent 33a1588 commit 761e32f

File tree

6 files changed

+184
-0
lines changed

6 files changed

+184
-0
lines changed

pptx-stubs/opc/__init__.pyi

Whitespace-only changes.

pptx-stubs/opc/package.pyi

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from collections.abc import Iterator, Mapping
2+
from typing import IO, Self
3+
4+
from pptx.opc.oxml import CT_Relationship, CT_Relationships
5+
from pptx.opc.packuri import PackURI
6+
from pptx.oxml.xmlchemy import BaseOxmlElement
7+
from pptx.package import Package
8+
from pptx.parts.presentation import PresentationPart
9+
from pptx.util import lazyproperty
10+
11+
class _RelatableMixin:
12+
def part_related_by(self, reltype: str) -> Part: ...
13+
def relate_to(self, target: Part | str, reltype: str, is_external: bool = ...) -> str: ...
14+
def related_part(self, rId: str) -> Part: ...
15+
def target_ref(self, rId: str) -> str: ...
16+
17+
class OpcPackage(_RelatableMixin):
18+
def __init__(self, pkg_file: str | IO[bytes]) -> None: ...
19+
@classmethod
20+
def open(cls, pkg_file: str | IO[bytes]) -> Self: ...
21+
def drop_rel(self, rId: str) -> None: ...
22+
def iter_parts(self) -> Iterator[Part]: ...
23+
def iter_rels(self) -> Iterator[_Relationship]: ...
24+
@property
25+
def main_document_part(self) -> PresentationPart: ...
26+
def next_partname(self, tmpl: str) -> PackURI: ...
27+
def save(self, pkg_file: str | IO[bytes]) -> None: ...
28+
29+
class _PackageLoader:
30+
def __init__(self, pkg_file: str | IO[bytes], package: Package) -> None: ...
31+
@classmethod
32+
def load(cls, pkg_file: str | IO[bytes], package: Package) -> tuple[CT_Relationships, dict[PackURI, Part]]: ...
33+
34+
class Part(_RelatableMixin):
35+
def __init__(self, partname: PackURI, content_type: str, package: Package, blob: bytes | None = ...) -> None: ...
36+
@classmethod
37+
def load(cls, partname: PackURI, content_type: str, package: Package, blob: bytes) -> Self: ...
38+
@property
39+
def blob(self) -> bytes: ...
40+
@blob.setter
41+
def blob(self, blob: bytes) -> None: ...
42+
@lazyproperty
43+
def content_type(self) -> str: ...
44+
def load_rels_from_xml(self, xml_rels: CT_Relationships, parts: dict[PackURI, Part]) -> None: ...
45+
@lazyproperty
46+
def package(self) -> Package: ...
47+
@property
48+
def partname(self) -> PackURI: ...
49+
@partname.setter
50+
def partname(self, partname: PackURI) -> None: ...
51+
@lazyproperty
52+
def rels(self) -> _Relationships: ...
53+
54+
class XmlPart(Part):
55+
def __init__(self, partname: PackURI, content_type: str, package: Package, element: BaseOxmlElement) -> None: ...
56+
@classmethod
57+
def load(cls, partname: PackURI, content_type: str, package: Package, blob: bytes) -> Self: ...
58+
@property
59+
def blob(self) -> bytes: ...
60+
def drop_rel(self, rId: str) -> None: ...
61+
@property
62+
def part(self) -> Self: ...
63+
64+
class PartFactory:
65+
part_type_for: dict[str, type[Part]] = ...
66+
def __new__(cls, partname: PackURI, content_type: str, package: Package, blob: bytes) -> Part: ...
67+
68+
class _ContentTypeMap:
69+
def __init__(self, overrides: dict[str, str], defaults: dict[str, str]) -> None: ...
70+
def __getitem__(self, partname: PackURI) -> str: ...
71+
@classmethod
72+
def from_xml(cls, content_types_xml: bytes) -> _ContentTypeMap: ...
73+
74+
class _Relationships(Mapping[str, "_Relationship"]):
75+
def __init__(self, base_uri: str) -> None: ...
76+
def __contains__(self, rId: object) -> bool: ...
77+
def __getitem__(self, rId: str) -> _Relationship: ...
78+
def __iter__(self) -> Iterator[str]: ...
79+
def __len__(self) -> int: ...
80+
def get_or_add(self, reltype: str, target_part: Part) -> str: ...
81+
def get_or_add_ext_rel(self, reltype: str, target_ref: str) -> str: ...
82+
def load_from_xml(self, base_uri: str, xml_rels: CT_Relationships, parts: dict[PackURI, Part]) -> None: ...
83+
def part_with_reltype(self, reltype: str) -> Part: ...
84+
def pop(self, rId: str) -> _Relationship: ...
85+
@property
86+
def xml(self) -> bytes: ...
87+
88+
class _Relationship:
89+
def __init__(self, base_uri: str, rId: str, reltype: str, target_mode: str, target: Part | str) -> None: ...
90+
@classmethod
91+
def from_xml(cls, base_uri: str, rel: CT_Relationship, parts: dict[PackURI, Part]) -> _Relationship: ...
92+
@lazyproperty
93+
def is_external(self) -> bool: ...
94+
@lazyproperty
95+
def reltype(self) -> str: ...
96+
@lazyproperty
97+
def rId(self) -> str: ...
98+
@lazyproperty
99+
def target_part(self) -> Part: ...
100+
@lazyproperty
101+
def target_partname(self) -> PackURI: ...
102+
@lazyproperty
103+
def target_ref(self) -> str: ...

pptx-stubs/opc/packuri.pyi

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from re import Pattern
2+
from typing import Self
3+
4+
class PackURI(str):
5+
_filename_re: Pattern[str] = ...
6+
def __new__(cls, pack_uri_str: str) -> Self: ...
7+
@staticmethod
8+
def from_rel_ref(baseURI: str, relative_ref: str) -> PackURI: ...
9+
@property
10+
def baseURI(self) -> str: ...
11+
@property
12+
def ext(self) -> str: ...
13+
@property
14+
def filename(self) -> str: ...
15+
@property
16+
def idx(self) -> int | None: ...
17+
@property
18+
def membername(self) -> str: ...
19+
def relative_ref(self, baseURI: str) -> str: ...
20+
@property
21+
def rels_uri(self) -> PackURI: ...
22+
23+
PACKAGE_URI: PackURI = ...
24+
CONTENT_TYPES_URI: PackURI = ...

pptx-stubs/opc/serialized.pyi

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from collections.abc import Container, Sequence
2+
from typing import IO, Any
3+
4+
from pptx.opc.oxml import CT_Types
5+
from pptx.opc.package import Part, _Relationships
6+
from pptx.opc.packuri import PackURI
7+
8+
class PackageReader(Container[bytes]):
9+
def __init__(self, pkg_file: str | IO[bytes]) -> None: ...
10+
def __contains__(self, pack_uri: object) -> bool: ...
11+
def __getitem__(self, pack_uri: PackURI) -> bytes: ...
12+
def rels_xml_for(self, partname: PackURI) -> bytes | None: ...
13+
14+
class PackageWriter:
15+
def __init__(self, pkg_file: str | IO[bytes], pkg_rels: _Relationships, parts: Sequence[Part]) -> None: ...
16+
@classmethod
17+
def write(cls, pkg_file: str | IO[bytes], pkg_rels: _Relationships, parts: Sequence[Part]) -> None: ...
18+
19+
class _PhysPkgReader(Container[PackURI]):
20+
def __contains__(self, item: object) -> bool: ...
21+
def __getitem__(self, pack_uri: PackURI) -> bytes: ...
22+
@classmethod
23+
def factory(cls, pkg_file: str | IO[bytes]) -> _PhysPkgReader: ...
24+
25+
class _DirPkgReader(_PhysPkgReader):
26+
def __init__(self, path: str) -> None: ...
27+
def __contains__(self, pack_uri: object) -> bool: ...
28+
def __getitem__(self, pack_uri: PackURI) -> bytes: ...
29+
30+
class _ZipPkgReader(_PhysPkgReader):
31+
def __init__(self, pkg_file: str | IO[bytes]) -> None: ...
32+
def __contains__(self, pack_uri: object) -> bool: ...
33+
def __getitem__(self, pack_uri: PackURI) -> bytes: ...
34+
35+
class _PhysPkgWriter:
36+
@classmethod
37+
def factory(cls, pkg_file: str | IO[bytes]) -> _ZipPkgWriter: ...
38+
def write(self, pack_uri: PackURI, blob: bytes) -> None: ...
39+
40+
class _ZipPkgWriter(_PhysPkgWriter):
41+
def __init__(self, pkg_file: str | IO[bytes]) -> None: ...
42+
def __enter__(self) -> _ZipPkgWriter: ...
43+
def __exit__(self, *exc: list[Any]) -> None: ...
44+
def write(self, pack_uri: PackURI, blob: bytes) -> None: ...
45+
46+
class _ContentTypesItem:
47+
def __init__(self, parts: Sequence[Part]) -> None: ...
48+
@classmethod
49+
def xml_for(cls, parts: Sequence[Part]) -> CT_Types: ...

pptx-stubs/opc/shared.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from typing import Any
2+
3+
class CaseInsensitiveDict(dict):
4+
def __contains__(self, key: Any) -> bool: ...
5+
def __getitem__(self, key: Any): ...
6+
def __setitem__(self, key: Any, value: Any) -> None: ...

pptx-stubs/opc/spec.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
default_content_types: tuple[tuple[str, str]] = ...
2+
image_content_types: dict[str, str] = ...

0 commit comments

Comments
 (0)