summaryrefslogtreecommitdiffstats
path: root/Lib/xml/sax
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2020-08-09 10:50:53 (GMT)
committerGitHub <noreply@github.com>2020-08-09 10:50:53 (GMT)
commite28b8c93878072dc02b116108ef5443084290d47 (patch)
tree5a5a398cdc0dbb9f8c78fe9d37ed15b7e3ce89ce /Lib/xml/sax
parent67acf74c4eaf64a860cc1bcda6efe6e9cb01f89b (diff)
downloadcpython-e28b8c93878072dc02b116108ef5443084290d47.zip
cpython-e28b8c93878072dc02b116108ef5443084290d47.tar.gz
cpython-e28b8c93878072dc02b116108ef5443084290d47.tar.bz2
bpo-35018: Sax parser should provide user access to lexical handlers (GH-20958)
Co-Authored-By: Jonathan Gossage <jgossage@gmail.com>
Diffstat (limited to 'Lib/xml/sax')
-rw-r--r--Lib/xml/sax/handler.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/xml/sax/handler.py b/Lib/xml/sax/handler.py
index 481733d..e8d417e 100644
--- a/Lib/xml/sax/handler.py
+++ b/Lib/xml/sax/handler.py
@@ -340,3 +340,48 @@ all_properties = [property_lexical_handler,
property_xml_string,
property_encoding,
property_interning_dict]
+
+
+class LexicalHandler:
+ """Optional SAX2 handler for lexical events.
+
+ This handler is used to obtain lexical information about an XML
+ document, that is, information about how the document was encoded
+ (as opposed to what it contains, which is reported to the
+ ContentHandler), such as comments and CDATA marked section
+ boundaries.
+
+ To set the LexicalHandler of an XMLReader, use the setProperty
+ method with the property identifier
+ 'http://xml.org/sax/properties/lexical-handler'."""
+
+ def comment(self, content):
+ """Reports a comment anywhere in the document (including the
+ DTD and outside the document element).
+
+ content is a string that holds the contents of the comment."""
+
+ def startDTD(self, name, public_id, system_id):
+ """Report the start of the DTD declarations, if the document
+ has an associated DTD.
+
+ A startEntity event will be reported before declaration events
+ from the external DTD subset are reported, and this can be
+ used to infer from which subset DTD declarations derive.
+
+ name is the name of the document element type, public_id the
+ public identifier of the DTD (or None if none were supplied)
+ and system_id the system identfier of the external subset (or
+ None if none were supplied)."""
+
+ def endDTD(self):
+ """Signals the end of DTD declarations."""
+
+ def startCDATA(self):
+ """Reports the beginning of a CDATA marked section.
+
+ The contents of the CDATA marked section will be reported
+ through the characters event."""
+
+ def endCDATA(self):
+ """Reports the end of a CDATA marked section."""