B /g^-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|_y|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.7/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|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!z:r"zxmlns:)ZgetattrZ_attrsr!rdocumentZcreateElementNS buildDocument createElementitemsZcreateAttributeNSZsetAttributeNodeNScreateAttributesetAttributeNodevaluerrr)rnametagNameattrsZ xmlns_uriZ xmlns_attrsanamer/r%Z localnamer$nodeZa_uriZ a_localnameZqnameattrrrrstartElementNS3sP           zPullDOM.startElementNScC&t|fdg|jd<|jd|_dSNr(rrr)rr0r1rrr endElementNSlzPullDOM.endElementNScCs~|jr|j|}n |d|}x0|D]$\}}|j|}||_||q*Wt|fdg|jd<|jd|_| |dSr8) r)r+r*r,r-r/r.rrr)rr0r2r4r3r/r5rrr startElementps   zPullDOM.startElementcCr7r8r9)rr0rrr endElementr;zPullDOM.endElementcCsN|jr2|j|}t|fdg|jd<|jd|_nt|fdg}|j|dSr8)r) createCommentrrrr)rZsr4eventrrrcomments   zPullDOM.commentcCsR|jr4|j||}t|fdg|jd<|jd|_nt||fdg}|j|dSr8)r)createProcessingInstructionrrrr)rtargetdatar4r?rrrprocessingInstructions zPullDOM.processingInstructioncC.|j|}t|fdg|jd<|jd|_dSr8)r)createTextNoderrrcharsr4rrrignorableWhitespace zPullDOM.ignorableWhitespacecCrEr8)r)rFrrrGrrr charactersrJzPullDOM.characterscCs$|jdkr ddl}|jjjj|_dS)Nr)r Zxml.dom.minidomZdomZminidomZDocumentZimplementation)rr rrr startDocumentrzPullDOM.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 ) r ZcreateDocumentr)rrrrrrArr>ZAssertionErrorZ 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.resetcCs|}|r|StdSr)r_Z IndexError)rZposrcrrr __getitem__zDOMEventStream.__getitem__cCs|}|r|StdSr)r_Z StopIterationrrcrrr__next__rezDOMEventStream.__next__cCs|SrrrMrrr__iter__r zDOMEventStream.__iter__cCsp|}|g}x\|rj|\}}||kr(dS|tkr>|d||tkrR||n|tkr`|d=|}qWdSr)r_r appendChildrr)rr4r?ZparentsZtokenZcur_noderrr expandNodes zDOMEventStream.expandNodecCs|jjds|jj|j_x<|jjdsT|j|j}|sF|jdS|j|qW|jjdd}|jjdd|jjd<|S)Nr(r) rarrr[Zreadr]r\ZcloserZ)rbufrcrrrr_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[rMrrrrOs zDOMEventStream.clearN) rPrQrRrr`rdrgrhrjr_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<)s  zSAX2DOM.startElementcCs4t||||jdd}|jd}||dSNrr(r )r rDrrri)rrBrCr4rqrrrrD/s zSAX2DOM.processingInstructioncC2t|||jdd}|jd}||dSrr)r rIrrrirrHr4rqrrrrI5  zSAX2DOM.ignorableWhitespacecCrsrr)r rKrrrirtrrrrK;ruzSAX2DOM.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[rrrrlDs   rlcCs6ddlm}t|}||}|s*tj}t|||S)Nr)StringIO)ZiorxZlenr rbrwrY)Zstringr\rxr]rkrrr parseStringOs   ry)NNr)Zxml.saxr Zxml.sax.handlerrrrrrrrrrbZContentHandlerr rSrYrnrvrlryrrrrZs"8U!