U AT^.c@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 elementStackappendpushpopZAttributeError _ns_contexts_current_contextpending_events)selfr r r'/usr/lib64/python3.8/xml/dom/pulldom.py__init__s     zPullDOM.__init__cCs|jd}|jd=|SNr )r)rZresultrrrr! z PullDOM.popcCs ||_dSN)_locator)rZlocatorrrrsetDocumentLocator&zPullDOM.setDocumentLocatorcCsHt|dsg|_|j|pd|f|j|j|pZAssertionErrorZ firstChild) rr%Ztagnamer4ZeZ_rBrCZnrrrr*s$    zPullDOM.buildDocumentcCs t|jfdg|jd<|dSr8)rr)rrrrrr endDocumentszPullDOM.endDocumentcCs d|_dS)z.clear(): Explicitly release parsing structuresN)r)rMrrrclearsz PullDOM.clearr)__name__ __module__ __qualname__rr)rrrr&r'r6r:r<r=r@rDrIrKrLr*rNrOrrrrr s& 9  r c@s$eZdZddZddZddZdS) ErrorHandlercCs t|dSr)ZprintrZ exceptionrrrwarningr zErrorHandler.warningcC|dSrrrTrrrerrorr zErrorHandler.errorcCrVrrrTrrr fatalErrorr zErrorHandler.fatalErrorN)rPrQrRrUrWrXrrrrrSsrSc@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)DOMEventStreamcCs2||_||_||_t|jds&|j|_|dS)Nfeed)streamparserbufsizer#_slurpgetEventreset)rr[r\r]rrrrs  zDOMEventStream.__init__cCs.t|_|jtjjjd|j|jdSr8) r pulldomr\Z setFeaturer saxZhandlerZfeature_namespacesZsetContentHandlerrMrrrr`szDOMEventStream.resetcCs0ddl}|jdtdd|}|r(|StdS)Nrz[DOMEventStream's __getitem__ method ignores 'pos' parameter. Use iterator protocol instead.i)Z stacklevel)warningsZwarnZDeprecationWarningr_Z IndexError)rZposrcrcrrr __getitem__szDOMEventStream.__getitem__cCs|}|r|StdSr)r_Z StopIterationrrdrrr__next__szDOMEventStream.__next__cCs|SrrrMrrr__iter__r zDOMEventStream.__iter__cCsl|}|g}|rh|\}}||kr&dS|tkr<|d||tkrP||n|tkr^|d=|}qdSr)r_r appendChildrr)rr4r?ZparentsZtokenZcur_noderrr expandNodes zDOMEventStream.expandNodecCs~|jjds|jj|j_|jjdsR|j|j}|sD|jdS|j|q|jjdd}|jjdd|jjd<|S)Nr(r) rarrr[Zreadr]r\ZcloserZ)rbufrdrrrr_s    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). )r\parser[_emitr_rMrrrr^szDOMEventStream._slurpcCs,|jjdd}|jjdd|jjd<|S)zn Fallback replacement for getEvent() that emits the events that _slurp() read previously. r(r)rarrfrrrrmszDOMEventStream._emitcCs|j|`d|_d|_dS)z+clear(): Explicitly release parsing objectsN)rarOr\r[rMrrrrO!s zDOMEventStream.clearN) rPrQrRrr`rergrhrjr_r^rmrOrrrrrYs  rYc@s4eZdZddZddZddZddZd d Zd S) SAX2DOMcCs2t|||||jd}|jd}||dSNr i)r r6rri)rr0r1r2curNode parentNoderrrr6*s  zSAX2DOM.startElementNScCs0t||||jd}|jd}||dSro)r r<rri)rr0r2rprqrrrr<0s  zSAX2DOM.startElementcCs4t||||jdd}|jd}||dSNrr(r )r rDrrri)rrBrCr4rqrrrrD6s zSAX2DOM.processingInstructioncC2t|||jdd}|jd}||dSrr)r rIrrrirrHr4rqrrrrI<  zSAX2DOM.ignorableWhitespacecCrsrr)r rKrrrirtrrrrKBruzSAX2DOM.charactersN)rPrQrRr6r<rDrIrKrrrrrn(s rni?cCs@|dkr t}t|tr"t|d}n|}|s4tj}t|||S)NZrb)default_bufsizeZ isinstanceZstrZopenr rb make_parserrY)Zstream_or_stringr\r]r[rrrrlKs   rlcCs6ddlm}t|}||}|s*tj}t|||S)Nr)StringIO)ZiorxZlenr rbrwrY)Zstringr\rxr]rkrrr parseStringVs   ry)NNr)Zxml.saxr Zxml.sax.handlerrrrrrrrrrbZContentHandlerr rSrYrnrvrlryrrrrZs"8\!