|
1 |
| -from typing import Any |
| 1 | +from typing import Any, NoReturn, Optional |
| 2 | +from typing_extensions import Literal |
| 3 | +from urllib.request import OpenerDirector |
| 4 | +from xml.dom.expatbuilder import ExpatBuilder, ExpatBuilderNS |
| 5 | +from xml.dom.minidom import Node |
2 | 6 |
|
3 |
| -def __getattr__(name: str) -> Any: ... # incomplete |
| 7 | +# UNKNOWN TYPES: |
| 8 | +# - `Options.errorHandler`. |
| 9 | +# The same as `_DOMBuilderErrorHandlerType`? |
| 10 | +# Maybe `xml.sax.handler.ErrorHandler`? |
| 11 | +# - Return type of DOMBuilder.getFeature(). |
| 12 | +# We could get rid of the `Any` if we knew more |
| 13 | +# about `Options.errorHandler`. |
4 | 14 |
|
5 |
| -class DocumentLS(Any): ... |
6 |
| -class DOMImplementationLS(Any): ... |
| 15 | +# ALIASES REPRESENTING MORE UNKNOWN TYPES: |
| 16 | + |
| 17 | +# probably the same as `Options.errorHandler`? |
| 18 | +# Maybe `xml.sax.handler.ErrorHandler`? |
| 19 | +_DOMBuilderErrorHandlerType = Optional[Any] |
| 20 | +# probably some kind of IO... |
| 21 | +_DOMInputSourceCharacterStreamType = Optional[Any] |
| 22 | +# probably a string?? |
| 23 | +_DOMInputSourceStringDataType = Optional[Any] |
| 24 | +# probably a string?? |
| 25 | +_DOMInputSourceEncodingType = Optional[Any] |
| 26 | + |
| 27 | +class Options: |
| 28 | + namespaces: int |
| 29 | + namespace_declarations: bool |
| 30 | + validation: bool |
| 31 | + external_parameter_entities: bool |
| 32 | + external_general_entities: bool |
| 33 | + external_dtd_subset: bool |
| 34 | + validate_if_schema: bool |
| 35 | + validate: bool |
| 36 | + datatype_normalization: bool |
| 37 | + create_entity_ref_nodes: bool |
| 38 | + entities: bool |
| 39 | + whitespace_in_element_content: bool |
| 40 | + cdata_sections: bool |
| 41 | + comments: bool |
| 42 | + charset_overrides_xml_encoding: bool |
| 43 | + infoset: bool |
| 44 | + supported_mediatypes_only: bool |
| 45 | + errorHandler: Any | None |
| 46 | + filter: DOMBuilderFilter | None # a guess, but seems likely |
| 47 | + |
| 48 | +class DOMBuilder: |
| 49 | + entityResolver: DOMEntityResolver | None # a guess, but seems likely |
| 50 | + errorHandler: _DOMBuilderErrorHandlerType |
| 51 | + filter: DOMBuilderFilter | None # a guess, but seems likely |
| 52 | + ACTION_REPLACE: Literal[1] |
| 53 | + ACTION_APPEND_AS_CHILDREN: Literal[2] |
| 54 | + ACTION_INSERT_AFTER: Literal[3] |
| 55 | + ACTION_INSERT_BEFORE: Literal[4] |
| 56 | + def __init__(self) -> None: ... |
| 57 | + def setFeature(self, name: str, state: int) -> None: ... |
| 58 | + def supportsFeature(self, name: str) -> bool: ... |
| 59 | + def canSetFeature(self, name: str, state: int) -> bool: ... |
| 60 | + # getFeature could return any attribute from an instance of `Options` |
| 61 | + def getFeature(self, name: str) -> Any: ... |
| 62 | + def parseURI(self, uri: str) -> ExpatBuilder | ExpatBuilderNS: ... |
| 63 | + def parse(self, input: DOMInputSource) -> ExpatBuilder | ExpatBuilderNS: ... |
| 64 | + # `input` and `cnode` argtypes for `parseWithContext` are unknowable |
| 65 | + # as the function does nothing with them, and always raises an exception. |
| 66 | + # But `input` is *probably* `DOMInputSource`? |
| 67 | + def parseWithContext(self, input: object, cnode: object, action: Literal[1, 2, 3, 4]) -> NoReturn: ... |
| 68 | + |
| 69 | +class DOMEntityResolver: |
| 70 | + def resolveEntity(self, publicId: str | None, systemId: str) -> DOMInputSource: ... |
| 71 | + |
| 72 | +class DOMInputSource: |
| 73 | + byteStream: OpenerDirector | None |
| 74 | + characterStream: _DOMInputSourceCharacterStreamType |
| 75 | + stringData: _DOMInputSourceStringDataType |
| 76 | + encoding: _DOMInputSourceEncodingType |
| 77 | + publicId: str | None |
| 78 | + systemId: str | None |
| 79 | + baseURI: str | None |
| 80 | + |
| 81 | +class DOMBuilderFilter: |
| 82 | + FILTER_ACCEPT: Literal[1] |
| 83 | + FILTER_REJECT: Literal[2] |
| 84 | + FILTER_SKIP: Literal[3] |
| 85 | + FILTER_INTERRUPT: Literal[4] |
| 86 | + whatToShow: int |
| 87 | + # The argtypes for acceptNode and startContainer appear to be irrelevant. |
| 88 | + def acceptNode(self, element: object) -> Literal[1]: ... |
| 89 | + def startContainer(self, element: object) -> Literal[1]: ... |
| 90 | + |
| 91 | +class DocumentLS: |
| 92 | + async_: bool |
| 93 | + def abort(self) -> NoReturn: ... |
| 94 | + # `load()` and `loadXML()` always raise exceptions |
| 95 | + # so the argtypes of `uri` and `source` are unknowable. |
| 96 | + # `source` is *probably* `DOMInputSource`? |
| 97 | + # `uri` is *probably* a str? (see DOMBuilder.parseURI()) |
| 98 | + def load(self, uri: object) -> NoReturn: ... |
| 99 | + def loadXML(self, source: object) -> NoReturn: ... |
| 100 | + def saveXML(self, snode: Node | None) -> str: ... |
| 101 | + |
| 102 | +class DOMImplementationLS: |
| 103 | + MODE_SYNCHRONOUS: Literal[1] |
| 104 | + MODE_ASYNCHRONOUS: Literal[2] |
| 105 | + def createDOMBuilder(self, mode: Literal[1], schemaType: None) -> DOMBuilder: ... |
| 106 | + def createDOMWriter(self) -> NoReturn: ... |
| 107 | + def createDOMInputSource(self) -> DOMInputSource: ... |
0 commit comments