Major update for the xml module (#13349)

This commit is contained in:
Stephen Morton
2025-02-27 03:50:09 -08:00
committed by GitHub
parent 0647903db3
commit 40dc55c4be
15 changed files with 1029 additions and 581 deletions
+5 -5
View File
@@ -4,15 +4,15 @@ from xml.sax.xmlreader import Locator
class SAXException(Exception):
def __init__(self, msg: str, exception: Exception | None = None) -> None: ...
def getMessage(self) -> str: ...
def getException(self) -> Exception: ...
def getException(self) -> Exception | None: ...
def __getitem__(self, ix: object) -> NoReturn: ...
class SAXParseException(SAXException):
def __init__(self, msg: str, exception: Exception | None, locator: Locator) -> None: ...
def getColumnNumber(self) -> int: ...
def getLineNumber(self) -> int: ...
def getPublicId(self): ...
def getSystemId(self): ...
def getColumnNumber(self) -> int | None: ...
def getLineNumber(self) -> int | None: ...
def getPublicId(self) -> str | None: ...
def getSystemId(self) -> str | None: ...
class SAXNotRecognizedException(SAXException): ...
class SAXNotSupportedException(SAXException): ...
+53 -24
View File
@@ -1,53 +1,82 @@
import sys
from _typeshed import Unused
from xml.sax import xmlreader
from _typeshed import ReadableBuffer
from collections.abc import Mapping
from typing import Any, Literal, overload
from typing_extensions import TypeAlias
from xml.sax import _Source, xmlreader
from xml.sax.handler import _ContentHandlerProtocol
if sys.version_info >= (3, 10):
from xml.sax.handler import LexicalHandler
_BoolType: TypeAlias = Literal[0, 1] | bool
version: str
AttributesImpl = xmlreader.AttributesImpl
AttributesNSImpl = xmlreader.AttributesNSImpl
class _ClosedParser: ...
class _ClosedParser:
ErrorColumnNumber: int
ErrorLineNumber: int
class ExpatLocator(xmlreader.Locator):
def __init__(self, parser: ExpatParser) -> None: ...
def getColumnNumber(self) -> int: ...
def getColumnNumber(self) -> int | None: ...
def getLineNumber(self) -> int: ...
def getPublicId(self): ...
def getSystemId(self): ...
def getPublicId(self) -> str | None: ...
def getSystemId(self) -> str | None: ...
class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
def __init__(self, namespaceHandling: int = 0, bufsize: int = 65516) -> None: ...
def parse(self, source) -> None: ...
def prepareParser(self, source) -> None: ...
def setContentHandler(self, handler) -> None: ...
def getFeature(self, name: str): ...
def setFeature(self, name: str, state) -> None: ...
def getProperty(self, name: str): ...
def setProperty(self, name: str, value) -> None: ...
def __init__(self, namespaceHandling: _BoolType = 0, bufsize: int = 65516) -> None: ...
def parse(self, source: xmlreader.InputSource | _Source) -> None: ...
def prepareParser(self, source: xmlreader.InputSource) -> None: ...
def setContentHandler(self, handler: _ContentHandlerProtocol) -> None: ...
def getFeature(self, name: str) -> _BoolType: ...
def setFeature(self, name: str, state: _BoolType) -> None: ...
if sys.version_info >= (3, 10):
@overload
def getProperty(self, name: Literal["http://xml.org/sax/properties/lexical-handler"]) -> LexicalHandler | None: ...
@overload
def getProperty(self, name: Literal["http://www.python.org/sax/properties/interning-dict"]) -> dict[str, Any] | None: ...
@overload
def getProperty(self, name: Literal["http://xml.org/sax/properties/xml-string"]) -> bytes | None: ...
@overload
def getProperty(self, name: str) -> object: ...
if sys.version_info >= (3, 10):
@overload
def setProperty(self, name: Literal["http://xml.org/sax/properties/lexical-handler"], value: LexicalHandler) -> None: ...
@overload
def setProperty(
self, name: Literal["http://www.python.org/sax/properties/interning-dict"], value: dict[str, Any]
) -> None: ...
@overload
def setProperty(self, name: str, value: object) -> None: ...
if sys.version_info >= (3, 9):
def feed(self, data, isFinal: bool = False) -> None: ...
def feed(self, data: str | ReadableBuffer, isFinal: bool = False) -> None: ...
else:
def feed(self, data, isFinal: int = 0) -> None: ...
def feed(self, data: str | ReadableBuffer, isFinal: _BoolType = 0) -> None: ...
def flush(self) -> None: ...
def close(self) -> None: ...
def reset(self) -> None: ...
def getColumnNumber(self) -> int | None: ...
def getLineNumber(self) -> int: ...
def getPublicId(self): ...
def getSystemId(self): ...
def start_element(self, name: str, attrs: xmlreader.AttributesImpl) -> None: ...
def getPublicId(self) -> str | None: ...
def getSystemId(self) -> str | None: ...
def start_element(self, name: str, attrs: Mapping[str, str]) -> None: ...
def end_element(self, name: str) -> None: ...
def start_element_ns(self, name: str, attrs) -> None: ...
def start_element_ns(self, name: str, attrs: Mapping[str, str]) -> None: ...
def end_element_ns(self, name: str) -> None: ...
def processing_instruction(self, target: str, data: str) -> None: ...
def character_data(self, data: str) -> None: ...
def start_namespace_decl(self, prefix: str | None, uri: str) -> None: ...
def end_namespace_decl(self, prefix: str | None) -> None: ...
def start_doctype_decl(self, name: str, sysid: str | None, pubid: str | None, has_internal_subset: Unused) -> None: ...
def unparsed_entity_decl(self, name, base, sysid, pubid, notation_name) -> None: ...
def notation_decl(self, name, base, sysid, pubid) -> None: ...
def external_entity_ref(self, context, base, sysid, pubid): ...
def start_doctype_decl(self, name: str, sysid: str | None, pubid: str | None, has_internal_subset: bool) -> None: ...
def unparsed_entity_decl(self, name: str, base: str | None, sysid: str, pubid: str | None, notation_name: str) -> None: ...
def notation_decl(self, name: str, base: str | None, sysid: str, pubid: str | None) -> None: ...
def external_entity_ref(self, context: str, base: str | None, sysid: str, pubid: str | None) -> int: ...
def skipped_entity_handler(self, name: str, is_pe: bool) -> None: ...
def create_parser(namespaceHandling: int = 0, bufsize: int = 65516) -> ExpatParser: ...
+48 -17
View File
@@ -1,14 +1,36 @@
import sys
from typing import NoReturn
from typing import Literal, NoReturn, Protocol, type_check_only
from xml.sax import xmlreader
version: str
@type_check_only
class _ErrorHandlerProtocol(Protocol): # noqa: Y046 # Protocol is not used
def error(self, exception: BaseException) -> NoReturn: ...
def fatalError(self, exception: BaseException) -> NoReturn: ...
def warning(self, exception: BaseException) -> None: ...
class ErrorHandler:
def error(self, exception: BaseException) -> NoReturn: ...
def fatalError(self, exception: BaseException) -> NoReturn: ...
def warning(self, exception: BaseException) -> None: ...
@type_check_only
class _ContentHandlerProtocol(Protocol): # noqa: Y046 # Protocol is not used
def setDocumentLocator(self, locator: xmlreader.Locator) -> None: ...
def startDocument(self) -> None: ...
def endDocument(self) -> None: ...
def startPrefixMapping(self, prefix: str | None, uri: str) -> None: ...
def endPrefixMapping(self, prefix: str | None) -> None: ...
def startElement(self, name: str, attrs: xmlreader.AttributesImpl) -> None: ...
def endElement(self, name: str) -> None: ...
def startElementNS(self, name: tuple[str | None, str], qname: str | None, attrs: xmlreader.AttributesNSImpl) -> None: ...
def endElementNS(self, name: tuple[str | None, str], qname: str | None) -> None: ...
def characters(self, content: str) -> None: ...
def ignorableWhitespace(self, whitespace: str) -> None: ...
def processingInstruction(self, target: str, data: str) -> None: ...
def skippedEntity(self, name: str) -> None: ...
class ContentHandler:
def setDocumentLocator(self, locator: xmlreader.Locator) -> None: ...
def startDocument(self) -> None: ...
@@ -17,19 +39,28 @@ class ContentHandler:
def endPrefixMapping(self, prefix: str | None) -> None: ...
def startElement(self, name: str, attrs: xmlreader.AttributesImpl) -> None: ...
def endElement(self, name: str) -> None: ...
def startElementNS(self, name: tuple[str, str], qname: str, attrs: xmlreader.AttributesNSImpl) -> None: ...
def endElementNS(self, name: tuple[str, str], qname: str) -> None: ...
def startElementNS(self, name: tuple[str | None, str], qname: str | None, attrs: xmlreader.AttributesNSImpl) -> None: ...
def endElementNS(self, name: tuple[str | None, str], qname: str | None) -> None: ...
def characters(self, content: str) -> None: ...
def ignorableWhitespace(self, whitespace: str) -> None: ...
def processingInstruction(self, target: str, data: str) -> None: ...
def skippedEntity(self, name: str) -> None: ...
@type_check_only
class _DTDHandlerProtocol(Protocol): # noqa: Y046 # Protocol is not used
def notationDecl(self, name: str, publicId: str | None, systemId: str) -> None: ...
def unparsedEntityDecl(self, name: str, publicId: str | None, systemId: str, ndata: str) -> None: ...
class DTDHandler:
def notationDecl(self, name, publicId, systemId): ...
def unparsedEntityDecl(self, name, publicId, systemId, ndata): ...
def notationDecl(self, name: str, publicId: str | None, systemId: str) -> None: ...
def unparsedEntityDecl(self, name: str, publicId: str | None, systemId: str, ndata: str) -> None: ...
@type_check_only
class _EntityResolverProtocol(Protocol): # noqa: Y046 # Protocol is not used
def resolveEntity(self, publicId: str | None, systemId: str) -> str: ...
class EntityResolver:
def resolveEntity(self, publicId, systemId): ...
def resolveEntity(self, publicId: str | None, systemId: str) -> str: ...
feature_namespaces: str
feature_namespace_prefixes: str
@@ -38,18 +69,18 @@ feature_validation: str
feature_external_ges: str
feature_external_pes: str
all_features: list[str]
property_lexical_handler: str
property_declaration_handler: str
property_dom_node: str
property_xml_string: str
property_encoding: str
property_interning_dict: str
property_lexical_handler: Literal["http://xml.org/sax/properties/lexical-handler"]
property_declaration_handler: Literal["http://xml.org/sax/properties/declaration-handler"]
property_dom_node: Literal["http://xml.org/sax/properties/dom-node"]
property_xml_string: Literal["http://xml.org/sax/properties/xml-string"]
property_encoding: Literal["http://www.python.org/sax/properties/encoding"]
property_interning_dict: Literal["http://www.python.org/sax/properties/interning-dict"]
all_properties: list[str]
if sys.version_info >= (3, 10):
class LexicalHandler:
def comment(self, content: str) -> object: ...
def startDTD(self, name: str, public_id: str | None, system_id: str | None) -> object: ...
def endDTD(self) -> object: ...
def startCDATA(self) -> object: ...
def endCDATA(self) -> object: ...
def comment(self, content: str) -> None: ...
def startDTD(self, name: str, public_id: str | None, system_id: str | None) -> None: ...
def endDTD(self) -> None: ...
def startCDATA(self) -> None: ...
def endCDATA(self) -> None: ...
+24 -16
View File
@@ -2,6 +2,7 @@ from _typeshed import SupportsWrite
from codecs import StreamReaderWriter, StreamWriter
from collections.abc import Mapping
from io import RawIOBase, TextIOBase
from typing import Literal, NoReturn
from xml.sax import _Source, handler, xmlreader
def escape(data: str, entities: Mapping[str, str] = {}) -> str: ...
@@ -15,23 +16,26 @@ class XMLGenerator(handler.ContentHandler):
encoding: str = "iso-8859-1",
short_empty_elements: bool = False,
) -> None: ...
def _qname(self, name: tuple[str | None, str]) -> str: ...
def startDocument(self) -> None: ...
def endDocument(self) -> None: ...
def startPrefixMapping(self, prefix: str | None, uri: str) -> None: ...
def endPrefixMapping(self, prefix: str | None) -> None: ...
def startElement(self, name: str, attrs: xmlreader.AttributesImpl) -> None: ...
def endElement(self, name: str) -> None: ...
def startElementNS(self, name: tuple[str, str], qname: str, attrs: xmlreader.AttributesNSImpl) -> None: ...
def endElementNS(self, name: tuple[str, str], qname: str) -> None: ...
def startElementNS(self, name: tuple[str | None, str], qname: str | None, attrs: xmlreader.AttributesNSImpl) -> None: ...
def endElementNS(self, name: tuple[str | None, str], qname: str | None) -> None: ...
def characters(self, content: str) -> None: ...
def ignorableWhitespace(self, content: str) -> None: ...
def processingInstruction(self, target: str, data: str) -> None: ...
class XMLFilterBase(xmlreader.XMLReader):
def __init__(self, parent: xmlreader.XMLReader | None = None) -> None: ...
def error(self, exception): ...
def fatalError(self, exception): ...
def warning(self, exception): ...
# ErrorHandler methods
def error(self, exception: BaseException) -> NoReturn: ...
def fatalError(self, exception: BaseException) -> NoReturn: ...
def warning(self, exception: BaseException) -> None: ...
# ContentHandler methods
def setDocumentLocator(self, locator: xmlreader.Locator) -> None: ...
def startDocument(self) -> None: ...
def endDocument(self) -> None: ...
@@ -39,22 +43,26 @@ class XMLFilterBase(xmlreader.XMLReader):
def endPrefixMapping(self, prefix: str | None) -> None: ...
def startElement(self, name: str, attrs: xmlreader.AttributesImpl) -> None: ...
def endElement(self, name: str) -> None: ...
def startElementNS(self, name: tuple[str, str], qname: str, attrs: xmlreader.AttributesNSImpl) -> None: ...
def endElementNS(self, name: tuple[str, str], qname: str) -> None: ...
def startElementNS(self, name: tuple[str | None, str], qname: str | None, attrs: xmlreader.AttributesNSImpl) -> None: ...
def endElementNS(self, name: tuple[str | None, str], qname: str | None) -> None: ...
def characters(self, content: str) -> None: ...
def ignorableWhitespace(self, chars: str) -> None: ...
def processingInstruction(self, target: str, data: str) -> None: ...
def skippedEntity(self, name: str) -> None: ...
def notationDecl(self, name, publicId, systemId): ...
def unparsedEntityDecl(self, name, publicId, systemId, ndata): ...
def resolveEntity(self, publicId, systemId): ...
def parse(self, source: _Source) -> None: ...
def setLocale(self, locale): ...
def getFeature(self, name: str) -> object: ...
def setFeature(self, name: str, state: object) -> None: ...
# DTDHandler methods
def notationDecl(self, name: str, publicId: str | None, systemId: str) -> None: ...
def unparsedEntityDecl(self, name: str, publicId: str | None, systemId: str, ndata: str) -> None: ...
# EntityResolver methods
def resolveEntity(self, publicId: str | None, systemId: str) -> str: ...
# XMLReader methods
def parse(self, source: xmlreader.InputSource | _Source) -> None: ...
def setLocale(self, locale: str) -> None: ...
def getFeature(self, name: str) -> Literal[1, 0] | bool: ...
def setFeature(self, name: str, state: Literal[1, 0] | bool) -> None: ...
def getProperty(self, name: str) -> object: ...
def setProperty(self, name: str, value: object) -> None: ...
def getParent(self) -> xmlreader.XMLReader: ...
# XMLFilter methods
def getParent(self) -> xmlreader.XMLReader | None: ...
def setParent(self, parent: xmlreader.XMLReader) -> None: ...
def prepare_input_source(source, base=""): ...
def prepare_input_source(source: xmlreader.InputSource | _Source, base: str = "") -> xmlreader.InputSource: ...
+59 -56
View File
@@ -1,87 +1,90 @@
from _typeshed import ReadableBuffer
from collections.abc import Mapping
from typing import overload
from typing import Generic, Literal, TypeVar, overload
from typing_extensions import Self, TypeAlias
from xml.sax.handler import ContentHandler, DTDHandler, EntityResolver, ErrorHandler
from xml.sax import _Source, _SupportsReadClose
from xml.sax.handler import _ContentHandlerProtocol, _DTDHandlerProtocol, _EntityResolverProtocol, _ErrorHandlerProtocol
class XMLReader:
def parse(self, source): ...
def getContentHandler(self) -> ContentHandler: ...
def setContentHandler(self, handler: ContentHandler) -> None: ...
def getDTDHandler(self) -> DTDHandler: ...
def setDTDHandler(self, handler: DTDHandler) -> None: ...
def getEntityResolver(self) -> EntityResolver: ...
def setEntityResolver(self, resolver: EntityResolver) -> None: ...
def getErrorHandler(self) -> ErrorHandler: ...
def setErrorHandler(self, handler: ErrorHandler) -> None: ...
def setLocale(self, locale): ...
def getFeature(self, name: str) -> object: ...
def setFeature(self, name: str, state: object) -> None: ...
def parse(self, source: InputSource | _Source) -> None: ...
def getContentHandler(self) -> _ContentHandlerProtocol: ...
def setContentHandler(self, handler: _ContentHandlerProtocol) -> None: ...
def getDTDHandler(self) -> _DTDHandlerProtocol: ...
def setDTDHandler(self, handler: _DTDHandlerProtocol) -> None: ...
def getEntityResolver(self) -> _EntityResolverProtocol: ...
def setEntityResolver(self, resolver: _EntityResolverProtocol) -> None: ...
def getErrorHandler(self) -> _ErrorHandlerProtocol: ...
def setErrorHandler(self, handler: _ErrorHandlerProtocol) -> None: ...
def setLocale(self, locale: str) -> None: ...
def getFeature(self, name: str) -> Literal[0, 1] | bool: ...
def setFeature(self, name: str, state: Literal[0, 1] | bool) -> None: ...
def getProperty(self, name: str) -> object: ...
def setProperty(self, name: str, value: object) -> None: ...
class IncrementalParser(XMLReader):
def __init__(self, bufsize: int = 65536) -> None: ...
def parse(self, source): ...
def feed(self, data): ...
def prepareParser(self, source): ...
def close(self): ...
def reset(self): ...
def parse(self, source: InputSource | _Source) -> None: ...
def feed(self, data: str | ReadableBuffer) -> None: ...
def prepareParser(self, source: InputSource) -> None: ...
def close(self) -> None: ...
def reset(self) -> None: ...
class Locator:
def getColumnNumber(self): ...
def getLineNumber(self): ...
def getPublicId(self): ...
def getSystemId(self): ...
def getColumnNumber(self) -> int | None: ...
def getLineNumber(self) -> int | None: ...
def getPublicId(self) -> str | None: ...
def getSystemId(self) -> str | None: ...
class InputSource:
def __init__(self, system_id: str | None = None) -> None: ...
def setPublicId(self, public_id): ...
def getPublicId(self): ...
def setSystemId(self, system_id): ...
def getSystemId(self): ...
def setEncoding(self, encoding): ...
def getEncoding(self): ...
def setByteStream(self, bytefile): ...
def getByteStream(self): ...
def setCharacterStream(self, charfile): ...
def getCharacterStream(self): ...
def setPublicId(self, public_id: str | None) -> None: ...
def getPublicId(self) -> str | None: ...
def setSystemId(self, system_id: str | None) -> None: ...
def getSystemId(self) -> str | None: ...
def setEncoding(self, encoding: str | None) -> None: ...
def getEncoding(self) -> str | None: ...
def setByteStream(self, bytefile: _SupportsReadClose[bytes] | None) -> None: ...
def getByteStream(self) -> _SupportsReadClose[bytes] | None: ...
def setCharacterStream(self, charfile: _SupportsReadClose[str] | None) -> None: ...
def getCharacterStream(self) -> _SupportsReadClose[str] | None: ...
class AttributesImpl:
def __init__(self, attrs: Mapping[str, str]) -> None: ...
_AttrKey = TypeVar("_AttrKey", default=str)
class AttributesImpl(Generic[_AttrKey]):
def __init__(self, attrs: Mapping[_AttrKey, str]) -> None: ...
def getLength(self) -> int: ...
def getType(self, name: str) -> str: ...
def getValue(self, name: str) -> str: ...
def getValue(self, name: _AttrKey) -> str: ...
def getValueByQName(self, name: str) -> str: ...
def getNameByQName(self, name: str) -> str: ...
def getQNameByName(self, name: str) -> str: ...
def getNames(self) -> list[str]: ...
def getNameByQName(self, name: str) -> _AttrKey: ...
def getQNameByName(self, name: _AttrKey) -> str: ...
def getNames(self) -> list[_AttrKey]: ...
def getQNames(self) -> list[str]: ...
def __len__(self) -> int: ...
def __getitem__(self, name: str) -> str: ...
def keys(self) -> list[str]: ...
def __contains__(self, name: str) -> bool: ...
def __getitem__(self, name: _AttrKey) -> str: ...
def keys(self) -> list[_AttrKey]: ...
def __contains__(self, name: _AttrKey) -> bool: ...
@overload
def get(self, name: str, alternative: None = None) -> str | None: ...
def get(self, name: _AttrKey, alternative: None = None) -> str | None: ...
@overload
def get(self, name: str, alternative: str) -> str: ...
def get(self, name: _AttrKey, alternative: str) -> str: ...
def copy(self) -> Self: ...
def items(self) -> list[tuple[str, str]]: ...
def items(self) -> list[tuple[_AttrKey, str]]: ...
def values(self) -> list[str]: ...
_NSName: TypeAlias = tuple[str | None, str]
class AttributesNSImpl(AttributesImpl):
class AttributesNSImpl(AttributesImpl[_NSName]):
def __init__(self, attrs: Mapping[_NSName, str], qnames: Mapping[_NSName, str]) -> None: ...
def getType(self, name: _NSName) -> str: ... # type: ignore[override]
def getValue(self, name: _NSName) -> str: ... # type: ignore[override]
def getNameByQName(self, name: str) -> _NSName: ... # type: ignore[override]
def getQNameByName(self, name: _NSName) -> str: ... # type: ignore[override]
def getNames(self) -> list[_NSName]: ... # type: ignore[override]
def __getitem__(self, name: _NSName) -> str: ... # type: ignore[override]
def keys(self) -> list[_NSName]: ... # type: ignore[override]
def __contains__(self, name: _NSName) -> bool: ... # type: ignore[override]
@overload # type: ignore[override]
def getValue(self, name: _NSName) -> str: ...
def getNameByQName(self, name: str) -> _NSName: ...
def getQNameByName(self, name: _NSName) -> str: ...
def getNames(self) -> list[_NSName]: ...
def __getitem__(self, name: _NSName) -> str: ...
def keys(self) -> list[_NSName]: ...
def __contains__(self, name: _NSName) -> bool: ...
@overload
def get(self, name: _NSName, alternative: None = None) -> str | None: ...
@overload
def get(self, name: _NSName, alternative: str) -> str: ...
def items(self) -> list[tuple[_NSName, str]]: ... # type: ignore[override]
def items(self) -> list[tuple[_NSName, str]]: ...