-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathElementTree.pyi
319 lines (295 loc) · 12.1 KB
/
ElementTree.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import sys
from _typeshed import FileDescriptor, StrOrBytesPath, SupportsWrite
from typing import (
IO,
Any,
Callable,
Generator,
ItemsView,
Iterable,
Iterator,
KeysView,
Mapping,
MutableSequence,
Sequence,
TypeVar,
Union,
overload,
)
from typing_extensions import Literal, SupportsIndex
_T = TypeVar("_T")
_File = Union[StrOrBytesPath, FileDescriptor, IO[Any]]
VERSION: str
class ParseError(SyntaxError):
code: int
position: tuple[int, int]
def iselement(element: object) -> bool: ...
if sys.version_info >= (3, 8):
@overload
def canonicalize(
xml_data: str | bytes | None = ...,
*,
out: None = ...,
from_file: _File | None = ...,
with_comments: bool = ...,
strip_text: bool = ...,
rewrite_prefixes: bool = ...,
qname_aware_tags: Iterable[str] | None = ...,
qname_aware_attrs: Iterable[str] | None = ...,
exclude_attrs: Iterable[str] | None = ...,
exclude_tags: Iterable[str] | None = ...,
) -> str: ...
@overload
def canonicalize(
xml_data: str | bytes | None = ...,
*,
out: SupportsWrite[str],
from_file: _File | None = ...,
with_comments: bool = ...,
strip_text: bool = ...,
rewrite_prefixes: bool = ...,
qname_aware_tags: Iterable[str] | None = ...,
qname_aware_attrs: Iterable[str] | None = ...,
exclude_attrs: Iterable[str] | None = ...,
exclude_tags: Iterable[str] | None = ...,
) -> None: ...
class Element(MutableSequence[Element]):
tag: str
attrib: dict[str, str]
text: str | None
tail: str | None
def __init__(self, tag: str | Callable[..., Element], attrib: dict[str, str] = ..., **extra: str) -> None: ...
def append(self, __subelement: Element) -> None: ...
def clear(self) -> None: ...
def extend(self, __elements: Iterable[Element]) -> None: ...
def find(self, path: str, namespaces: dict[str, str] | None = ...) -> Element | None: ...
def findall(self, path: str, namespaces: dict[str, str] | None = ...) -> list[Element]: ...
@overload
def findtext(self, path: str, default: None = ..., namespaces: dict[str, str] | None = ...) -> str | None: ...
@overload
def findtext(self, path: str, default: _T, namespaces: dict[str, str] | None = ...) -> _T | str: ...
@overload
def get(self, key: str, default: None = ...) -> str | None: ...
@overload
def get(self, key: str, default: _T) -> str | _T: ...
def insert(self, __index: int, __subelement: Element) -> None: ...
def items(self) -> ItemsView[str, str]: ...
def iter(self, tag: str | None = ...) -> Generator[Element, None, None]: ...
def iterfind(self, path: str, namespaces: dict[str, str] | None = ...) -> Generator[Element, None, None]: ...
def itertext(self) -> Generator[str, None, None]: ...
def keys(self) -> KeysView[str]: ...
def makeelement(self, __tag: str, __attrib: dict[str, str]) -> Element: ...
def remove(self, __subelement: Element) -> None: ...
def set(self, __key: str, __value: str) -> None: ...
def __delitem__(self, i: SupportsIndex | slice) -> None: ...
@overload
def __getitem__(self, i: SupportsIndex) -> Element: ...
@overload
def __getitem__(self, s: slice) -> MutableSequence[Element]: ...
def __len__(self) -> int: ...
@overload
def __setitem__(self, i: SupportsIndex, o: Element) -> None: ...
@overload
def __setitem__(self, s: slice, o: Iterable[Element]) -> None: ...
if sys.version_info < (3, 9):
def getchildren(self) -> list[Element]: ...
def getiterator(self, tag: str | None = ...) -> list[Element]: ...
def SubElement(parent: Element, tag: str, attrib: dict[str, str] = ..., **extra: str) -> Element: ...
def Comment(text: str | None = ...) -> Element: ...
def ProcessingInstruction(target: str, text: str | None = ...) -> Element: ...
PI: Callable[..., Element]
class QName:
text: str
def __init__(self, text_or_uri: str, tag: str | None = ...) -> None: ...
class ElementTree:
def __init__(self, element: Element | None = ..., file: _File | None = ...) -> None: ...
def getroot(self) -> Element: ...
def parse(self, source: _File, parser: XMLParser | None = ...) -> Element: ...
def iter(self, tag: str | None = ...) -> Generator[Element, None, None]: ...
if sys.version_info < (3, 9):
def getiterator(self, tag: str | None = ...) -> list[Element]: ...
def find(self, path: str, namespaces: dict[str, str] | None = ...) -> Element | None: ...
@overload
def findtext(self, path: str, default: None = ..., namespaces: dict[str, str] | None = ...) -> str | None: ...
@overload
def findtext(self, path: str, default: _T, namespaces: dict[str, str] | None = ...) -> _T | str: ...
def findall(self, path: str, namespaces: dict[str, str] | None = ...) -> list[Element]: ...
def iterfind(self, path: str, namespaces: dict[str, str] | None = ...) -> Generator[Element, None, None]: ...
def write(
self,
file_or_filename: _File,
encoding: str | None = ...,
xml_declaration: bool | None = ...,
default_namespace: str | None = ...,
method: str | None = ...,
*,
short_empty_elements: bool = ...,
) -> None: ...
def write_c14n(self, file: _File) -> None: ...
def register_namespace(prefix: str, uri: str) -> None: ...
if sys.version_info >= (3, 8):
@overload
def tostring(
element: Element,
encoding: None = ...,
method: str | None = ...,
*,
xml_declaration: bool | None = ...,
default_namespace: str | None = ...,
short_empty_elements: bool = ...,
) -> bytes: ...
@overload
def tostring(
element: Element,
encoding: Literal["unicode"],
method: str | None = ...,
*,
xml_declaration: bool | None = ...,
default_namespace: str | None = ...,
short_empty_elements: bool = ...,
) -> str: ...
@overload
def tostring(
element: Element,
encoding: str,
method: str | None = ...,
*,
xml_declaration: bool | None = ...,
default_namespace: str | None = ...,
short_empty_elements: bool = ...,
) -> Any: ...
@overload
def tostringlist(
element: Element,
encoding: None = ...,
method: str | None = ...,
*,
xml_declaration: bool | None = ...,
default_namespace: str | None = ...,
short_empty_elements: bool = ...,
) -> list[bytes]: ...
@overload
def tostringlist(
element: Element,
encoding: Literal["unicode"],
method: str | None = ...,
*,
xml_declaration: bool | None = ...,
default_namespace: str | None = ...,
short_empty_elements: bool = ...,
) -> list[str]: ...
@overload
def tostringlist(
element: Element,
encoding: str,
method: str | None = ...,
*,
xml_declaration: bool | None = ...,
default_namespace: str | None = ...,
short_empty_elements: bool = ...,
) -> list[Any]: ...
else:
@overload
def tostring(
element: Element, encoding: None = ..., method: str | None = ..., *, short_empty_elements: bool = ...
) -> bytes: ...
@overload
def tostring(
element: Element, encoding: Literal["unicode"], method: str | None = ..., *, short_empty_elements: bool = ...
) -> str: ...
@overload
def tostring(element: Element, encoding: str, method: str | None = ..., *, short_empty_elements: bool = ...) -> Any: ...
@overload
def tostringlist(
element: Element, encoding: None = ..., method: str | None = ..., *, short_empty_elements: bool = ...
) -> list[bytes]: ...
@overload
def tostringlist(
element: Element, encoding: Literal["unicode"], method: str | None = ..., *, short_empty_elements: bool = ...
) -> list[str]: ...
@overload
def tostringlist(
element: Element, encoding: str, method: str | None = ..., *, short_empty_elements: bool = ...
) -> list[Any]: ...
def dump(elem: Element) -> None: ...
if sys.version_info >= (3, 9):
def indent(tree: Element | ElementTree, space: str = ..., level: int = ...) -> None: ...
def parse(source: _File, parser: XMLParser | None = ...) -> ElementTree: ...
def iterparse(source: _File, events: Sequence[str] | None = ..., parser: XMLParser | None = ...) -> Iterator[tuple[str, Any]]: ...
class XMLPullParser:
def __init__(self, events: Sequence[str] | None = ..., *, _parser: XMLParser | None = ...) -> None: ...
def feed(self, data: bytes) -> None: ...
def close(self) -> None: ...
def read_events(self) -> Iterator[tuple[str, Element]]: ...
def XML(text: str | bytes, parser: XMLParser | None = ...) -> Element: ...
def XMLID(text: str | bytes, parser: XMLParser | None = ...) -> tuple[Element, dict[str, Element]]: ...
# This is aliased to XML in the source.
fromstring = XML
def fromstringlist(sequence: Sequence[str | bytes], parser: XMLParser | None = ...) -> Element: ...
# This type is both not precise enough and too precise. The TreeBuilder
# requires the elementfactory to accept tag and attrs in its args and produce
# some kind of object that has .text and .tail properties.
# I've chosen to constrain the ElementFactory to always produce an Element
# because that is how almost everyone will use it.
# Unfortunately, the type of the factory arguments is dependent on how
# TreeBuilder is called by client code (they could pass strs, bytes or whatever);
# but we don't want to use a too-broad type, or it would be too hard to write
# elementfactories.
_ElementFactory = Callable[[Any, dict[Any, Any]], Element]
class TreeBuilder:
if sys.version_info >= (3, 8):
# comment_factory can take None because passing None to Comment is not an error
def __init__(
self,
element_factory: _ElementFactory | None = ...,
*,
comment_factory: Callable[[str | None], Element] | None = ...,
pi_factory: Callable[[str, str | None], Element] | None = ...,
insert_comments: bool = ...,
insert_pis: bool = ...,
) -> None: ...
insert_comments: bool
insert_pis: bool
else:
def __init__(self, element_factory: _ElementFactory | None = ...) -> None: ...
def close(self) -> Element: ...
def data(self, __data: str | bytes) -> None: ...
def start(self, __tag: str | bytes, __attrs: dict[str | bytes, str | bytes]) -> Element: ...
def end(self, __tag: str | bytes) -> Element: ...
if sys.version_info >= (3, 8):
# These two methods have pos-only parameters in the C implementation
def comment(self, __text: str | None) -> Element: ...
def pi(self, __target: str, __text: str | None = ...) -> Element: ...
if sys.version_info >= (3, 8):
class C14NWriterTarget:
def __init__(
self,
write: Callable[[str], Any],
*,
with_comments: bool = ...,
strip_text: bool = ...,
rewrite_prefixes: bool = ...,
qname_aware_tags: Iterable[str] | None = ...,
qname_aware_attrs: Iterable[str] | None = ...,
exclude_attrs: Iterable[str] | None = ...,
exclude_tags: Iterable[str] | None = ...,
) -> None: ...
def data(self, data: str) -> None: ...
def start_ns(self, prefix: str, uri: str) -> None: ...
def start(self, tag: str, attrs: Mapping[str, str]) -> None: ...
def end(self, tag: str) -> None: ...
def comment(self, text: str) -> None: ...
def pi(self, target: str, data: str) -> None: ...
class XMLParser:
parser: Any
target: Any
# TODO-what is entity used for???
entity: Any
version: str
if sys.version_info >= (3, 8):
def __init__(self, *, target: Any = ..., encoding: str | None = ...) -> None: ...
else:
def __init__(self, html: int = ..., target: Any = ..., encoding: str | None = ...) -> None: ...
def doctype(self, __name: str, __pubid: str, __system: str) -> None: ...
def close(self) -> Any: ...
def feed(self, __data: str | bytes) -> None: ...