Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major update for the xml module #13349

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 0 additions & 5 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
"stdlib/tkinter/scrolledtext.pyi",
"stdlib/tkinter/tix.pyi",
"stdlib/tkinter/ttk.pyi",
"stdlib/xml/dom/NodeFilter.pyi",
"stdlib/xml/dom/expatbuilder.pyi",
"stdlib/xml/dom/minidom.pyi",
"stdlib/xml/dom/pulldom.pyi",
"stdlib/xml/sax",
"stubs/aiofiles/aiofiles/tempfile/temptypes.pyi",
"stubs/antlr4-python3-runtime",
"stubs/Authlib",
Expand Down
11 changes: 7 additions & 4 deletions stdlib/xml/dom/NodeFilter.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import Literal
from xml.dom.minidom import Node

class NodeFilter:
FILTER_ACCEPT: int
FILTER_REJECT: int
FILTER_SKIP: int
FILTER_ACCEPT: Literal[1]
FILTER_REJECT: Literal[2]
FILTER_SKIP: Literal[3]

SHOW_ALL: int
SHOW_ELEMENT: int
Expand All @@ -16,4 +19,4 @@ class NodeFilter:
SHOW_DOCUMENT_TYPE: int
SHOW_DOCUMENT_FRAGMENT: int
SHOW_NOTATION: int
def acceptNode(self, node) -> int: ...
def acceptNode(self, node: Node) -> int: ...
137 changes: 84 additions & 53 deletions stdlib/xml/dom/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,69 +1,100 @@
from typing import Any, Final
from typing import Any, Final, Literal

from .domreg import getDOMImplementation as getDOMImplementation, registerDOMImplementation as registerDOMImplementation

class Node:
ELEMENT_NODE: int
ATTRIBUTE_NODE: int
TEXT_NODE: int
CDATA_SECTION_NODE: int
ENTITY_REFERENCE_NODE: int
ENTITY_NODE: int
PROCESSING_INSTRUCTION_NODE: int
COMMENT_NODE: int
DOCUMENT_NODE: int
DOCUMENT_TYPE_NODE: int
DOCUMENT_FRAGMENT_NODE: int
NOTATION_NODE: int
ELEMENT_NODE: Literal[1]
ATTRIBUTE_NODE: Literal[2]
TEXT_NODE: Literal[3]
CDATA_SECTION_NODE: Literal[4]
ENTITY_REFERENCE_NODE: Literal[5]
ENTITY_NODE: Literal[6]
PROCESSING_INSTRUCTION_NODE: Literal[7]
COMMENT_NODE: Literal[8]
DOCUMENT_NODE: Literal[9]
DOCUMENT_TYPE_NODE: Literal[10]
DOCUMENT_FRAGMENT_NODE: Literal[11]
NOTATION_NODE: Literal[12]

# ExceptionCode
INDEX_SIZE_ERR: Final[int]
DOMSTRING_SIZE_ERR: Final[int]
HIERARCHY_REQUEST_ERR: Final[int]
WRONG_DOCUMENT_ERR: Final[int]
INVALID_CHARACTER_ERR: Final[int]
NO_DATA_ALLOWED_ERR: Final[int]
NO_MODIFICATION_ALLOWED_ERR: Final[int]
NOT_FOUND_ERR: Final[int]
NOT_SUPPORTED_ERR: Final[int]
INUSE_ATTRIBUTE_ERR: Final[int]
INVALID_STATE_ERR: Final[int]
SYNTAX_ERR: Final[int]
INVALID_MODIFICATION_ERR: Final[int]
NAMESPACE_ERR: Final[int]
INVALID_ACCESS_ERR: Final[int]
VALIDATION_ERR: Final[int]
INDEX_SIZE_ERR: Final = 1
DOMSTRING_SIZE_ERR: Final = 2
HIERARCHY_REQUEST_ERR: Final = 3
WRONG_DOCUMENT_ERR: Final = 4
INVALID_CHARACTER_ERR: Final = 5
NO_DATA_ALLOWED_ERR: Final = 6
NO_MODIFICATION_ALLOWED_ERR: Final = 7
NOT_FOUND_ERR: Final = 8
NOT_SUPPORTED_ERR: Final = 9
INUSE_ATTRIBUTE_ERR: Final = 10
INVALID_STATE_ERR: Final = 11
SYNTAX_ERR: Final = 12
INVALID_MODIFICATION_ERR: Final = 13
NAMESPACE_ERR: Final = 14
INVALID_ACCESS_ERR: Final = 15
VALIDATION_ERR: Final = 16

class DOMException(Exception):
code: int
def __init__(self, *args: Any, **kw: Any) -> None: ...
def _get_code(self) -> int: ...

class IndexSizeErr(DOMException): ...
class DomstringSizeErr(DOMException): ...
class HierarchyRequestErr(DOMException): ...
class WrongDocumentErr(DOMException): ...
class InvalidCharacterErr(DOMException): ...
class NoDataAllowedErr(DOMException): ...
class NoModificationAllowedErr(DOMException): ...
class NotFoundErr(DOMException): ...
class NotSupportedErr(DOMException): ...
class InuseAttributeErr(DOMException): ...
class InvalidStateErr(DOMException): ...
class SyntaxErr(DOMException): ...
class InvalidModificationErr(DOMException): ...
class NamespaceErr(DOMException): ...
class InvalidAccessErr(DOMException): ...
class ValidationErr(DOMException): ...
class IndexSizeErr(DOMException):
code: Literal[1]

class DomstringSizeErr(DOMException):
code: Literal[2]

class HierarchyRequestErr(DOMException):
code: Literal[3]

class WrongDocumentErr(DOMException):
code: Literal[4]

class InvalidCharacterErr(DOMException):
code: Literal[5]

class NoDataAllowedErr(DOMException):
code: Literal[6]

class NoModificationAllowedErr(DOMException):
code: Literal[7]

class NotFoundErr(DOMException):
code: Literal[8]

class NotSupportedErr(DOMException):
code: Literal[9]

class InuseAttributeErr(DOMException):
code: Literal[10]

class InvalidStateErr(DOMException):
code: Literal[11]

class SyntaxErr(DOMException):
code: Literal[12]

class InvalidModificationErr(DOMException):
code: Literal[13]

class NamespaceErr(DOMException):
code: Literal[14]

class InvalidAccessErr(DOMException):
code: Literal[15]

class ValidationErr(DOMException):
code: Literal[16]

class UserDataHandler:
NODE_CLONED: int
NODE_IMPORTED: int
NODE_DELETED: int
NODE_RENAMED: int

XML_NAMESPACE: Final[str]
XMLNS_NAMESPACE: Final[str]
XHTML_NAMESPACE: Final[str]
NODE_CLONED: Literal[1]
NODE_IMPORTED: Literal[2]
NODE_DELETED: Literal[3]
NODE_RENAMED: Literal[4]

XML_NAMESPACE: Final = "http://www.w3.org/XML/1998/namespace"
XMLNS_NAMESPACE: Final = "http://www.w3.org/2000/xmlns/"
XHTML_NAMESPACE: Final = "http://www.w3.org/1999/xhtml"
EMPTY_NAMESPACE: Final[None]
EMPTY_PREFIX: Final[None]
111 changes: 66 additions & 45 deletions stdlib/xml/dom/expatbuilder.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from _typeshed import Incomplete, ReadableBuffer, SupportsRead
from _typeshed import ReadableBuffer, SupportsRead
from typing import Any, NoReturn
from xml.dom.minidom import Document, DOMImplementation, Node, TypeInfo
from typing_extensions import TypeAlias
from xml.dom.minidom import Document, DocumentFragment, DOMImplementation, Element, Node, TypeInfo
from xml.dom.xmlbuilder import DOMBuilderFilter, Options
from xml.parsers.expat import XMLParserType

_Model: TypeAlias = tuple[int, int, str | None, tuple[Any, ...]] # same as in pyexpat

TEXT_NODE = Node.TEXT_NODE
CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE
Expand All @@ -10,45 +14,56 @@ FILTER_ACCEPT = DOMBuilderFilter.FILTER_ACCEPT
FILTER_REJECT = DOMBuilderFilter.FILTER_REJECT
FILTER_SKIP = DOMBuilderFilter.FILTER_SKIP
FILTER_INTERRUPT = DOMBuilderFilter.FILTER_INTERRUPT
theDOMImplementation: DOMImplementation | None
theDOMImplementation: DOMImplementation

class ElementInfo:
tagName: Incomplete
def __init__(self, tagName, model: Incomplete | None = None) -> None: ...
def getAttributeType(self, aname) -> TypeInfo: ...
def getAttributeTypeNS(self, namespaceURI, localName) -> TypeInfo: ...
tagName: str
def __init__(self, tagName: str, model: _Model | None = None) -> None: ...
def getAttributeType(self, aname: str) -> TypeInfo: ...
def getAttributeTypeNS(self, namespaceURI: str | None, localName: str) -> TypeInfo: ...
def isElementContent(self) -> bool: ...
def isEmpty(self) -> bool: ...
def isId(self, aname) -> bool: ...
def isIdNS(self, euri, ename, auri, aname) -> bool: ...
def isId(self, aname: str) -> bool: ...
def isIdNS(self, euri: str, ename: str, auri: str, aname: str) -> bool: ...

class ExpatBuilder:
document: Document # Created in self.reset()
curNode: Incomplete # Created in self.reset()
curNode: DocumentFragment | Element | Document # Created in self.reset()
def __init__(self, options: Options | None = None) -> None: ...
def createParser(self): ...
def getParser(self): ...
def createParser(self) -> XMLParserType: ...
def getParser(self) -> XMLParserType: ...
def reset(self) -> None: ...
def install(self, parser) -> None: ...
def install(self, parser: XMLParserType) -> None: ...
def parseFile(self, file: SupportsRead[ReadableBuffer | str]) -> Document: ...
def parseString(self, string: str | ReadableBuffer) -> Document: ...
def start_doctype_decl_handler(self, doctypeName, systemId, publicId, has_internal_subset) -> None: ...
def start_doctype_decl_handler(
self, doctypeName: str, systemId: str | None, publicId: str | None, has_internal_subset: bool
) -> None: ...
def end_doctype_decl_handler(self) -> None: ...
def pi_handler(self, target, data) -> None: ...
def character_data_handler_cdata(self, data) -> None: ...
def character_data_handler(self, data) -> None: ...
def pi_handler(self, target: str, data: str) -> None: ...
def character_data_handler_cdata(self, data: str) -> None: ...
def character_data_handler(self, data: str) -> None: ...
def start_cdata_section_handler(self) -> None: ...
def end_cdata_section_handler(self) -> None: ...
def entity_decl_handler(self, entityName, is_parameter_entity, value, base, systemId, publicId, notationName) -> None: ...
def notation_decl_handler(self, notationName, base, systemId, publicId) -> None: ...
def comment_handler(self, data) -> None: ...
def external_entity_ref_handler(self, context, base, systemId, publicId) -> int: ...
def first_element_handler(self, name, attributes) -> None: ...
def start_element_handler(self, name, attributes) -> None: ...
def end_element_handler(self, name) -> None: ...
def element_decl_handler(self, name, model) -> None: ...
def attlist_decl_handler(self, elem, name, type, default, required) -> None: ...
def xml_decl_handler(self, version, encoding, standalone) -> None: ...
def entity_decl_handler(
self,
entityName: str,
is_parameter_entity: bool,
value: str | None,
base: str | None,
systemId: str,
publicId: str | None,
notationName: str | None,
) -> None: ...
def notation_decl_handler(self, notationName: str, base: str | None, systemId: str, publicId: str | None) -> None: ...
def comment_handler(self, data: str) -> None: ...
def external_entity_ref_handler(self, context: str, base: str | None, systemId: str | None, publicId: str | None) -> int: ...
def first_element_handler(self, name: str, attributes: list[str]) -> None: ...
def start_element_handler(self, name: str, attributes: list[str]) -> None: ...
def end_element_handler(self, name: str) -> None: ...
def element_decl_handler(self, name: str, model: _Model) -> None: ...
def attlist_decl_handler(self, elem: str, name: str, type: str, default: str | None, required: bool) -> None: ...
def xml_decl_handler(self, version: str, encoding: str | None, standalone: int) -> None: ...

class FilterVisibilityController:
filter: DOMBuilderFilter
Expand All @@ -57,7 +72,7 @@ class FilterVisibilityController:
def acceptNode(self, node: Node) -> int: ...

class FilterCrutch:
def __init__(self, builder) -> None: ...
def __init__(self, builder: ExpatBuilder) -> None: ...

class Rejecter(FilterCrutch):
def start_element_handler(self, *args: Any) -> None: ...
Expand All @@ -68,33 +83,39 @@ class Skipper(FilterCrutch):
def end_element_handler(self, *args: Any) -> None: ...

class FragmentBuilder(ExpatBuilder):
fragment: Incomplete | None
originalDocument: Incomplete
context: Incomplete
def __init__(self, context, options: Options | None = None) -> None: ...
fragment: DocumentFragment | None
originalDocument: Document
context: Node
def __init__(self, context: Node, options: Options | None = None) -> None: ...
def reset(self) -> None: ...
def parseFile(self, file: SupportsRead[ReadableBuffer | str]) -> DocumentFragment: ... # type: ignore[override]
def parseString(self, string: ReadableBuffer | str) -> DocumentFragment: ... # type: ignore[override]
def external_entity_ref_handler(self, context: str, base: str | None, systemId: str | None, publicId: str | None) -> int: ...

class Namespaces:
def createParser(self): ...
def install(self, parser) -> None: ...
def start_namespace_decl_handler(self, prefix, uri) -> None: ...
def start_element_handler(self, name, attributes) -> None: ...
def end_element_handler(self, name) -> None: ...
def createParser(self) -> XMLParserType: ...
def install(self, parser: XMLParserType) -> None: ...
def start_namespace_decl_handler(self, prefix: str | None, uri: str) -> None: ...
def start_element_handler(self, name: str, attributes: list[str]) -> None: ...
def end_element_handler(self, name: str) -> None: ... # only exists if __debug__

class ExpatBuilderNS(Namespaces, ExpatBuilder): ...
class FragmentBuilderNS(Namespaces, FragmentBuilder): ...
class ParseEscape(Exception): ...

class InternalSubsetExtractor(ExpatBuilder):
subset: Any | None
def getSubset(self) -> Any | None: ...
subset: str | list[str] | None = None
def getSubset(self) -> str: ...
def parseFile(self, file: SupportsRead[ReadableBuffer | str]) -> None: ... # type: ignore[override]
def parseString(self, string: str | ReadableBuffer) -> None: ... # type: ignore[override]
def start_doctype_decl_handler(self, name, publicId, systemId, has_internal_subset) -> None: ... # type: ignore[override]
def start_doctype_decl_handler( # type: ignore[override]
self, name: str, publicId: str | None, systemId: str | None, has_internal_subset: bool
) -> None: ...
def end_doctype_decl_handler(self) -> NoReturn: ...
def start_element_handler(self, name, attrs) -> NoReturn: ...
def start_element_handler(self, name: str, attrs: list[str]) -> NoReturn: ...

def parse(file: str | SupportsRead[ReadableBuffer | str], namespaces: bool = True): ...
def parseString(string: str | ReadableBuffer, namespaces: bool = True): ...
def parseFragment(file, context, namespaces: bool = True): ...
def parseFragmentString(string: str, context, namespaces: bool = True): ...
def parse(file: str | SupportsRead[ReadableBuffer | str], namespaces: bool = True) -> Document: ...
def parseString(string: str | ReadableBuffer, namespaces: bool = True) -> Document: ...
def parseFragment(file: str | SupportsRead[ReadableBuffer | str], context: Node, namespaces: bool = True) -> DocumentFragment: ...
def parseFragmentString(string: str | ReadableBuffer, context: Node, namespaces: bool = True) -> DocumentFragment: ...
def makeBuilder(options: Options) -> ExpatBuilderNS | ExpatBuilder: ...
Loading
Loading