B /g^-@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|_y|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.7/xml/dom/pulldom.py__init__s     zPullDOM.__init__cCs|jd}|jd=|S)Nr )r)rresultrrrr!s z PullDOM.popcCs ||_dS)N)_locator)rZlocatorrrrsetDocumentLocator&szPullDOM.setDocumentLocatorcCsHt|dsg|_|j|pd|f|j|j|px|D]\}}||j||f<qWg|_|\}} |r|dkrr|j|} | rn| d| }n| }|jr|j||} q|||} n |jr|j| } n |d| } x|D]\}}|\} } | |kr | dkr| }nd| }|j | |}| |nX| rL|j| } | r.| d| }n| }|j | |}| |n|j | }| |||_ qWt| fdg|jd<|jd|_|| dS)Nzhttp://www.w3.org/2000/xmlns/r :r!zxmlns:)getattrZ_attrsr rdocumentZcreateElementNS buildDocument createElementitemsZcreateAttributeNSZsetAttributeNodeNScreateAttributesetAttributeNodevaluerrr)rnametagNameattrsZ xmlns_uriZ xmlns_attrsanamer1r%Z localnamer$nodeZa_uriZ a_localnameZqnameattrrrrstartElementNS3sP           zPullDOM.startElementNScCs&t|fdg|jd<|jd|_dS)Nr))rrr)rr2r3rrr endElementNSlszPullDOM.endElementNScCs~|jr|j|}n |d|}x0|D]$\}}|j|}||_||q*Wt|fdg|jd<|jd|_| |dS)Nr)) r+r-r,r.r/r1r0rrr)rr2r4r6r5r1r7rrr startElementps   zPullDOM.startElementcCs&t|fdg|jd<|jd|_dS)Nr))rrr)rr2rrr endElementszPullDOM.endElementcCsN|jr2|j|}t|fdg|jd<|jd|_nt|fdg}|j|dS)Nr))r+ createCommentrrrr)rsr6eventrrrcomments   zPullDOM.commentcCsR|jr4|j||}t|fdg|jd<|jd|_nt||fdg}|j|dS)Nr))r+createProcessingInstructionrrrr)rtargetdatar6r>rrrprocessingInstructions zPullDOM.processingInstructioncCs.|j|}t|fdg|jd<|jd|_dS)Nr))r+createTextNoderr)rcharsr6rrrignorableWhitespaces zPullDOM.ignorableWhitespacecCs.|j|}t|fdg|jd<|jd|_dS)Nr))r+rDr r)rrEr6rrr characterss zPullDOM.characterscCs$|jdkr ddl}|jjjj|_dS)Nr)rZxml.dom.minidomZdomZminidomZDocumentimplementation)rr rrr startDocuments zPullDOM.startDocumentc Cs|j||d}||_t|fdg|jd<|jd|_||x|jD]}|ddtkr|d\}}}|j||}t|f|d<nD|ddt kr|j |dd}t |f|d<nt d|dd||jd<||_qFWd|_|j S)Nr)rzUnknown pending event ) rZcreateDocumentr+rrrrrr@rr<AssertionErrorZ firstChild) rr%Ztagnamer6e_rArBnrrrr,s$     zPullDOM.buildDocumentcCs t|jfdg|jd<|dS)Nr))rr+rr)rrrr endDocumentszPullDOM.endDocumentcCs d|_dS)z.clear(): Explicitly release parsing structuresN)r+)rrrrclearsz PullDOM.clear)N)__name__ __module__ __qualname__rr+rrrr&r'r8r9r:r;r?rCrFrGrIr,rNrOrrrrr s& 9  r c@s$eZdZddZddZddZdS) ErrorHandlercCs t|dS)N)print)r exceptionrrrwarningszErrorHandler.warningcCs|dS)Nr)rrUrrrerrorszErrorHandler.errorcCs|dS)Nr)rrUrrr fatalErrorszErrorHandler.fatalErrorN)rPrQrRrVrWrXrrrrrSsrSc@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|jdS)Nr)) r pulldomr\Z setFeaturer saxZhandlerZfeature_namespacesZsetContentHandler)rrrrr`szDOMEventStream.resetcCs|}|r|StdS)N)r_ IndexError)rposrcrrr __getitem__szDOMEventStream.__getitem__cCs|}|r|StdS)N)r_ StopIteration)rrerrr__next__szDOMEventStream.__next__cCs|S)Nr)rrrr__iter__szDOMEventStream.__iter__cCsp|}|g}x\|rj|\}}||kr(dS|tkr>|d||tkrR||n|tkr`|d=|}qWdS)Nr )r_r appendChildrr)rr6r>parentstokenZcur_noderrr expandNodes zDOMEventStream.expandNodecCs|jjds|jj|j_x<|jjdsT|j|j}|sF|jdS|j|qW|jjdd}|jjdd|jjd<|S)Nr)r) rarrr[readr]r\closerZ)rbufrerrrr_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_)rrrrr^szDOMEventStream._slurpcCs,|jjdd}|jjdd|jjd<|S)zn Fallback replacement for getEvent() that emits the events that _slurp() read previously. r)r)rar)rrerrrrrszDOMEventStream._emitcCs|j|`d|_d|_dS)z+clear(): Explicitly release parsing objectsN)rarOr\r[)rrrrrOs zDOMEventStream.clearN) rPrQrRrr`rfrhrirmr_r^rrrOrrrrrYs rYc@s4eZdZddZddZddZddZd d Zd S) SAX2DOMcCs2t|||||jd}|jd}||dS)Nr )r r8rrj)rr2r3r4curNode parentNoderrrr8#s  zSAX2DOM.startElementNScCs0t||||jd}|jd}||dS)Nr rt)r r:rrj)rr2r4rurvrrrr:)s  zSAX2DOM.startElementcCs4t||||jdd}|jd}||dS)Nrr)r )r rCrrrj)rrArBr6rvrrrrC/s zSAX2DOM.processingInstructioncCs2t|||jdd}|jd}||dS)Nrr)r )r rFrrrj)rrEr6rvrrrrF5s  zSAX2DOM.ignorableWhitespacecCs2t|||jdd}|jd}||dS)Nrr)r )r rGrrrj)rrEr6rvrrrrG;s  zSAX2DOM.charactersN)rPrQrRr8r:rCrFrGrrrrrs!s rsi?cCs@|dkr t}t|tr"t|d}n|}|s4tj}t|||S)Nrb)default_bufsize isinstancestropenr rb make_parserrY)Zstream_or_stringr\r]r[rrrrqDs   rqcCs6ddlm}t|}||}|s*tj}t|||S)Nr)StringIO)ior}lenr rbr|rY)stringr\r}r]rprrr parseStringOs   r)NN)N)Zxml.saxr Zxml.sax.handlerrrrrrrrr rbZContentHandlerr rSrYrsrxrqrrrrrs"8U!