U AT^.@sddlZddlZdZdZdZdZdZdZdZ d Z Gd d d ej j Z Gd d d ZGdddZGddde ZdZdddZdddZdS)N START_ELEMENT END_ELEMENTCOMMENTSTART_DOCUMENT END_DOCUMENTPROCESSING_INSTRUCTIONIGNORABLE_WHITESPACE CHARACTERSc@seZdZdZdZd$ddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZddZd d!Zd"d#ZdS)%PullDOMNcCszddlm}||_ddg|_|j|_g|_|jj|_z|jj|_Wnt k rVYnX|dig|_ |j d|_ g|_ dS)Nr) XML_NAMESPACExml) Zxml.domr documentFactory firstEvent lastEvent elementStackappendpushpopAttributeError _ns_contexts_current_contextpending_events)selfrr r'/usr/lib64/python3.8/xml/dom/pulldom.py__init__s     zPullDOM.__init__cCs|jd}|jd=|SNr )r)rresultrrrr!s z PullDOM.popcCs ||_dSN)_locator)rZlocatorrrrsetDocumentLocator&szPullDOM.setDocumentLocatorcCsHt|dsg|_|j|pd|f|j|j|pr?rCrGrKrLrNr.rTrUrrrrr s& 9  r c@s$eZdZddZddZddZdS) ErrorHandlercCs t|dSr)printr exceptionrrrwarningszErrorHandler.warningcCs|dSrrr[rrrerrorszErrorHandler.errorcCs|dSrrr[rrr fatalErrorszErrorHandler.fatalErrorN)rVrWrXr]r^r_rrrrrYsrYc@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)DOMEventStreamcCs2||_||_||_t|jds&|j|_|dS)Nfeed)streamparserbufsizer$_slurpgetEventreset)rrbrcrdrrrrs  zDOMEventStream.__init__cCs.t|_|jtjjjd|j|jdSr;) r pulldomrcZ setFeaturer saxhandlerZfeature_namespacesZsetContentHandlerrSrrrrgszDOMEventStream.resetcCs0ddl}|jdtdd|}|r(|StdS)Nrz[DOMEventStream's __getitem__ method ignores 'pos' parameter. Use iterator protocol instead.) stacklevel)warningswarnDeprecationWarningrf IndexError)rposrmrcrrr __getitem__szDOMEventStream.__getitem__cCs|}|r|StdSr)rf StopIterationrrrrrr__next__szDOMEventStream.__next__cCs|SrrrSrrr__iter__szDOMEventStream.__iter__cCsl|}|g}|rh|\}}||kr&dS|tkr<|d||tkrP||n|tkr^|d=|}qdSr)rfr appendChildrr)rr8rBparentstokenZcur_noderrr expandNodes zDOMEventStream.expandNodecCs~|jjds|jj|j_|jjdsR|j|j}|sD|jdS|j|q|jjdd}|jjdd|jjd<|S)Nr+r) rhrrrbreadrdrcclosera)rbufrrrrrrfs    zDOMEventStream.getEventcCs|j|j|j|_|S)z Fallback replacement for getEvent() using the standard SAX2 interface, which means we slurp the SAX events into memory (no performance gain, but we are compatible to all SAX parsers). )rcparserb_emitrfrSrrrreszDOMEventStream._slurpcCs,|jjdd}|jjdd|jjd<|S)zn Fallback replacement for getEvent() that emits the events that _slurp() read previously. r+r)rhrrurrrrszDOMEventStream._emitcCs|j|`d|_d|_dS)z+clear(): Explicitly release parsing objectsN)rhrUrcrbrSrrrrU!s zDOMEventStream.clearN) rVrWrXrrgrsrvrwr{rfrerrUrrrrr`s  r`c@s4eZdZddZddZddZddZd d Zd S) SAX2DOMcCs2t|||||jd}|jd}||dSNr )r r:rrx)rr4r5r6curNode parentNoderrrr:*s  zSAX2DOM.startElementNScCs0t||||jd}|jd}||dSr)r r>rrx)rr4r6rrrrrr>0s  zSAX2DOM.startElementcCs4t||||jdd}|jd}||dSNrr+r )r rGrrrx)rrErFr8rrrrrG6s zSAX2DOM.processingInstructioncCs2t|||jdd}|jd}||dSr)r rKrrrxrrJr8rrrrrK<s  zSAX2DOM.ignorableWhitespacecCs2t|||jdd}|jd}||dSr)r rLrrrxrrrrrLBs  zSAX2DOM.charactersN)rVrWrXr:r>rGrKrLrrrrr(s ri?cCs@|dkr t}t|tr"t|d}n|}|s4tj}t|||S)Nrb)default_bufsize isinstancestropenr ri make_parserr`)Zstream_or_stringrcrdrbrrrrKs   rcCs6ddlm}t|}||}|s*tj}t|||S)Nr)StringIO)iorlenr rirr`)stringrcrrdr~rrr parseStringVs   r)NN)N)Zxml.saxr Zxml.sax.handlerrrrrrrrr riZContentHandlerr rYr`rrrrrrrrs"8\!