Wc1csdZddlmZddlmZmZGddZGddeZGdd ZGd d Z Gd d Z Gdde Z dZ e dkr e dSdS)z]An XML Reader is the SAX 2 name for an XML parser. XML Parsers should be based on this code. )handler)SAXNotSupportedExceptionSAXNotRecognizedExceptioncsleZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdS) XMLReadera%Interface for reading an XML document using callbacks. XMLReader is the interface that an XML parser's SAX2 driver must implement. This interface allows an application to set and query features and properties in the parser, to register event handlers for document processing, and to initiate a document parse. All SAX interfaces are assumed to be synchronous: the parse methods must not return until parsing is complete, and readers must wait for an event-handler callback to return before reporting the next event.cstj|_tj|_tj |_tj|_dSN) rZContentHandler _cont_handlerZ DTDHandler _dtd_handlerZEntityResolver _ent_handlerZ ErrorHandler _err_handlerself */usr/lib64/python3.12/xml/sax/xmlreader.py__init__zXMLReader.__init__sL$335#..0#224#002ctd)zAParse an XML document from a system identifier or an InputSource. This method must be implemented!ZNotImplementedErrorr source r parsezXMLReader.parses!"DEErc|jS)z#Returns the current ContentHandler.rr r r getContentHandlerzXMLReader.getContentHandler"s!!!rc||_dS)z:Registers a new object to receive document content events.Nrr rrr setContentHandlerzXMLReader.setContentHandler&s$rcr)z Returns the current DTD handler.rr r r getDTDHandlerzXMLReader.getDTDHandler*   rcr)z7Register an object to receive basic DTD-related events.Nrrrr setDTDHandlerzXMLReader.setDTDHandler.#rcr)z#Returns the current EntityResolver.rr r r getEntityResolverzXMLReader.getEntityResolver2rrcr)z0Register an object to resolve external entities.Nr")r Zresolverrr setEntityResolverzXMLReader.setEntityResolver6s$rcr)z!Returns the current ErrorHandler.r r r r getErrorHandlerzXMLReader.getErrorHandler:rrcr)z3Register an object to receive error-message events.Nr%rrr setErrorHandlerzXMLReader.setErrorHandler>r!rcr)aHAllow an application to set the locale for errors and warnings. SAX parsers are not required to provide localization for errors and warnings; if they cannot support the requested locale, however, they must raise a SAX exception. Applications may request a locale change in the middle of a parse.zLocale support not implemented)r)r Zlocalerr setLocalezXMLReader.setLocaleBs''GHHrc"td|z)z1Looks up and returns the state of a SAX2 feature.Feature '%s' not recognizedrr namerr getFeaturezXMLReader.getFeatureK'(E(LMMrcr))z!Sets the state of a SAX2 feature.r*r+)r r-Zstate r setFeaturezXMLReader.setFeatureOr/rcr))z2Looks up and returns the value of a SAX2 property.Property '%s' not recognizedr+r,rr getPropertyzXMLReader.getPropertyS'(F(MNNrcr))z"Sets the value of a SAX2 property.r2r+)r r-Zvaluer0r setPropertyzXMLReader.setPropertyWr4rN)__name__ __module__ __qualname____doc__rrrrrr r#r$r&r'r(r.r1r3r5rr rr s  333 FFF"""%%%!!!$$$!!!%%%!!!$$$IIINNNNNNOOOOOOOOrrcs8eZdZdZd dZdZdZdZdZdZ d S) IncrementalParserasThis interface adds three extra methods to the XMLReader interface that allow XML parsers to support incremental parsing. Support for this interface is optional, since not all underlying XML parsers support this functionality. When the parser is instantiated it is ready to begin accepting data from the feed method immediately. After parsing has been finished with a call to close the reset method must be called to make the parser ready to accept new data, either from feed or using the parse method. Note that these methods must _not_ be called during parsing, that is, after parse has been called and before it returns. By default, the class also implements the parse method of the XMLReader interface using the feed, close and reset methods of the IncrementalParser interface as a convenience to SAX 2.0 driver writers.csB||_tj|dSr)_bufsizerr)r Zbufsizerr rzIncrementalParser.__init__os  4    rcsbddlm}|j|}|j||j }||j }|j |j}|r1|j||j |j}|r1|jdS)Nr)saxutils) r>Zprepare_input_source prepareParsergetCharacterStream getByteStreamZreadr=feedclose)r rr>ZfileZbuffers r rzIncrementalParser.parsess..v6 6""((* <'')D4==)f IIf  YYt}}-Ff rcr)aThis method gives the raw XML data in the data parameter to the parser and makes it parse the data, emitting the corresponding events. It is allowed for XML constructs to be split across several calls to feed. feed may raise SAXException.rr)r Zdatarr rCzIncrementalParser.feeds""DEErcr)ztThis method is called by the parse implementation to allow the SAX 2.0 driver to prepare itself for parsing.z!prepareParser must be overridden!rrrr r@zIncrementalParser.prepareParsers""EFFrcr)aThis method is called when the entire XML document has been passed to the parser through the feed method, to notify the parser that there are no more data. This allows the parser to do the final checks on the document and empty the internal data buffer. The parser will not be ready to parse another document until the reset method has been called. close may raise SAXException.rrr r r rDzIncrementalParser.closes""DEErcr)zThis method is called after close has been called to reset the parser so that it is ready to parse new documents. The results of calling parse or feed after close without calling reset are undefined.rrr r r resetzIncrementalParser.resets ""DEErN)r<) r6r7r8r9rrrCr@rDrEr:rr r;r;[s&!!!!   FFFGGG F F FFFFFFrr;cs*eZdZdZdZdZdZdZdS)LocatorzInterface for associating a SAX event with a document location. A locator object will return valid results only during calls to DocumentHandler methods; at any other time, the results are unpredictable.cdS)z6Return the column number where the current event ends.r:r r r getColumnNumberzLocator.getColumnNumberrrcrG)z4Return the line number where the current event ends.rHr:r r r getLineNumberzLocator.getLineNumberrJrcrG)z3Return the public identifier for the current event.Nr:r r r getPublicIdzLocator.getPublicIdtrcrG)z3Return the system identifier for the current event.Nr:r r r getSystemIdzLocator.getSystemIdrMrN)r6r7r8r9rIrKrLrNr:rr rFrFsZ"" rrFcsVeZdZdZddZdZdZdZdZdZ d Z d Z d Z d Z d ZdS) InputSourceanEncapsulation of the information needed by the XMLReader to read entities. This class may include information about the public identifier, system identifier, byte stream (possibly with character encoding information) and/or the character stream of an entity. Applications will create objects of this class for use in the XMLReader.parse method and for returning from EntityResolver.resolveEntity. An InputSource belongs to the application, the XMLReader is not allowed to modify InputSource objects passed to it from the application, although it may make copies and modify those.NcsL||_d|_d|_d|_d|_dSr)_InputSource__system_id_InputSource__public_id_InputSource__encoding_InputSource__bytefile_InputSource__charfiler Z system_idrr rzInputSource.__init__s+$rcr)z/Sets the public identifier of this InputSource.NrQ)r Z public_idrr setPublicIdzInputSource.setPublicId$rcr)z2Returns the public identifier of this InputSource.rVr r r rLzInputSource.getPublicIdrcr)z/Sets the system identifier of this InputSource.NrPrUrr setSystemIdzInputSource.setSystemIdrXrcr)z2Returns the system identifier of this InputSource.rZr r r rNzInputSource.getSystemIdrYrcr)a4Sets the character encoding of this InputSource. The encoding must be a string acceptable for an XML encoding declaration (see section 4.3.3 of the XML recommendation). The encoding attribute of the InputSource is ignored if the InputSource also contains a character stream.NrR)r Zencodingrr setEncodingzInputSource.setEncoding#rcr)z/Get the character encoding of this InputSource.r\r r r getEncodingzInputSource.getEncoding rcr)aSet the byte stream (a Python file-like object which does not perform byte-to-character conversion) for this input source. The SAX parser will ignore this if there is also a character stream specified, but it will use a byte stream in preference to opening a URI connection itself. If the application knows the character encoding of the byte stream, it should set it with the setEncoding method.NrS)r Zbytefilerr setByteStreamzInputSource.setByteStreams#rcr)zGet the byte stream for this input source. The getEncoding method will return the character encoding for this byte stream, or None if unknown.rar r r rBzInputSource.getByteStreams rcr)a^Set the character stream for this input source. (The stream must be a Python 2.0 Unicode-wrapped file-like that performs conversion to Unicode strings.) If there is a character stream specified, the SAX parser will ignore any byte stream and will not attempt to open a URI connection to the system identifier.NrT)r Zcharfilerr setCharacterStreamzInputSource.setCharacterStreamr^rcr)z/Get the character stream for this input source.rcr r r rAzInputSource.getCharacterStreamr`rr)r6r7r8r9rrWrLr[rNr]r_rbrBrdrAr:rr rOrOs B B    %%%   %%%   ### # # ####rrOcsveZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZddZdZdZdZdS)AttributesImplcr)zQNon-NS-aware implementation. attrs should be of the form {name : value}.N_attrs)r attrsrr rzAttributesImpl.__init__s rc0t|jSrZlenrgr r r getLengthzAttributesImpl.getLength4;;rcrG)NZCDATAr:r,rr getTypezAttributesImpl.getType!swrc&|j|Srrfr,rr getValuezAttributesImpl.getValue${{4  rcrnrrfr,rr getValueByQNamezAttributesImpl.getValueByQName'rprc<||jvr t||SrrgKeyErrorr,rr getNameByQNamezAttributesImpl.getNameByQName* t{{ " "4.  rcrrrrsr,rr getQNameByNamezAttributesImpl.getQNameByName/rvrcNt|jjSrlistrgkeysr r r getNameszAttributesImpl.getNames4DKK$$&''rcrxrryr r r getQNameszAttributesImpl.getQNames7r}rcrirrjr r r __len__zAttributesImpl.__len__:rlrcrnrrfr,rr __getitem__zAttributesImpl.__getitem__=rprcrxrryr r r r{zAttributesImpl.keys@r}rcs||jvSrrfr,rr __contains__zAttributesImpl.__contains__Cst{{""rNcs<|jj||Sr)rgget)r r-Z alternativer0r rzAttributesImpl.getFs{{t[11rcs:|j|jSr) __class__rgr r r copyzAttributesImpl.copyIs~~dkk**rcrxr)rzrgitemsr r r rzAttributesImpl.itemsLsDKK%%'((rcrxr)rzrgvaluesr r r rzAttributesImpl.valuesOsDKK&&())rr)r6r7r8rrkrmrorqrurwr|r~rrr{rrrrrr:rr reres    !!!!!!  ((((((   !!!(((###2222+++)))*****rrecs2eZdZdZdZdZdZdZdZdS)AttributesNSImplcs"||_||_dS)zNS-aware implementation. attrs should be of the form {(ns_uri, lname): value, ...}. qnames of the form {(ns_uri, lname): qname, ...}.N)rg_qnames)r rhZqnamesr0r rzAttributesNSImpl.__init__Vs   rcs|jjD]\}}||ks |j|cSt|r)rrrgrtr r-ZnsnameZqname r rqz AttributesNSImpl.getValueByQName^sK#||113 + +OVU}}{{6****tnrcst|jjD]\}}||ks |cSt|r)rrrtrrr ruzAttributesNSImpl.getNameByQNamees?#||113  OVU}} tnrcrnr)rr,rr rwzAttributesNSImpl.getQNameByNamels||D!!rcrxr)rzrrr r r r~zAttributesNSImpl.getQNamesosDLL'')**rcsP|j|j|jSr)rrgrr r r rzAttributesNSImpl.copyrs~~dkk4<<88rN) r6r7r8rrqrurwr~rr:rr rrTsn"""+++99999rrcsNtttdSr)rr;rFr:rr _testrvs KK IIIIrZ__main__N)r9r?rZ _exceptionsrrrr;rFrOrerrr6r:rr rsj""LLLLLLLL NONONONONONONO`FFFFFFFFFF FFFFT0UUUUUUUr:*:*:*:*:*:*:*|99999~99D  z EGGGGr