rfc@sdZddlmZmZmZddlmZmZmZddlm Z ddl m Z m Z ddl mZddlTejZejZejZejjZejjZejjZejjZejZi ejedd 6ejed d 6ejed d 6ejedd6ejedd6ejedd6ejedd6ejedd6ejedd6ZdefdYZdZdZ dfdYZ!eeefZ"d efd!YZ#d"efd#YZ$d$e$fd%YZ%d&e$fd'YZ&d(Z'd)e'Z(d*e!fd+YZ)d,fd-YZ*d.e*e!fd/YZ+d0e*e)fd1YZ,d2e-fd3YZ.d4e!fd5YZ/e0d6Z1e0d7Z2e0d8Z3e0d9Z4d:Z5d;S(<sFacility to use the Expat parser to load a minidom instance from a string or file. This avoids all the overhead of SAX and pulldom to gain performance. i(t xmlbuildertminidomtNode(tEMPTY_NAMESPACEt EMPTY_PREFIXtXMLNS_NAMESPACE(texpat(t _append_childt_set_attribute_node(t NodeFilter(t*tcdatatCDATAt enumerationtENUMtentitytENTITYtentitiestENTITIEStidtIDtidreftIDREFtidrefstIDREFStnmtokentNMTOKENtnmtokenstNMTOKENSt ElementInfocBsbeZd Zd dZdZdZdZdZdZ d Z d Z d Z RS(t _attr_infot_modelttagNamecCs||_g|_||_dS(N(R RR(tselfR tmodel((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt__init__As  cCs|j|j|jfS(N(RRR (R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt __getstate__FscCs|\|_|_|_dS(N(RRR (R!tstate((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt __setstate__IscCs\xR|jD]G}|d|kr |d}|ddkrBtdSt|dSq q WtjS(Niiit(R(Rt _typeinfo_mapRt_no_type(R!tanametinfott((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pytgetAttributeTypeLs cCstjS(N(RR)(R!t namespaceURIt localName((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pytgetAttributeTypeNSVscCs:|jr2|jd}|tjjtjjfkStSdS(Ni(RRR"t XML_CTYPE_ANYtXML_CTYPE_MIXEDtFalse(R!ttype((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pytisElementContentYs    cCs(|jr |jdtjjkStSdS(Ni(RRR"tXML_CTYPE_EMPTYR3(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pytisEmptyas cCs6x/|jD]$}|d|kr |ddkSq WtS(NiiR(RR3(R!R*R+((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pytisIdgscCs|j||fS(N(R8(R!teuritenametauriR*((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pytisIdNSms(s _attr_infos_modelstagNameN( t__name__t __module__t __slots__tNoneR#R$R&R-R0R5R7R8R<(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR>s       cCs|j||S(N(t_intern_setdefault(tbuilderts((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt_internqscCsd|kst|jd}|j}t|dkr|\}}}|||}d||f}|||}|||}n%|\}}t}|||}}||||||fS(Nt is%s:%s(tAssertionErrortsplitRAtlenR(RBtnametpartstinternturit localnametprefixtqname((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt_parse_ns_namets  t ExpatBuildercBs eZdZddZdZdZdZdZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZRS(sPDocument builder that uses Expat to build a ParsedXML.DOM document instance.cCsw|dkrtj}n||_|jjdk rNt|jj|_nd|_t|_d|_ |j dS(N( R@RtOptionst_optionstfiltertFilterVisibilityControllert_filterRt_finish_start_elementt_parsertreset(R!toptions((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR#s     cCs tjS(sCreate a new parser object.(Rt ParserCreate(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt createParserscCsh|jsa|j|_|jjj|_t|j_t|j_t|j_|j |jn|jS(s7Return the parser object, creating a new one if needed.( RXR\RKt setdefaultRAtTruet buffer_texttordered_attributestspecified_attributestinstall(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt getParsers    cCs@tjtdd|_|j|_|jj|_t|_dS(s6Free all data structures used during DOM construction.N( ttheDOMImplementationtcreateDocumentRR@tdocumenttcurNodet _elem_infoR3t_cdata(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRYs  cCs|j|_|j|_|j|_|j|_|jj rK|j |_ n|j |_ |jjrr|j|_n|jjr|j|_|j|_|j|_n |j|_|j|_|j|_|j|_|j|_ dS(s>Install the callbacks needed to build the DOM into the parser.N(!tstart_doctype_decl_handlertStartDoctypeDeclHandlertfirst_element_handlertStartElementHandlertend_element_handlertEndElementHandlert pi_handlertProcessingInstructionHandlerRSRtentity_decl_handlertEntityDeclHandlertnotation_decl_handlertNotationDeclHandlertcommentstcomment_handlertCommentHandlertcdata_sectionststart_cdata_section_handlertStartCdataSectionHandlertend_cdata_section_handlertEndCdataSectionHandlertcharacter_data_handler_cdatatCharacterDataHandlertcharacter_data_handlertexternal_entity_ref_handlertExternalEntityRefHandlertxml_decl_handlertXmlDeclHandlertelement_decl_handlertElementDeclHandlertattlist_decl_handlertAttlistDeclHandler(R!tparser((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRbs$              cCs|j}t}ykxT|jd}|s1Pn|j|d|rc|jjrc|j|nt}q|jdtWntk rnX|j}|j d|_ |S(sIParse a document from a file object, returning the document node.iiiti@N( RcR^treadtParseRftdocumentElementt _setup_subsetR3t ParseEscapeRYR@RX(R!tfileRt first_buffertbuffertdoc((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt parseFiles$      cCsa|j}y!|j|t|j|Wntk r@nX|j}|jd|_|S(s<Parse a document from a string, returning the document node.N( RcRR^RRRfRYR@RX(R!tstringRR((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt parseStrings     cCsD|jjr@t}|j||j}||jj_ndS(s/Load the internal subset if there might be one.N(RftdoctypetInternalSubsetExtractorRt getSubsettinternalSubset(R!Rt extractortsubset((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRs     cCs|jjj|||}|j|_t|j|||j_|jr|jj|tkrd|j_|jj d=d}d|j _ d|j _ n|r|dk rg|j_g|j_nd|j _d|j _|j|j _ndS(Ni(RftimplementationtcreateDocumentTypet ownerDocumentRRRVt acceptNodet FILTER_REJECTR@t childNodesRXRsRuRt_seqt notationsRxRqtend_doctype_decl_handlertEndDoctypeDeclHandler(R!t doctypeNametsystemIdtpublicIdthas_internal_subsetR((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRjs$   !       cCsO|jjr|j|j_n|j|j_|jp<|jsKt |_ ndS(N( RSRvRwRXRxRpRqRhRVRt_finish_end_element(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRs  cCs]|jj||}t|j||jrY|jj|tkrY|jj|ndS(N(RftcreateProcessingInstructionRRgRVRRt removeChild(R!ttargettdatatnode((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRp s!cCs|jj}|jrd|jrF|djtkrF|dj|dS|jj|}t |_n|r|djt kr|d}|j |}|j }||d<|dt__doc__R@R#R\RcRYRbRRRRjRRpR~RRrRtRwRzR|RRlRRWRnRRRRR(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRQs:                       RUcBseZdZdZdZdZdZi eje j 6ej e j 6ej e j6eje j6eje j6eje j6eje j6eje j6eje j6eje j6eje j6eje j 6Z!RS(soWrapper around a DOMBuilderFilter which implements the checks to make the whatToShow filter attribute work.RTcCs ||_dS(N(RT(R!RT((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR#scCsu|j|j}|jj|@rm|jj|}|tkrGtn|tkritdt |n|St SdS(Ns)startContainer() returned illegal value: ( t_nodetype_maskRRTt whatToShowRtFILTER_INTERRUPTRt_ALLOWED_FILTER_RETURNSt ValueErrortreprR(R!Rtmasktval((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRs   cCs|j|j}|jj|@r|jj|}|tkrGtn|tkr|j}x|j D]}|j |qgWt S|t krt dt|n|StSdS(Ns%acceptNode() returned illegal value: (RRRTRRRRRRRt appendChildRRRRR(R!RRRtparentR((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRs     (sfilter("R=R>RR?R#RRR t SHOW_ELEMENTRt ELEMENT_NODEtSHOW_ATTRIBUTEtATTRIBUTE_NODEt SHOW_TEXTRtSHOW_CDATA_SECTIONRtSHOW_ENTITY_REFERENCEtENTITY_REFERENCE_NODEt SHOW_ENTITYt ENTITY_NODEtSHOW_PROCESSING_INSTRUCTIONtPROCESSING_INSTRUCTION_NODEt SHOW_COMMENTt COMMENT_NODEt SHOW_DOCUMENTt DOCUMENT_NODEtSHOW_DOCUMENT_TYPEtDOCUMENT_TYPE_NODEtSHOW_DOCUMENT_FRAGMENTtDOCUMENT_FRAGMENT_NODEt SHOW_NOTATIONt NOTATION_NODER(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRUs$             t FilterCrutchcBseZdZdZRS(t_buildert_levelt _old_startt_old_endcCsOd|_||_|j}|j|_|j|_|j|_|j|_dS(Ni( RRRXRmRRoRRRn(R!RBR((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR# s      (s_builders_levels _old_starts_old_end(R=R>R?R#(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR sRcBs)eZdZdZdZdZRS(cCs>tj|||j}xdD]}t||dq WdS(NRqRxRR{R}R(sProcessingInstructionHandlersCommentHandlersCharacterDataHandlersStartCdataSectionHandlersEndCdataSectionHandlersExternalEntityRefHandler(RR#RXtsetattrR@(R!RBRRI((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR#s  cGs|jd|_dS(Ni(R(R!targs((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR$scGsZ|jdkrF|jj}|jj||j|_|j|_n|jd|_dS(Nii(RRRXRbRRmRRo(R!RR((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRn's   ((R=R>R?R#RRn(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRs RcBs eZdZdZdZRS(cGsB|jj}|j||jj|k r>|jd|_ndS(Ni(RRgRR(R!RR((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR4s  cGs`|jdkr?|j|jj_|j|jj_d|_n|jd|_|j|dS(Nii(RRRRXRmRRoR@(R!R((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRn:s  ((R=R>R?RRn(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR1s s8http://xml.python.org/entities/fragment-builder/internals %%s ]> &fragment-builder-internal;tFragmentBuildercBsPeZdZddZdZdZdZdZdZ dZ RS( sBuilder which constructs document fragments given XML source text and a context node. The context node is expected to provide information about the namespace declarations which are in scope at the start of the fragment. cCsM|jtkr$||_||_n|j|_||_tj||dS(N(RRtoriginalDocumentRRRQR#(R!RRZ((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR#bs     cCstj|d|_dS(N(RQRYR@tfragment(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRYks cCs|j|jS(sRParse a document fragment from a file object, returning the fragment node.(RR(R!R((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRosc Cs||_|j}|jj}d}|r|jp?|j}|jrdd|j|jf}q|jrd|j}qnd}|j}t |||f}y|j |dWn|j nX|j }|j |S(sMParse a document fragment from a string, returning the fragment node.RsPUBLIC "%s" "%s"s SYSTEM "%s"i( t_sourceRcR RRt_getDeclarationsRRt _getNSattrst_FRAGMENT_BUILDER_TEMPLATERRYR ( R!RRRtidentRtnsattrsRfR ((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRts,         cCs|jjj}d}|rxt|jjD]v}|jj|}|rY|d}nd||jf}|jrd||j|j f}q.d||j f}q.Wxt|j jD]}|j j|}|r|d}nd||jf}|jrd||j|j f}n5|j r=d||j f}nd ||j j f}|j rrd ||j f}n|d }qWn|S( sRe-create the internal subset from the DocumentType node. This is only needed if we don't already have the internalSubset as a string. Rs s%ss%s SYSTEM "%s">s %s(RRRRRtlengthtitemtnodeNameRRRt firstChildRR(R!RRCRtnotationR((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR s6      cCsdS(NR((R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRscCs|tkr|j}|j}|jj|}|j|_|jj|_|j|_z|j|j dWd||_||_d|_ XdSt j |||||SdS(Nii( t$_FRAGMENT_BUILDER_INTERNAL_SYSTEM_IDRfRgRXtExternalEntityParserCreateR tcreateDocumentFragmentR RR R@RQR(R!RRRRt old_documentt old_cur_nodeR((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRs        N( R=R>RR@R#RYRRR RR(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR Ys    $ t NamespacescBsDeZdZdZdZdZdZdZdZRS(s7Mix-in class for builders; adds support for namespaces.cCs g|_dS(N(t_ns_ordered_prefixes(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt_initNamespacesscCstjdd}t|_|S(s'Create a new namespace-handling parser.tnamespace_separatorRE(RR[R^tnamespace_prefixes(R!R((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR\s cCs/tj|||jjr+|j|_ndS(s.Insert the namespace-handlers onto the parser.N(RQRbRStnamespace_declarationststart_namespace_decl_handlertStartNamespaceDeclHandler(R!R((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRbs cCs|jj||fdS(s/Push this namespace declaration on our storage.N(RR(R!RNRL((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR#scCsd|kr*t||\}}}}nt}|}d}t}tj||||}|j|_t|j |||_ |j rIx|j D]\}}|rtj t |d|t |d}ntj dt dt}|jdj} || d<| d<|j} || d<| d<|j| dRRR\RbR#RRn(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRs     :tExpatBuilderNScBseZdZdZRS(s*Document builder that supports namespaces.cCstj||jdS(N(RQRYR(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRY5s (R=R>RRY(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR*2stFragmentBuilderNScBs eZdZdZdZRS(s*Fragment builder that supports namespaces.cCstj||jdS(N(R RYR(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRY=s cCsd}|j}g}x|rt|drx|jjD]p\}}||kr[q=n|j||r{d|}nd}|rd|||f}q=d||f}q=Wn|j}qW|S(sNReturn string of namespace attributes from this element and ancestors.Rt_ns_prefix_urisxmlns:R%s%s %s='%s's %s='%s'(RthasattrR,titemsRR(R!tattrsRRRNRLtdeclname((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRAs"      (R=R>RRYR(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR+:s RcBseZdZRS(sEException raised to short-circuit parsing in InternalSubsetExtractor.(R=R>R(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyR_sRcBsSeZdZdZdZdZdZdZdZ dZ dZ RS( sBXML processor which can rip out the internal document type subset.cCs|jS(s'Return the internal subset as a string.(R(R!((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRhscCs,ytj||Wntk r'nXdS(N(RQRR(R!R((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRls cCs,ytj||Wntk r'nXdS(N(RQRR(R!R((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRrs cCs|j|_|j|_dS(N(RjRkRRm(R!R((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRbxs cCsF|r9|j}g|_|jj|_|j|_n tdS(N(RcRRtDefaultHandlerRRR(R!RIRRRR((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRj|s   cCs@dj|jjddjdd}||_tdS(NRs s s (tjoinRtreplaceR(R!RC((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRs* cCs tdS(N(R(R!RIR/((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRsN( R=R>RR@RRRRRbRjRR(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRcs     cCsp|rt}n t}t|tr]t|d}z|j|}Wd|jXn|j|}|S(s{Parse a document, returning the resulting Document node. 'file' may be either a file name or an open file object. trbN(R*RQt isinstancet StringTypestopenRtclose(Rt namespacesRBtfptresult((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pytparses  cCs(|rt}n t}|j|S(sOParse a document from a string, returning the resulting Document node. (R*RQR(RR9RB((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyRs  cCsv|rt|}n t|}t|trct|d}z|j|}Wd|jXn|j|}|S(sParse a fragment of a document, given the context from which it was originally extracted. context should be the parent of the node(s) which are in the fragment. 'file' may be either a file name or an open file object. R4N(R+R R5R6R7RR8(RRR9RBR:R;((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt parseFragments cCs.|rt|}n t|}|j|S(sParse a fragment of a document from a string, given the context from which it was originally extracted. context should be the parent of the node(s) which are in the fragment. (R+R R(RRR9RB((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pytparseFragmentStrings cCs!|jrt|St|SdS(s,Create a builder based on an Options object.N(R9R*RQ(RZ((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyt makeBuilders  N(6Rtxml.domRRRRRRt xml.parsersRtxml.dom.minidomRRtxml.dom.NodeFilterR txml.dom.minicompatRRRtDOMBuilderFilterRRRRtgetDOMImplementationRdtTypeInfoR@R(tobjectRRDRPRQRRURRRRRR RR*R+t ExceptionRRR^R<RR=R>R?(((s,/usr/lib64/python2.7/xml/dom/expatbuilder.pyts`         3  I:  ud%,