massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / coc-python-data / languageServer.0.5.59 / Typeshed / stdlib / 2and3 / xml / etree / ElementTree.pyi
1 # Stubs for xml.etree.ElementTree\r
2 \r
3 from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iterator, KeysView, List, MutableSequence, Optional, overload, Sequence, Text, Tuple, TypeVar, Union\r
4 import io\r
5 import sys\r
6 \r
7 VERSION = ...  # type: str\r
8 \r
9 class ParseError(SyntaxError): ...\r
10 \r
11 def iselement(element: 'Element') -> bool: ...\r
12 \r
13 _T = TypeVar('_T')\r
14 \r
15 # Type for parser inputs. Parser will accept any unicode/str/bytes and coerce,\r
16 # and this is true in py2 and py3 (even fromstringlist() in python3 can be\r
17 # called with a heterogeneous list)\r
18 _parser_input_type = Union[bytes, Text]\r
19 \r
20 # Type for individual tag/attr/ns/text values in args to most functions.\r
21 # In py2, the library accepts str or unicode everywhere and coerces\r
22 # aggressively.\r
23 # In py3, bytes is not coerced to str and so use of bytes is probably an error,\r
24 # so we exclude it. (why? the parser never produces bytes when it parses XML,\r
25 # so e.g., element.get(b'name') will always return None for parsed XML, even if\r
26 # there is a 'name' attribute.)\r
27 _str_argument_type = Union[str, Text]\r
28 \r
29 # Type for return values from individual tag/attr/text values and serialization\r
30 if sys.version_info >= (3,):\r
31     # note: in python3, everything comes out as str, yay:\r
32     _str_result_type = str\r
33     # unfortunately, tostring and tostringlist can return either bytes or str\r
34     # depending on the value of `encoding` parameter. Client code knows best:\r
35     _tostring_result_type = Any\r
36 else:\r
37     # in python2, if the tag/attribute/text wasn't decode-able as ascii, it\r
38     # comes out as a unicode string; otherwise it comes out as str. (see\r
39     # _fixtext function in the source). Client code knows best:\r
40     _str_result_type = Any\r
41     # On the bright side, tostring and tostringlist always return bytes:\r
42     _tostring_result_type = bytes\r
43 \r
44 class Element(MutableSequence['Element']):\r
45     tag = ...  # type: _str_result_type\r
46     attrib = ...  # type: Dict[_str_result_type, _str_result_type]\r
47     text = ...  # type: Optional[_str_result_type]\r
48     tail = ...  # type: Optional[_str_result_type]\r
49     def __init__(self, tag: Union[_str_argument_type, Callable[..., 'Element']], attrib: Dict[_str_argument_type, _str_argument_type]=..., **extra: _str_argument_type) -> None: ...\r
50     def append(self, subelement: 'Element') -> None: ...\r
51     def clear(self) -> None: ...\r
52     def copy(self) -> 'Element': ...\r
53     def extend(self, elements: Iterable['Element']) -> None: ...\r
54     def find(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> Optional['Element']: ...\r
55     def findall(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> List['Element']: ...\r
56     def findtext(self, path: _str_argument_type, default: _T=..., namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> Union[_T, _str_result_type]: ...\r
57     def get(self, key: _str_argument_type, default: _T=...) -> Union[_str_result_type, _T]: ...\r
58     def getchildren(self) -> List['Element']: ...\r
59     def getiterator(self, tag: _str_argument_type=...) -> List['Element']: ...\r
60     if sys.version_info >= (3, 2):\r
61         def insert(self, index: int, subelement: 'Element') -> None: ...\r
62     else:\r
63         def insert(self, index: int, element: 'Element') -> None: ...\r
64     def items(self) -> ItemsView[_str_result_type, _str_result_type]: ...\r
65     def iter(self, tag: _str_argument_type=...) -> Generator['Element', None, None]: ...\r
66     def iterfind(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> List['Element']: ...\r
67     def itertext(self) -> Generator[_str_result_type, None, None]: ...\r
68     def keys(self) -> KeysView[_str_result_type]: ...\r
69     def makeelement(self, tag: _str_argument_type, attrib: Dict[_str_argument_type, _str_argument_type]) -> 'Element': ...\r
70     def remove(self, subelement: 'Element') -> None: ...\r
71     def set(self, key: _str_argument_type, value: _str_argument_type) -> None: ...\r
72     def __bool__(self) -> bool: ...\r
73     def __delitem__(self, i: Union[int, slice]) -> None: ...\r
74     @overload\r
75     def __getitem__(self, i: int) -> 'Element': ...\r
76     @overload\r
77     def __getitem__(self, s: slice) -> Sequence['Element']: ...\r
78     def __len__(self) -> int: ...\r
79     @overload\r
80     def __setitem__(self, i: int, o: 'Element') -> None: ...\r
81     @overload\r
82     def __setitem__(self, s: slice, o: Iterable['Element']) -> None: ...\r
83 \r
84 \r
85 def SubElement(parent: Element, tag: _str_argument_type, attrib: Dict[_str_argument_type, _str_argument_type]=..., **extra: _str_argument_type) -> Element: ...\r
86 def Comment(text: _str_argument_type=...) -> Element: ...\r
87 def ProcessingInstruction(target: _str_argument_type, text: _str_argument_type=...) -> Element: ...\r
88 \r
89 PI = ...  # type: Callable[..., Element]\r
90 \r
91 class QName:\r
92     text = ...  # type: str\r
93     def __init__(self, text_or_uri: _str_argument_type, tag: _str_argument_type=...) -> None: ...\r
94 \r
95 \r
96 _file_or_filename = Union[str, bytes, int, IO[Any]]\r
97 \r
98 class ElementTree:\r
99     def __init__(self, element: Element=..., file: _file_or_filename=...) -> None: ...\r
100     def getroot(self) -> Element: ...\r
101     def parse(self, source: _file_or_filename, parser: 'XMLParser'=...) -> Element: ...\r
102     def iter(self, tag: _str_argument_type=...) -> Generator[Element, None, None]: ...\r
103     def getiterator(self, tag: _str_argument_type=...) -> List[Element]: ...\r
104     def find(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> Optional[Element]: ...\r
105     def findtext(self, path: _str_argument_type, default: _T=..., namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> Union[_T, _str_result_type]: ...\r
106     def findall(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> List[Element]: ...\r
107     def iterfind(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> List[Element]: ...\r
108     if sys.version_info >= (3, 4):\r
109         def write(self, file_or_filename: _file_or_filename, encoding: str=..., xml_declaration: Optional[bool]=..., default_namespace: _str_argument_type=..., method: str=..., *, short_empty_elements: bool=...) -> None: ...\r
110     else:\r
111         def write(self, file_or_filename: _file_or_filename, encoding: str=..., xml_declaration: Optional[bool]=..., default_namespace: _str_argument_type=..., method: str=...) -> None: ...\r
112     def write_c14n(self, file: _file_or_filename) -> None: ...\r
113 \r
114 def register_namespace(prefix: _str_argument_type, uri: _str_argument_type) -> None: ...\r
115 if sys.version_info >= (3, 4):\r
116     def tostring(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> _tostring_result_type: ...\r
117     def tostringlist(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> List[_tostring_result_type]: ...\r
118 else:\r
119     def tostring(element: Element, encoding: str=..., method: str=...) -> _tostring_result_type: ...\r
120     def tostringlist(element: Element, encoding: str=..., method: str=...) -> List[_tostring_result_type]: ...\r
121 def dump(elem: Element) -> None: ...\r
122 def parse(source: _file_or_filename, parser: 'XMLParser'=...) -> ElementTree: ...\r
123 def iterparse(source: _file_or_filename, events: Sequence[str]=..., parser: 'XMLParser'=...) -> Iterator[Tuple[str, Any]]: ...\r
124 \r
125 if sys.version_info >= (3, 4):\r
126     class XMLPullParser:\r
127         def __init__(self, events: Sequence[str]=..., *, _parser: 'XMLParser'=...) -> None: ...\r
128         def feed(self, data: bytes) -> None: ...\r
129         def close(self) -> None: ...\r
130         def read_events(self) -> Iterator[Tuple[str, Element]]: ...\r
131 \r
132 def XML(text: _parser_input_type, parser: 'XMLParser'=...) -> Element: ...\r
133 def XMLID(text: _parser_input_type, parser: 'XMLParser'=...) -> Tuple[Element, Dict[_str_result_type, Element]]: ...\r
134 \r
135 # This is aliased to XML in the source.\r
136 fromstring = XML\r
137 \r
138 def fromstringlist(sequence: Sequence[_parser_input_type], parser: 'XMLParser'=...) -> Element: ...\r
139 \r
140 # This type is both not precise enough and too precise. The TreeBuilder\r
141 # requires the elementfactory to accept tag and attrs in its args and produce\r
142 # some kind of object that has .text and .tail properties.\r
143 # I've chosen to constrain the ElementFactory to always produce an Element\r
144 # because that is how almost everyone will use it.\r
145 # Unfortunately, the type of the factory arguments is dependent on how\r
146 # TreeBuilder is called by client code (they could pass strs, bytes or whatever);\r
147 # but we don't want to use a too-broad type, or it would be too hard to write\r
148 # elementfactories.\r
149 _ElementFactory = Callable[[Any, Dict[Any, Any]], Element]\r
150 \r
151 class TreeBuilder:\r
152     def __init__(self, element_factory: _ElementFactory=...) -> None: ...\r
153     def close(self) -> Element: ...\r
154     def data(self, data: _parser_input_type) -> None: ...\r
155     def start(self, tag: _parser_input_type, attrs: Dict[_parser_input_type, _parser_input_type]) -> Element: ...\r
156     def end(self, tag: _parser_input_type) -> Element: ...\r
157 \r
158 class XMLParser:\r
159     parser = ...  # type: Any\r
160     target = ...  # type: TreeBuilder\r
161     # TODO-what is entity used for???\r
162     entity = ...  # type: Any\r
163     version = ...  # type: str\r
164     def __init__(self, html: int=..., target: TreeBuilder=..., encoding: str=...) -> None: ...\r
165     def doctype(self, name: str, pubid: str, system: str) -> None: ...\r
166     def close(self) -> Element: ...\r
167     def feed(self, data: _parser_input_type) -> None: ...\r