Skip to content

Commit 0d05183

Browse files
authored
[et-xmlfile] Add stubs (#14962)
1 parent 9fc1377 commit 0d05183

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed

stubs/et_xmlfile/METADATA.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = "2.0.*"
2+
upstream_repository = "https://foss.heptapod.net/openpyxl/et_xmlfile"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import Final
2+
3+
from .xmlfile import xmlfile as xmlfile
4+
5+
__version__: Final[str]
6+
__author__: Final[str]
7+
__license__: Final[str]
8+
__author_email__: Final[str]
9+
__url__: Final[str]
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import xml.etree.ElementTree as ET
2+
from _typeshed import Unused
3+
from collections.abc import Callable
4+
from typing import Any, Literal, overload
5+
6+
def current_global_nsmap() -> dict[str, str]: ...
7+
8+
class IncrementalTree(ET.ElementTree):
9+
def write( # type: ignore[override]
10+
self,
11+
file_or_filename: ET._FileWrite,
12+
encoding: str | None = None,
13+
xml_declaration: bool | None = None,
14+
default_namespace: str | None = None,
15+
method: Literal["xml", "html", "text"] | None = None, # does not accept 'c14n', unlike parent method
16+
*,
17+
short_empty_elements: bool = True,
18+
nsmap: dict[str, str] | None = None,
19+
root_ns_only: bool = False,
20+
minimal_ns_only: bool = False,
21+
) -> None: ...
22+
23+
def process_attribs(
24+
elem: ET.Element[Any],
25+
is_nsmap_scope_changed: bool | None,
26+
default_ns_attr_prefix: str | None,
27+
nsmap_scope: dict[str, str],
28+
global_nsmap: dict[str, str],
29+
new_namespace_prefixes: set[str],
30+
uri_to_prefix: dict[str, str],
31+
) -> tuple[list[tuple[str, str]], str | None, dict[str, str]]: ...
32+
def write_elem_start(
33+
write: Callable[..., None],
34+
elem: ET.Element[Any],
35+
nsmap_scope: dict[str, str],
36+
global_nsmap: dict[str, str],
37+
short_empty_elements: bool | None,
38+
is_html: bool | None,
39+
is_root: bool = False,
40+
uri_to_prefix: dict[str, str] | None = None,
41+
default_ns_attr_prefix: str | None = None,
42+
new_nsmap: dict[str, str] | None = None,
43+
**kwargs: Unused,
44+
) -> tuple[str | None, dict[str, str], str | None, dict[str, str] | None, bool]: ...
45+
@overload
46+
def tostring(
47+
element: ET.Element[Any],
48+
encoding: None = None,
49+
method: Literal["xml", "html", "text"] | None = None,
50+
*,
51+
xml_declaration: bool | None = None,
52+
default_namespace: str | None = None,
53+
short_empty_elements: bool = True,
54+
nsmap: dict[str, str] | None = None,
55+
root_ns_only: bool = False,
56+
minimal_ns_only: bool = False,
57+
tree_cls: type[ET.ElementTree] = ...,
58+
) -> bytes: ...
59+
@overload
60+
def tostring(
61+
element: ET.Element[Any],
62+
encoding: Literal["unicode"],
63+
method: Literal["xml", "html", "text"] | None = None,
64+
*,
65+
xml_declaration: bool | None = None,
66+
default_namespace: str | None = None,
67+
short_empty_elements: bool = True,
68+
nsmap: dict[str, str] | None = None,
69+
root_ns_only: bool = False,
70+
minimal_ns_only: bool = False,
71+
tree_cls: type[ET.ElementTree] = ...,
72+
) -> str: ...
73+
@overload
74+
def tostring(
75+
element: ET.Element[Any],
76+
encoding: str,
77+
method: Literal["xml", "html", "text"] | None = None,
78+
*,
79+
xml_declaration: bool | None = None,
80+
default_namespace: str | None = None,
81+
short_empty_elements: bool = True,
82+
nsmap: dict[str, str] | None = None,
83+
root_ns_only: bool = False,
84+
minimal_ns_only: bool = False,
85+
tree_cls: type[ET.ElementTree] = ...,
86+
) -> Any: ...
87+
@overload
88+
def tostringlist(
89+
element: ET.Element[Any],
90+
encoding: None = None,
91+
method: Literal["xml", "html", "text"] | None = None,
92+
*,
93+
xml_declaration: bool | None = None,
94+
default_namespace: str | None = None,
95+
short_empty_elements: bool = True,
96+
nsmap: dict[str, str] | None = None,
97+
root_ns_only: bool = False,
98+
minimal_ns_only: bool = False,
99+
tree_cls: type[ET.ElementTree] = ...,
100+
) -> list[bytes]: ...
101+
@overload
102+
def tostringlist(
103+
element: ET.Element[Any],
104+
encoding: Literal["unicode"],
105+
method: Literal["xml", "html", "text"] | None = None,
106+
*,
107+
xml_declaration: bool | None = None,
108+
default_namespace: str | None = None,
109+
short_empty_elements: bool = True,
110+
nsmap: dict[str, str] | None = None,
111+
root_ns_only: bool = False,
112+
minimal_ns_only: bool = False,
113+
tree_cls: type[ET.ElementTree] = ...,
114+
) -> list[str]: ...
115+
@overload
116+
def tostringlist(
117+
element: ET.Element[Any],
118+
encoding: str,
119+
method: Literal["xml", "html", "text"] | None = None,
120+
*,
121+
xml_declaration: bool | None = None,
122+
default_namespace: str | None = None,
123+
short_empty_elements: bool = True,
124+
nsmap: dict[str, str] | None = None,
125+
root_ns_only: bool = False,
126+
minimal_ns_only: bool = False,
127+
tree_cls: type[ET.ElementTree] = ...,
128+
) -> list[Any]: ...
129+
@overload
130+
def compat_tostring(
131+
element: ET.Element[Any],
132+
encoding: None = None,
133+
method: Literal["xml", "html", "text"] | None = None,
134+
*,
135+
xml_declaration: bool | None = None,
136+
default_namespace: str | None = None,
137+
short_empty_elements: bool = True,
138+
nsmap: dict[str, str] | None = None,
139+
root_ns_only: bool = True,
140+
minimal_ns_only: bool = False,
141+
tree_cls: type[ET.ElementTree] = ...,
142+
) -> bytes: ...
143+
@overload
144+
def compat_tostring(
145+
element: ET.Element[Any],
146+
encoding: Literal["unicode"],
147+
method: Literal["xml", "html", "text"] | None = None,
148+
*,
149+
xml_declaration: bool | None = None,
150+
default_namespace: str | None = None,
151+
short_empty_elements: bool = True,
152+
nsmap: dict[str, str] | None = None,
153+
root_ns_only: bool = True,
154+
minimal_ns_only: bool = False,
155+
tree_cls: type[ET.ElementTree] = ...,
156+
) -> str: ...
157+
@overload
158+
def compat_tostring(
159+
element: ET.Element[Any],
160+
encoding: str,
161+
method: Literal["xml", "html", "text"] | None = None,
162+
*,
163+
xml_declaration: bool | None = None,
164+
default_namespace: str | None = None,
165+
short_empty_elements: bool = True,
166+
nsmap: dict[str, str] | None = None,
167+
root_ns_only: bool = True,
168+
minimal_ns_only: bool = False,
169+
tree_cls: type[ET.ElementTree] = ...,
170+
) -> Any: ...
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import types
2+
import xml.etree.ElementTree as ET
3+
from _typeshed import Incomplete
4+
from collections.abc import Generator
5+
from contextlib import contextmanager
6+
from typing import Any
7+
8+
class LxmlSyntaxError(Exception): ...
9+
10+
class _IncrementalFileWriter:
11+
global_nsmap: dict[str, str]
12+
is_html: bool
13+
def __init__(self, output_file: ET._FileWrite) -> None: ...
14+
@contextmanager
15+
def element(
16+
self,
17+
tag: str | ET._ElementCallable,
18+
attrib: dict[str, str] | None = None,
19+
nsmap: dict[str, str] | None = None,
20+
**_extra: str,
21+
) -> Generator[None]: ...
22+
def write(self, arg: str | ET.Element[Any]) -> None: ...
23+
def __enter__(self) -> None: ...
24+
def __exit__(
25+
self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None
26+
) -> None: ...
27+
28+
class xmlfile:
29+
encoding: str
30+
writer_cm: Incomplete
31+
def __init__(
32+
self, output_file: ET._FileWrite, buffered: bool = False, encoding: str = "utf-8", close: bool = False
33+
) -> None: ...
34+
def __enter__(self) -> _IncrementalFileWriter: ...
35+
def __exit__(
36+
self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None
37+
) -> None: ...

0 commit comments

Comments
 (0)