1*cda5da8dSAndroid Build Coastguard Worker""" 2*cda5da8dSAndroid Build Coastguard WorkerThis module contains the core classes of version 2.0 of SAX for Python. 3*cda5da8dSAndroid Build Coastguard WorkerThis file provides only default classes with absolutely minimum 4*cda5da8dSAndroid Build Coastguard Workerfunctionality, from which drivers and applications can be subclassed. 5*cda5da8dSAndroid Build Coastguard Worker 6*cda5da8dSAndroid Build Coastguard WorkerMany of these classes are empty and are included only as documentation 7*cda5da8dSAndroid Build Coastguard Workerof the interfaces. 8*cda5da8dSAndroid Build Coastguard Worker 9*cda5da8dSAndroid Build Coastguard Worker$Id$ 10*cda5da8dSAndroid Build Coastguard Worker""" 11*cda5da8dSAndroid Build Coastguard Worker 12*cda5da8dSAndroid Build Coastguard Workerversion = '2.0beta' 13*cda5da8dSAndroid Build Coastguard Worker 14*cda5da8dSAndroid Build Coastguard Worker#============================================================================ 15*cda5da8dSAndroid Build Coastguard Worker# 16*cda5da8dSAndroid Build Coastguard Worker# HANDLER INTERFACES 17*cda5da8dSAndroid Build Coastguard Worker# 18*cda5da8dSAndroid Build Coastguard Worker#============================================================================ 19*cda5da8dSAndroid Build Coastguard Worker 20*cda5da8dSAndroid Build Coastguard Worker# ===== ERRORHANDLER ===== 21*cda5da8dSAndroid Build Coastguard Worker 22*cda5da8dSAndroid Build Coastguard Workerclass ErrorHandler: 23*cda5da8dSAndroid Build Coastguard Worker """Basic interface for SAX error handlers. 24*cda5da8dSAndroid Build Coastguard Worker 25*cda5da8dSAndroid Build Coastguard Worker If you create an object that implements this interface, then 26*cda5da8dSAndroid Build Coastguard Worker register the object with your XMLReader, the parser will call the 27*cda5da8dSAndroid Build Coastguard Worker methods in your object to report all warnings and errors. There 28*cda5da8dSAndroid Build Coastguard Worker are three levels of errors available: warnings, (possibly) 29*cda5da8dSAndroid Build Coastguard Worker recoverable errors, and unrecoverable errors. All methods take a 30*cda5da8dSAndroid Build Coastguard Worker SAXParseException as the only parameter.""" 31*cda5da8dSAndroid Build Coastguard Worker 32*cda5da8dSAndroid Build Coastguard Worker def error(self, exception): 33*cda5da8dSAndroid Build Coastguard Worker "Handle a recoverable error." 34*cda5da8dSAndroid Build Coastguard Worker raise exception 35*cda5da8dSAndroid Build Coastguard Worker 36*cda5da8dSAndroid Build Coastguard Worker def fatalError(self, exception): 37*cda5da8dSAndroid Build Coastguard Worker "Handle a non-recoverable error." 38*cda5da8dSAndroid Build Coastguard Worker raise exception 39*cda5da8dSAndroid Build Coastguard Worker 40*cda5da8dSAndroid Build Coastguard Worker def warning(self, exception): 41*cda5da8dSAndroid Build Coastguard Worker "Handle a warning." 42*cda5da8dSAndroid Build Coastguard Worker print(exception) 43*cda5da8dSAndroid Build Coastguard Worker 44*cda5da8dSAndroid Build Coastguard Worker 45*cda5da8dSAndroid Build Coastguard Worker# ===== CONTENTHANDLER ===== 46*cda5da8dSAndroid Build Coastguard Worker 47*cda5da8dSAndroid Build Coastguard Workerclass ContentHandler: 48*cda5da8dSAndroid Build Coastguard Worker """Interface for receiving logical document content events. 49*cda5da8dSAndroid Build Coastguard Worker 50*cda5da8dSAndroid Build Coastguard Worker This is the main callback interface in SAX, and the one most 51*cda5da8dSAndroid Build Coastguard Worker important to applications. The order of events in this interface 52*cda5da8dSAndroid Build Coastguard Worker mirrors the order of the information in the document.""" 53*cda5da8dSAndroid Build Coastguard Worker 54*cda5da8dSAndroid Build Coastguard Worker def __init__(self): 55*cda5da8dSAndroid Build Coastguard Worker self._locator = None 56*cda5da8dSAndroid Build Coastguard Worker 57*cda5da8dSAndroid Build Coastguard Worker def setDocumentLocator(self, locator): 58*cda5da8dSAndroid Build Coastguard Worker """Called by the parser to give the application a locator for 59*cda5da8dSAndroid Build Coastguard Worker locating the origin of document events. 60*cda5da8dSAndroid Build Coastguard Worker 61*cda5da8dSAndroid Build Coastguard Worker SAX parsers are strongly encouraged (though not absolutely 62*cda5da8dSAndroid Build Coastguard Worker required) to supply a locator: if it does so, it must supply 63*cda5da8dSAndroid Build Coastguard Worker the locator to the application by invoking this method before 64*cda5da8dSAndroid Build Coastguard Worker invoking any of the other methods in the DocumentHandler 65*cda5da8dSAndroid Build Coastguard Worker interface. 66*cda5da8dSAndroid Build Coastguard Worker 67*cda5da8dSAndroid Build Coastguard Worker The locator allows the application to determine the end 68*cda5da8dSAndroid Build Coastguard Worker position of any document-related event, even if the parser is 69*cda5da8dSAndroid Build Coastguard Worker not reporting an error. Typically, the application will use 70*cda5da8dSAndroid Build Coastguard Worker this information for reporting its own errors (such as 71*cda5da8dSAndroid Build Coastguard Worker character content that does not match an application's 72*cda5da8dSAndroid Build Coastguard Worker business rules). The information returned by the locator is 73*cda5da8dSAndroid Build Coastguard Worker probably not sufficient for use with a search engine. 74*cda5da8dSAndroid Build Coastguard Worker 75*cda5da8dSAndroid Build Coastguard Worker Note that the locator will return correct information only 76*cda5da8dSAndroid Build Coastguard Worker during the invocation of the events in this interface. The 77*cda5da8dSAndroid Build Coastguard Worker application should not attempt to use it at any other time.""" 78*cda5da8dSAndroid Build Coastguard Worker self._locator = locator 79*cda5da8dSAndroid Build Coastguard Worker 80*cda5da8dSAndroid Build Coastguard Worker def startDocument(self): 81*cda5da8dSAndroid Build Coastguard Worker """Receive notification of the beginning of a document. 82*cda5da8dSAndroid Build Coastguard Worker 83*cda5da8dSAndroid Build Coastguard Worker The SAX parser will invoke this method only once, before any 84*cda5da8dSAndroid Build Coastguard Worker other methods in this interface or in DTDHandler (except for 85*cda5da8dSAndroid Build Coastguard Worker setDocumentLocator).""" 86*cda5da8dSAndroid Build Coastguard Worker 87*cda5da8dSAndroid Build Coastguard Worker def endDocument(self): 88*cda5da8dSAndroid Build Coastguard Worker """Receive notification of the end of a document. 89*cda5da8dSAndroid Build Coastguard Worker 90*cda5da8dSAndroid Build Coastguard Worker The SAX parser will invoke this method only once, and it will 91*cda5da8dSAndroid Build Coastguard Worker be the last method invoked during the parse. The parser shall 92*cda5da8dSAndroid Build Coastguard Worker not invoke this method until it has either abandoned parsing 93*cda5da8dSAndroid Build Coastguard Worker (because of an unrecoverable error) or reached the end of 94*cda5da8dSAndroid Build Coastguard Worker input.""" 95*cda5da8dSAndroid Build Coastguard Worker 96*cda5da8dSAndroid Build Coastguard Worker def startPrefixMapping(self, prefix, uri): 97*cda5da8dSAndroid Build Coastguard Worker """Begin the scope of a prefix-URI Namespace mapping. 98*cda5da8dSAndroid Build Coastguard Worker 99*cda5da8dSAndroid Build Coastguard Worker The information from this event is not necessary for normal 100*cda5da8dSAndroid Build Coastguard Worker Namespace processing: the SAX XML reader will automatically 101*cda5da8dSAndroid Build Coastguard Worker replace prefixes for element and attribute names when the 102*cda5da8dSAndroid Build Coastguard Worker http://xml.org/sax/features/namespaces feature is true (the 103*cda5da8dSAndroid Build Coastguard Worker default). 104*cda5da8dSAndroid Build Coastguard Worker 105*cda5da8dSAndroid Build Coastguard Worker There are cases, however, when applications need to use 106*cda5da8dSAndroid Build Coastguard Worker prefixes in character data or in attribute values, where they 107*cda5da8dSAndroid Build Coastguard Worker cannot safely be expanded automatically; the 108*cda5da8dSAndroid Build Coastguard Worker start/endPrefixMapping event supplies the information to the 109*cda5da8dSAndroid Build Coastguard Worker application to expand prefixes in those contexts itself, if 110*cda5da8dSAndroid Build Coastguard Worker necessary. 111*cda5da8dSAndroid Build Coastguard Worker 112*cda5da8dSAndroid Build Coastguard Worker Note that start/endPrefixMapping events are not guaranteed to 113*cda5da8dSAndroid Build Coastguard Worker be properly nested relative to each-other: all 114*cda5da8dSAndroid Build Coastguard Worker startPrefixMapping events will occur before the corresponding 115*cda5da8dSAndroid Build Coastguard Worker startElement event, and all endPrefixMapping events will occur 116*cda5da8dSAndroid Build Coastguard Worker after the corresponding endElement event, but their order is 117*cda5da8dSAndroid Build Coastguard Worker not guaranteed.""" 118*cda5da8dSAndroid Build Coastguard Worker 119*cda5da8dSAndroid Build Coastguard Worker def endPrefixMapping(self, prefix): 120*cda5da8dSAndroid Build Coastguard Worker """End the scope of a prefix-URI mapping. 121*cda5da8dSAndroid Build Coastguard Worker 122*cda5da8dSAndroid Build Coastguard Worker See startPrefixMapping for details. This event will always 123*cda5da8dSAndroid Build Coastguard Worker occur after the corresponding endElement event, but the order 124*cda5da8dSAndroid Build Coastguard Worker of endPrefixMapping events is not otherwise guaranteed.""" 125*cda5da8dSAndroid Build Coastguard Worker 126*cda5da8dSAndroid Build Coastguard Worker def startElement(self, name, attrs): 127*cda5da8dSAndroid Build Coastguard Worker """Signals the start of an element in non-namespace mode. 128*cda5da8dSAndroid Build Coastguard Worker 129*cda5da8dSAndroid Build Coastguard Worker The name parameter contains the raw XML 1.0 name of the 130*cda5da8dSAndroid Build Coastguard Worker element type as a string and the attrs parameter holds an 131*cda5da8dSAndroid Build Coastguard Worker instance of the Attributes class containing the attributes of 132*cda5da8dSAndroid Build Coastguard Worker the element.""" 133*cda5da8dSAndroid Build Coastguard Worker 134*cda5da8dSAndroid Build Coastguard Worker def endElement(self, name): 135*cda5da8dSAndroid Build Coastguard Worker """Signals the end of an element in non-namespace mode. 136*cda5da8dSAndroid Build Coastguard Worker 137*cda5da8dSAndroid Build Coastguard Worker The name parameter contains the name of the element type, just 138*cda5da8dSAndroid Build Coastguard Worker as with the startElement event.""" 139*cda5da8dSAndroid Build Coastguard Worker 140*cda5da8dSAndroid Build Coastguard Worker def startElementNS(self, name, qname, attrs): 141*cda5da8dSAndroid Build Coastguard Worker """Signals the start of an element in namespace mode. 142*cda5da8dSAndroid Build Coastguard Worker 143*cda5da8dSAndroid Build Coastguard Worker The name parameter contains the name of the element type as a 144*cda5da8dSAndroid Build Coastguard Worker (uri, localname) tuple, the qname parameter the raw XML 1.0 145*cda5da8dSAndroid Build Coastguard Worker name used in the source document, and the attrs parameter 146*cda5da8dSAndroid Build Coastguard Worker holds an instance of the Attributes class containing the 147*cda5da8dSAndroid Build Coastguard Worker attributes of the element. 148*cda5da8dSAndroid Build Coastguard Worker 149*cda5da8dSAndroid Build Coastguard Worker The uri part of the name tuple is None for elements which have 150*cda5da8dSAndroid Build Coastguard Worker no namespace.""" 151*cda5da8dSAndroid Build Coastguard Worker 152*cda5da8dSAndroid Build Coastguard Worker def endElementNS(self, name, qname): 153*cda5da8dSAndroid Build Coastguard Worker """Signals the end of an element in namespace mode. 154*cda5da8dSAndroid Build Coastguard Worker 155*cda5da8dSAndroid Build Coastguard Worker The name parameter contains the name of the element type, just 156*cda5da8dSAndroid Build Coastguard Worker as with the startElementNS event.""" 157*cda5da8dSAndroid Build Coastguard Worker 158*cda5da8dSAndroid Build Coastguard Worker def characters(self, content): 159*cda5da8dSAndroid Build Coastguard Worker """Receive notification of character data. 160*cda5da8dSAndroid Build Coastguard Worker 161*cda5da8dSAndroid Build Coastguard Worker The Parser will call this method to report each chunk of 162*cda5da8dSAndroid Build Coastguard Worker character data. SAX parsers may return all contiguous 163*cda5da8dSAndroid Build Coastguard Worker character data in a single chunk, or they may split it into 164*cda5da8dSAndroid Build Coastguard Worker several chunks; however, all of the characters in any single 165*cda5da8dSAndroid Build Coastguard Worker event must come from the same external entity so that the 166*cda5da8dSAndroid Build Coastguard Worker Locator provides useful information.""" 167*cda5da8dSAndroid Build Coastguard Worker 168*cda5da8dSAndroid Build Coastguard Worker def ignorableWhitespace(self, whitespace): 169*cda5da8dSAndroid Build Coastguard Worker """Receive notification of ignorable whitespace in element content. 170*cda5da8dSAndroid Build Coastguard Worker 171*cda5da8dSAndroid Build Coastguard Worker Validating Parsers must use this method to report each chunk 172*cda5da8dSAndroid Build Coastguard Worker of ignorable whitespace (see the W3C XML 1.0 recommendation, 173*cda5da8dSAndroid Build Coastguard Worker section 2.10): non-validating parsers may also use this method 174*cda5da8dSAndroid Build Coastguard Worker if they are capable of parsing and using content models. 175*cda5da8dSAndroid Build Coastguard Worker 176*cda5da8dSAndroid Build Coastguard Worker SAX parsers may return all contiguous whitespace in a single 177*cda5da8dSAndroid Build Coastguard Worker chunk, or they may split it into several chunks; however, all 178*cda5da8dSAndroid Build Coastguard Worker of the characters in any single event must come from the same 179*cda5da8dSAndroid Build Coastguard Worker external entity, so that the Locator provides useful 180*cda5da8dSAndroid Build Coastguard Worker information.""" 181*cda5da8dSAndroid Build Coastguard Worker 182*cda5da8dSAndroid Build Coastguard Worker def processingInstruction(self, target, data): 183*cda5da8dSAndroid Build Coastguard Worker """Receive notification of a processing instruction. 184*cda5da8dSAndroid Build Coastguard Worker 185*cda5da8dSAndroid Build Coastguard Worker The Parser will invoke this method once for each processing 186*cda5da8dSAndroid Build Coastguard Worker instruction found: note that processing instructions may occur 187*cda5da8dSAndroid Build Coastguard Worker before or after the main document element. 188*cda5da8dSAndroid Build Coastguard Worker 189*cda5da8dSAndroid Build Coastguard Worker A SAX parser should never report an XML declaration (XML 1.0, 190*cda5da8dSAndroid Build Coastguard Worker section 2.8) or a text declaration (XML 1.0, section 4.3.1) 191*cda5da8dSAndroid Build Coastguard Worker using this method.""" 192*cda5da8dSAndroid Build Coastguard Worker 193*cda5da8dSAndroid Build Coastguard Worker def skippedEntity(self, name): 194*cda5da8dSAndroid Build Coastguard Worker """Receive notification of a skipped entity. 195*cda5da8dSAndroid Build Coastguard Worker 196*cda5da8dSAndroid Build Coastguard Worker The Parser will invoke this method once for each entity 197*cda5da8dSAndroid Build Coastguard Worker skipped. Non-validating processors may skip entities if they 198*cda5da8dSAndroid Build Coastguard Worker have not seen the declarations (because, for example, the 199*cda5da8dSAndroid Build Coastguard Worker entity was declared in an external DTD subset). All processors 200*cda5da8dSAndroid Build Coastguard Worker may skip external entities, depending on the values of the 201*cda5da8dSAndroid Build Coastguard Worker http://xml.org/sax/features/external-general-entities and the 202*cda5da8dSAndroid Build Coastguard Worker http://xml.org/sax/features/external-parameter-entities 203*cda5da8dSAndroid Build Coastguard Worker properties.""" 204*cda5da8dSAndroid Build Coastguard Worker 205*cda5da8dSAndroid Build Coastguard Worker 206*cda5da8dSAndroid Build Coastguard Worker# ===== DTDHandler ===== 207*cda5da8dSAndroid Build Coastguard Worker 208*cda5da8dSAndroid Build Coastguard Workerclass DTDHandler: 209*cda5da8dSAndroid Build Coastguard Worker """Handle DTD events. 210*cda5da8dSAndroid Build Coastguard Worker 211*cda5da8dSAndroid Build Coastguard Worker This interface specifies only those DTD events required for basic 212*cda5da8dSAndroid Build Coastguard Worker parsing (unparsed entities and attributes).""" 213*cda5da8dSAndroid Build Coastguard Worker 214*cda5da8dSAndroid Build Coastguard Worker def notationDecl(self, name, publicId, systemId): 215*cda5da8dSAndroid Build Coastguard Worker "Handle a notation declaration event." 216*cda5da8dSAndroid Build Coastguard Worker 217*cda5da8dSAndroid Build Coastguard Worker def unparsedEntityDecl(self, name, publicId, systemId, ndata): 218*cda5da8dSAndroid Build Coastguard Worker "Handle an unparsed entity declaration event." 219*cda5da8dSAndroid Build Coastguard Worker 220*cda5da8dSAndroid Build Coastguard Worker 221*cda5da8dSAndroid Build Coastguard Worker# ===== ENTITYRESOLVER ===== 222*cda5da8dSAndroid Build Coastguard Worker 223*cda5da8dSAndroid Build Coastguard Workerclass EntityResolver: 224*cda5da8dSAndroid Build Coastguard Worker """Basic interface for resolving entities. If you create an object 225*cda5da8dSAndroid Build Coastguard Worker implementing this interface, then register the object with your 226*cda5da8dSAndroid Build Coastguard Worker Parser, the parser will call the method in your object to 227*cda5da8dSAndroid Build Coastguard Worker resolve all external entities. Note that DefaultHandler implements 228*cda5da8dSAndroid Build Coastguard Worker this interface with the default behaviour.""" 229*cda5da8dSAndroid Build Coastguard Worker 230*cda5da8dSAndroid Build Coastguard Worker def resolveEntity(self, publicId, systemId): 231*cda5da8dSAndroid Build Coastguard Worker """Resolve the system identifier of an entity and return either 232*cda5da8dSAndroid Build Coastguard Worker the system identifier to read from as a string, or an InputSource 233*cda5da8dSAndroid Build Coastguard Worker to read from.""" 234*cda5da8dSAndroid Build Coastguard Worker return systemId 235*cda5da8dSAndroid Build Coastguard Worker 236*cda5da8dSAndroid Build Coastguard Worker 237*cda5da8dSAndroid Build Coastguard Worker#============================================================================ 238*cda5da8dSAndroid Build Coastguard Worker# 239*cda5da8dSAndroid Build Coastguard Worker# CORE FEATURES 240*cda5da8dSAndroid Build Coastguard Worker# 241*cda5da8dSAndroid Build Coastguard Worker#============================================================================ 242*cda5da8dSAndroid Build Coastguard Worker 243*cda5da8dSAndroid Build Coastguard Workerfeature_namespaces = "http://xml.org/sax/features/namespaces" 244*cda5da8dSAndroid Build Coastguard Worker# true: Perform Namespace processing (default). 245*cda5da8dSAndroid Build Coastguard Worker# false: Optionally do not perform Namespace processing 246*cda5da8dSAndroid Build Coastguard Worker# (implies namespace-prefixes). 247*cda5da8dSAndroid Build Coastguard Worker# access: (parsing) read-only; (not parsing) read/write 248*cda5da8dSAndroid Build Coastguard Worker 249*cda5da8dSAndroid Build Coastguard Workerfeature_namespace_prefixes = "http://xml.org/sax/features/namespace-prefixes" 250*cda5da8dSAndroid Build Coastguard Worker# true: Report the original prefixed names and attributes used for Namespace 251*cda5da8dSAndroid Build Coastguard Worker# declarations. 252*cda5da8dSAndroid Build Coastguard Worker# false: Do not report attributes used for Namespace declarations, and 253*cda5da8dSAndroid Build Coastguard Worker# optionally do not report original prefixed names (default). 254*cda5da8dSAndroid Build Coastguard Worker# access: (parsing) read-only; (not parsing) read/write 255*cda5da8dSAndroid Build Coastguard Worker 256*cda5da8dSAndroid Build Coastguard Workerfeature_string_interning = "http://xml.org/sax/features/string-interning" 257*cda5da8dSAndroid Build Coastguard Worker# true: All element names, prefixes, attribute names, Namespace URIs, and 258*cda5da8dSAndroid Build Coastguard Worker# local names are interned using the built-in intern function. 259*cda5da8dSAndroid Build Coastguard Worker# false: Names are not necessarily interned, although they may be (default). 260*cda5da8dSAndroid Build Coastguard Worker# access: (parsing) read-only; (not parsing) read/write 261*cda5da8dSAndroid Build Coastguard Worker 262*cda5da8dSAndroid Build Coastguard Workerfeature_validation = "http://xml.org/sax/features/validation" 263*cda5da8dSAndroid Build Coastguard Worker# true: Report all validation errors (implies external-general-entities and 264*cda5da8dSAndroid Build Coastguard Worker# external-parameter-entities). 265*cda5da8dSAndroid Build Coastguard Worker# false: Do not report validation errors. 266*cda5da8dSAndroid Build Coastguard Worker# access: (parsing) read-only; (not parsing) read/write 267*cda5da8dSAndroid Build Coastguard Worker 268*cda5da8dSAndroid Build Coastguard Workerfeature_external_ges = "http://xml.org/sax/features/external-general-entities" 269*cda5da8dSAndroid Build Coastguard Worker# true: Include all external general (text) entities. 270*cda5da8dSAndroid Build Coastguard Worker# false: Do not include external general entities. 271*cda5da8dSAndroid Build Coastguard Worker# access: (parsing) read-only; (not parsing) read/write 272*cda5da8dSAndroid Build Coastguard Worker 273*cda5da8dSAndroid Build Coastguard Workerfeature_external_pes = "http://xml.org/sax/features/external-parameter-entities" 274*cda5da8dSAndroid Build Coastguard Worker# true: Include all external parameter entities, including the external 275*cda5da8dSAndroid Build Coastguard Worker# DTD subset. 276*cda5da8dSAndroid Build Coastguard Worker# false: Do not include any external parameter entities, even the external 277*cda5da8dSAndroid Build Coastguard Worker# DTD subset. 278*cda5da8dSAndroid Build Coastguard Worker# access: (parsing) read-only; (not parsing) read/write 279*cda5da8dSAndroid Build Coastguard Worker 280*cda5da8dSAndroid Build Coastguard Workerall_features = [feature_namespaces, 281*cda5da8dSAndroid Build Coastguard Worker feature_namespace_prefixes, 282*cda5da8dSAndroid Build Coastguard Worker feature_string_interning, 283*cda5da8dSAndroid Build Coastguard Worker feature_validation, 284*cda5da8dSAndroid Build Coastguard Worker feature_external_ges, 285*cda5da8dSAndroid Build Coastguard Worker feature_external_pes] 286*cda5da8dSAndroid Build Coastguard Worker 287*cda5da8dSAndroid Build Coastguard Worker 288*cda5da8dSAndroid Build Coastguard Worker#============================================================================ 289*cda5da8dSAndroid Build Coastguard Worker# 290*cda5da8dSAndroid Build Coastguard Worker# CORE PROPERTIES 291*cda5da8dSAndroid Build Coastguard Worker# 292*cda5da8dSAndroid Build Coastguard Worker#============================================================================ 293*cda5da8dSAndroid Build Coastguard Worker 294*cda5da8dSAndroid Build Coastguard Workerproperty_lexical_handler = "http://xml.org/sax/properties/lexical-handler" 295*cda5da8dSAndroid Build Coastguard Worker# data type: xml.sax.sax2lib.LexicalHandler 296*cda5da8dSAndroid Build Coastguard Worker# description: An optional extension handler for lexical events like comments. 297*cda5da8dSAndroid Build Coastguard Worker# access: read/write 298*cda5da8dSAndroid Build Coastguard Worker 299*cda5da8dSAndroid Build Coastguard Workerproperty_declaration_handler = "http://xml.org/sax/properties/declaration-handler" 300*cda5da8dSAndroid Build Coastguard Worker# data type: xml.sax.sax2lib.DeclHandler 301*cda5da8dSAndroid Build Coastguard Worker# description: An optional extension handler for DTD-related events other 302*cda5da8dSAndroid Build Coastguard Worker# than notations and unparsed entities. 303*cda5da8dSAndroid Build Coastguard Worker# access: read/write 304*cda5da8dSAndroid Build Coastguard Worker 305*cda5da8dSAndroid Build Coastguard Workerproperty_dom_node = "http://xml.org/sax/properties/dom-node" 306*cda5da8dSAndroid Build Coastguard Worker# data type: org.w3c.dom.Node 307*cda5da8dSAndroid Build Coastguard Worker# description: When parsing, the current DOM node being visited if this is 308*cda5da8dSAndroid Build Coastguard Worker# a DOM iterator; when not parsing, the root DOM node for 309*cda5da8dSAndroid Build Coastguard Worker# iteration. 310*cda5da8dSAndroid Build Coastguard Worker# access: (parsing) read-only; (not parsing) read/write 311*cda5da8dSAndroid Build Coastguard Worker 312*cda5da8dSAndroid Build Coastguard Workerproperty_xml_string = "http://xml.org/sax/properties/xml-string" 313*cda5da8dSAndroid Build Coastguard Worker# data type: String 314*cda5da8dSAndroid Build Coastguard Worker# description: The literal string of characters that was the source for 315*cda5da8dSAndroid Build Coastguard Worker# the current event. 316*cda5da8dSAndroid Build Coastguard Worker# access: read-only 317*cda5da8dSAndroid Build Coastguard Worker 318*cda5da8dSAndroid Build Coastguard Workerproperty_encoding = "http://www.python.org/sax/properties/encoding" 319*cda5da8dSAndroid Build Coastguard Worker# data type: String 320*cda5da8dSAndroid Build Coastguard Worker# description: The name of the encoding to assume for input data. 321*cda5da8dSAndroid Build Coastguard Worker# access: write: set the encoding, e.g. established by a higher-level 322*cda5da8dSAndroid Build Coastguard Worker# protocol. May change during parsing (e.g. after 323*cda5da8dSAndroid Build Coastguard Worker# processing a META tag) 324*cda5da8dSAndroid Build Coastguard Worker# read: return the current encoding (possibly established through 325*cda5da8dSAndroid Build Coastguard Worker# auto-detection. 326*cda5da8dSAndroid Build Coastguard Worker# initial value: UTF-8 327*cda5da8dSAndroid Build Coastguard Worker# 328*cda5da8dSAndroid Build Coastguard Worker 329*cda5da8dSAndroid Build Coastguard Workerproperty_interning_dict = "http://www.python.org/sax/properties/interning-dict" 330*cda5da8dSAndroid Build Coastguard Worker# data type: Dictionary 331*cda5da8dSAndroid Build Coastguard Worker# description: The dictionary used to intern common strings in the document 332*cda5da8dSAndroid Build Coastguard Worker# access: write: Request that the parser uses a specific dictionary, to 333*cda5da8dSAndroid Build Coastguard Worker# allow interning across different documents 334*cda5da8dSAndroid Build Coastguard Worker# read: return the current interning dictionary, or None 335*cda5da8dSAndroid Build Coastguard Worker# 336*cda5da8dSAndroid Build Coastguard Worker 337*cda5da8dSAndroid Build Coastguard Workerall_properties = [property_lexical_handler, 338*cda5da8dSAndroid Build Coastguard Worker property_dom_node, 339*cda5da8dSAndroid Build Coastguard Worker property_declaration_handler, 340*cda5da8dSAndroid Build Coastguard Worker property_xml_string, 341*cda5da8dSAndroid Build Coastguard Worker property_encoding, 342*cda5da8dSAndroid Build Coastguard Worker property_interning_dict] 343*cda5da8dSAndroid Build Coastguard Worker 344*cda5da8dSAndroid Build Coastguard Worker 345*cda5da8dSAndroid Build Coastguard Workerclass LexicalHandler: 346*cda5da8dSAndroid Build Coastguard Worker """Optional SAX2 handler for lexical events. 347*cda5da8dSAndroid Build Coastguard Worker 348*cda5da8dSAndroid Build Coastguard Worker This handler is used to obtain lexical information about an XML 349*cda5da8dSAndroid Build Coastguard Worker document, that is, information about how the document was encoded 350*cda5da8dSAndroid Build Coastguard Worker (as opposed to what it contains, which is reported to the 351*cda5da8dSAndroid Build Coastguard Worker ContentHandler), such as comments and CDATA marked section 352*cda5da8dSAndroid Build Coastguard Worker boundaries. 353*cda5da8dSAndroid Build Coastguard Worker 354*cda5da8dSAndroid Build Coastguard Worker To set the LexicalHandler of an XMLReader, use the setProperty 355*cda5da8dSAndroid Build Coastguard Worker method with the property identifier 356*cda5da8dSAndroid Build Coastguard Worker 'http://xml.org/sax/properties/lexical-handler'.""" 357*cda5da8dSAndroid Build Coastguard Worker 358*cda5da8dSAndroid Build Coastguard Worker def comment(self, content): 359*cda5da8dSAndroid Build Coastguard Worker """Reports a comment anywhere in the document (including the 360*cda5da8dSAndroid Build Coastguard Worker DTD and outside the document element). 361*cda5da8dSAndroid Build Coastguard Worker 362*cda5da8dSAndroid Build Coastguard Worker content is a string that holds the contents of the comment.""" 363*cda5da8dSAndroid Build Coastguard Worker 364*cda5da8dSAndroid Build Coastguard Worker def startDTD(self, name, public_id, system_id): 365*cda5da8dSAndroid Build Coastguard Worker """Report the start of the DTD declarations, if the document 366*cda5da8dSAndroid Build Coastguard Worker has an associated DTD. 367*cda5da8dSAndroid Build Coastguard Worker 368*cda5da8dSAndroid Build Coastguard Worker A startEntity event will be reported before declaration events 369*cda5da8dSAndroid Build Coastguard Worker from the external DTD subset are reported, and this can be 370*cda5da8dSAndroid Build Coastguard Worker used to infer from which subset DTD declarations derive. 371*cda5da8dSAndroid Build Coastguard Worker 372*cda5da8dSAndroid Build Coastguard Worker name is the name of the document element type, public_id the 373*cda5da8dSAndroid Build Coastguard Worker public identifier of the DTD (or None if none were supplied) 374*cda5da8dSAndroid Build Coastguard Worker and system_id the system identfier of the external subset (or 375*cda5da8dSAndroid Build Coastguard Worker None if none were supplied).""" 376*cda5da8dSAndroid Build Coastguard Worker 377*cda5da8dSAndroid Build Coastguard Worker def endDTD(self): 378*cda5da8dSAndroid Build Coastguard Worker """Signals the end of DTD declarations.""" 379*cda5da8dSAndroid Build Coastguard Worker 380*cda5da8dSAndroid Build Coastguard Worker def startCDATA(self): 381*cda5da8dSAndroid Build Coastguard Worker """Reports the beginning of a CDATA marked section. 382*cda5da8dSAndroid Build Coastguard Worker 383*cda5da8dSAndroid Build Coastguard Worker The contents of the CDATA marked section will be reported 384*cda5da8dSAndroid Build Coastguard Worker through the characters event.""" 385*cda5da8dSAndroid Build Coastguard Worker 386*cda5da8dSAndroid Build Coastguard Worker def endCDATA(self): 387*cda5da8dSAndroid Build Coastguard Worker """Reports the end of a CDATA marked section.""" 388