U e5d)@sdZddlZddlZddlmZmZmZmZddlTddl m Z m Z ej j jej j jfZGdddej j Z ee dd d ee d d d ee d dd ddZddZddZddZddZGddde ZGddde Zeeddd eed dd eed d!d Gd"d#d#eZeed$d%d eZGd&d'd'eZeddZGd(d)d)e Zeed*d+d eed d,d d-d.ZGd/d0d0Z Gd1d2d2e e Z!Gd3d4d4e e Z"ee"d$d5d Gd6d7d7e"Z#ee#d8d9d ee#d:d;d dd?Z%Gd@dAdAe"Z&GdBdCdCe#Z'GdDdEdEeZ(ee(d$dFd GdGdHdHZ)GdIdJdJe)e e Z*GdKdLdLe)e Z+GdMdNdNe)e e Z,GdOdPdPe Z-GdQdRdReZ.dSdTZ/GdUdVdVe e Z0ee0dWdXd dYdZZ1d[d\Z2d]d^Z3ded_d`Z4dfdadbZ5dgdcddZ6dS)hacSimple implementation of the Level 1 DOM. Namespaces and other minor Level 2 features are also supported. parse("foo.xml") parseString("") Todo: ===== * convenience methods for getting elements and text. * more testing * bring some of the writer and linearizer code into conformance with this interface * SAX 2 namespaces N)EMPTY_NAMESPACE EMPTY_PREFIXXMLNS_NAMESPACEdomreg)*)DOMImplementationLS DocumentLSc@seZdZdZdZdZdZdZeZ ddZ d2ddZ d3dd Z d d Z d d ZddZddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Z dS)4NodeNcCsdS)NTselfr r '/usr/lib64/python3.8/xml/dom/minidom.py__bool__+sz Node.__bool__cCs|dd|SN) toprettyxml)r encodingr r r toxml.sz Node.toxml  cCsx|dkrt}ntjt|ddd}|jtjkrH||d|||n||d|||dkrh|S| SdS)Nxmlcharrefreplacer)rerrorsnewliner) ioStringIO TextIOWrapperBytesIOnodeTyper DOCUMENT_NODEwritexmlgetvaluedetach)r indentnewlrwriterr r r r1s   zNode.toprettyxmlcCs t|jSN)bool childNodesr r r r hasChildNodesCszNode.hasChildNodescCs|jSr%r'r r r r _get_childNodesFszNode._get_childNodescCs|jr|jdSdSNrr)r r r r _get_firstChildIszNode._get_firstChildcCs|jr|jdSdSNr)r r r r _get_lastChildMszNode._get_lastChildcCs |j|jkr,t|jD]}|||q|S|j|jkrTtjdt |t |f|j dk rj|j ||dkr~| |nz|j |}Wntk rtjYnX|jtkrt||j||||_||_|r|j|d}||_||_nd|_||_ |S)N%s cannot be child of %s)rDOCUMENT_FRAGMENT_NODEtupler' insertBefore_child_node_typesxmldomHierarchyRequestErrrepr parentNode removeChild appendChildindex ValueError NotFoundErr_nodeTypes_with_children_clear_id_cacheinsert nextSiblingpreviousSibling)r newChildrefChildcr=noder r r r4Qs8      zNode.insertBeforecCs|j|jkr*t|jD]}||q|S|j|jkrTtjdt |t |fn|jt krft ||j dk r||j |t||d|_|SNr0)rr2r3r'r<r5r6r7r8r9r@rAr:r; _append_childrC)r rHrGr r r r<qs       zNode.appendChildcCs|j|jkr(|j}|||||S|j|jkrPtjdt |t |f||kr\dS|j dk rr|j |z|j |}Wnt k rtjYnX||j |<||_ d|_ |jtks|jtkrt||j|_|j|_d|_d|_|jr||j_|jr||j_|SrI)rr2rCr;r4r5r6r7r8r9r:r'r=r>r?r@rArD)r rEoldChildrFr=r r r replaceChilds@        zNode.replaceChildcCsz|j|Wntk r.tjYnX|jdk rD|j|j_|jdk rX|j|j_d|_|_|jt krvt |d|_ |Sr%) r'remover>r6r7r?rCrDrr@rAr:r rKr r r r;s      zNode.removeChildcCsg}|jD]}|jtjkr|jsJ|r0|j|d_|jr@|j|j_|q|r|dj|jkr|d}|j|j|_|j|_|jr||j_|q||q |||jtj kr | q ||jdd<dSr-) r'rr TEXT_NODEdatarCrDunlinkappend ELEMENT_NODE normalize)r LchildrHr r r rTs*          zNode.normalizecCst|||jp|Sr%) _clone_node ownerDocument)r deepr r r cloneNodeszNode.cloneNodecCs|jj||Sr%)rXimplementation hasFeaturer featureversionr r r isSupportedszNode.isSupportedcCsdSr%r r r r r _get_localNameszNode._get_localNamecCs||kSr%r r otherr r r isSameNodeszNode.isSameNodecCs||dr|SdSdSr%)r`r r^r r r getInterfaces zNode.getInterfacec Cs0z|j|dWSttfk r*YdSXdSr+) _user_dataAttributeErrorKeyErrorr keyr r r getUserDataszNode.getUserDatacCsnd}z |j}Wntk r,i}||_YnX||krB||d}|dkr^d}|dk rj||=n ||f||<|Sr+)rgrh)r rkrPhandlerolddr r r setUserDatas    zNode.setUserDatacCsDt|dr@t|jD]&\}\}}|dk r||||||qdS)Nrg)hasattrlistrgitemsZhandle)r operationsrcZdstrkrPrmr r r _call_user_data_handlers zNode._call_user_data_handlercCs>d|_|_|jr.|jD] }|qt|_d|_d|_dSr%)r:rXr'rQNodeListrDrC)r rVr r r rQs   z Node.unlinkcCs|Sr%r r r r r __enter__szNode.__enter__cCs |dSr%)rQ)r ZetZevtbr r r __exit__sz Node.__exit__)N)rrN)!__name__ __module__ __qualname__ namespaceURIr:rXrCrDrprefixrrrr(r*r,r/r4r<rLr;rTrZr`rardrfrlrprvrQrxrzr r r r r "s:      r firstChildzFirst child node, or None.)doc lastChildzLast child node, or None. localNamez"Namespace-local name of this node.cCs2|j}|r|d}||_||_||||_dSr-)r'rDrCrRr:)r rHr'Zlastr r r rJs rJcCs$|dk r |jtjkrdS|j}qdSNTF)rr rr:rHr r r _in_document&s  rcCs6|r2|dddddddd}||d S) zWrites datachars to writer.&z&z>N)replacewrite)r$rPr r r _write_data.srcCsD|jD]8}|jtjkr2|dks(|j|kr2||t|||q|SNr)r'rr rStagNamerR_get_elements_by_tagName_helper)parentnamercrHr r r r5s   rcCsX|jD]L}|jtjkr|dks(|j|krD|dks:|j|krD||t||||q|Sr)r'rr rSrr~rR"_get_elements_by_tagName_ns_helper)rZnsURIrrrHr r r r=s   rc@sJeZdZejZdZdZdZdZ ej ej ej ej ejejejfZddZdS)DocumentFragmentz#document-fragmentNcCs t|_dSr%)rwr'r r r r __init__TszDocumentFragment.__init__)r{r|r}r r2rnodeName nodeValue attributesr:rSrOCDATA_SECTION_NODEENTITY_REFERENCE_NODEPROCESSING_INSTRUCTION_NODE COMMENT_NODE NOTATION_NODEr5rr r r r rFsrc@seZdZdZejZdZdZdZ ej ej fZ e ddfddZddZdd Zd d Zd d ZeeeZZddZddZeeeZZddZddZeeeZddZddZddZdS)Attr)_name_valuer~_prefixr' _localNamerX ownerElementNFcCs2d|_||_||_||_t|_|jtdSr%)rrr~rrwr'rRText)r qNamer~rrr r r rbs z Attr.__init__cCs4z|jWStk r.|jdddYSXdSN:r1r.)rrhrsplitr r r r raoszAttr._get_localNamecCs|jSr%) specifiedr r r r _get_specifieduszAttr._get_specifiedcCs|jSr%)rr r r r _get_namexszAttr._get_namecCs||_|jdk rt|jdSr%)rrrAr valuer r r _set_name{s zAttr._set_namecCs|jSr%)rr r r r _get_valueszAttr._get_valuecCs6||_||jd_|jdk r&t|j||jd_dSr+)rr'rPrrArr r r _set_values    zAttr._set_valuecCs|jSr%)rr r r r _get_prefixszAttr._get_prefixcCsd|j}|dkr&|r&|tkr&tjd||_|dkr<|j}nd||jf}|jrZt|j||_ dS)Nxmlnsz5illegal use of 'xmlns' prefix for the wrong namespacez%s:%s) r~rr6r7 NamespaceErrrrrrAr)r rZnsuriZnewNamer r r _set_prefixs  zAttr._set_prefixcCsv|j}|dk rR|j|j=|j|j|jf=|jrRd|_|jd8_|jj d8_ |j D] }| qX|j dd=dS)NFr1) r_attrsr_attrsNSr~r_is_id_magic_id_nodesrX_magic_id_countr'rQ)r elemrVr r r rQs   z Attr.unlinkcCsf|jr dS|j}|j}|dks&|dkr*dS||}|dkr@dS|jrV||j|jS||jSdSr) rrXr_get_elem_infor~isIdNSrisIdrr rrinfor r r _get_isIds zAttr._get_isIdcCs\|j}|j}|dks|dkr tS||}|dkr6tS|jrL||j|jS||jSdSr%) rXr_no_typerr~getAttributeTypeNSrgetAttributeTyperrr r r _get_schemaTypes zAttr._get_schemaType) r{r|r} __slots__r ATTRIBUTE_NODErrrrrOrr5rrrarrrpropertyrrrrrrrrrrQrrr r r r rXs.   rrz True if this attribute is an ID.z'Namespace-local name of this attribute. schemaTypezSchema type for this attribute.c@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ d:ddZeZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Z dS); NamedNodeMapaThe attribute list is a transient interface to the underlying dictionaries. Mutations here will change the underlying element's dictionary. Ordering is imposed artificially and does not reflect the order of attributes as found in an input document. rr _ownerElementcCs||_||_||_dSr%r)r attrsZattrsNSrr r r rszNamedNodeMap.__init__cCs t|jSr%)lenrr r r r _get_lengthszNamedNodeMap._get_lengthcCs4z|t|j|WStk r.YdSXdSr%)rrrkeys IndexErrorr r=r r r itemszNamedNodeMap.itemcCs*g}|jD]}||j|jfq|Sr%)rvaluesrRrrr rUrHr r r rsszNamedNodeMap.itemscCs0g}|jD]}||j|jf|jfq|Sr%)rrrRr~rrrr r r itemsNSszNamedNodeMap.itemsNScCs"t|tr||jkS||jkSdSr%) isinstancestrrrrjr r r __contains__s  zNamedNodeMap.__contains__cCs |jSr%)rrr r r r rszNamedNodeMap.keyscCs |jSr%)rrr r r r keysNSszNamedNodeMap.keysNScCs |jSr%)rrr r r r rszNamedNodeMap.valuesNcCs|j||Sr%rget)r rrr r r r szNamedNodeMap.getcCs:|jt|ddkrdSt|t|kt|t|kSdS)Nrr)rgetattridrbr r r _cmpszNamedNodeMap._cmpcCs||dkSr+rrbr r r __eq__szNamedNodeMap.__eq__cCs||dkSr+rrbr r r __ge__szNamedNodeMap.__ge__cCs||dkSr+rrbr r r __gt__szNamedNodeMap.__gt__cCs||dkSr+rrbr r r __le__szNamedNodeMap.__le__cCs||dkSr+rrbr r r __lt__!szNamedNodeMap.__lt__cCs"t|tr|j|S|j|SdSr%)rr3rr)r attname_or_tupler r r __getitem__$s  zNamedNodeMap.__getitem__cCsvt|trRz|j|}Wn0tk rHt|}|jj|_||YnX||_n t|tsdt d|}||dS)Nz%value must be a string or Attr object) rrrrirrrX setNamedItemr TypeError)r attnamerrHr r r __setitem__+s   zNamedNodeMap.__setitem__cCs(z |j|WStk r"YdSXdSr%)rrir rr r r getNamedItem:s zNamedNodeMap.getNamedItemcCs,z|j||fWStk r&YdSXdSr%)rrir r~rr r r getNamedItemNS@szNamedNodeMap.getNamedItemNScCsX||}|dk rJt|j|j|j=|j|j|jf=t|drFd|_ |St j dSNr) rrArrrrr~rrqrr6r7r?r rnr r r removeNamedItemFs    zNamedNodeMap.removeNamedItemcCsZ|||}|dk rLt|j|j|j|jf=|j|j=t|drHd|_ |St j dSr) rrArrr~rrrrqrr6r7r?r r~rrr r r removeNamedItemNSRs    zNamedNodeMap.removeNamedItemNScCstt|ts&tjdt|t|f|j|j}|r@| ||j|j<||j |j |j f<|j |_t|j|SrI)rrr6r7r8r9rrrrQrr~rrrrA)r rHrnr r r r^s   zNamedNodeMap.setNamedItemcCs ||Sr%)rr rHr r r setNamedItemNSkszNamedNodeMap.setNamedItemNScCs||}t|j|dSr%)rArrQ)r rrHr r r __delitem__ns zNamedNodeMap.__delitem__cCs|j|j|jfSr%rr r r r __getstate__sszNamedNodeMap.__getstate__cCs|\|_|_|_dSr%rr stater r r __setstate__vszNamedNodeMap.__setstate__)N)!r{r|r}__doc__rrrrrsrrrrrr__len__rrrrrrrrrrrrrrrrrr r r r rs<    rZlengthz$Number of nodes in the NamedNodeMap.c@s0eZdZdZddZddZddZdd Zd S) TypeInfo namespacercCs||_||_dSr%r)r rrr r r rszTypeInfo.__init__cCs2|jrd|jj|j|jfSd|jj|jfSdS)Nz<%s %r (from %r)>z<%s %r>)r __class__r{rr r r r __repr__s  zTypeInfo.__repr__cCs|jSr%)rr r r r rszTypeInfo._get_namecCs|jSr%)rr r r r _get_namespaceszTypeInfo._get_namespaceN)r{r|r}rrrrrr r r r rs rc@s eZdZdZejZdZeZ dZ ejej ej ej ejejfZeddfddZddZdd Zd d Zd d ZddZddZddZddZddZddZddZeZddZddZ d d!Z!e!Z"d"d#Z#d$d%Z$d&d'Z%d(d)Z&d*d+Z'd9d-d.Z(d/d0Z)d1d2Z*d3d4Z+d5d6Z,d7d8Z-dS):Element) rXr:rrrr~rr'rrrCrDNrcCsBd|_||_|_||_||_t|_d|_|_d|_ d|_ dSr%) r:rrrr~rwr'rCrDrr)r rr~rrr r r rs  zElement.__init__cCs|jdkri|_i|_dSr%)rrr r r r _ensure_attributess zElement._ensure_attributescCs4z|jWStk r.|jdddYSXdSr)rrhrrr r r r raszElement._get_localNamecCs|jSr%rr r r r _get_tagNameszElement._get_tagNamecCs@|jdk r&t|jD] }|qd|_d|_t|dSr%)rrrrrQrr )r attrr r r rQs   zElement.unlinkcCs8|jdkrdSz|j|jWStk r2YdSXdSr)rrri)r rr r r getAttributes  zElement.getAttributecCs<|jdkrdSz|j||fjWStk r6YdSXdSr)rrrirr r r getAttributeNSs  zElement.getAttributeNScCsV||}|dkr4t|}||_|j|_||n||jkrR||_|jrRt|dSr%)getAttributeNoderrrXsetAttributeNoderrA)r rrr r r r setAttributes   zElement.setAttributecCst|\}}|||}|dkrHt||||}||_|j|_||n4||jkrf||_|jrft||j|kr|||_||_ dSr%) _nssplitgetAttributeNodeNSrrrXr rrArr)r r~ qualifiedNamerr localnamer r r r setAttributeNSs     zElement.setAttributeNScCs|jdkrdS|j|Sr%r)r attrnamer r r r s zElement.getAttributeNodecCs|jdkrdS|j||fSr%)rrrr r r rs zElement.getAttributeNodeNScCs|jd|fkrtjd||j|jd}|dk rD|||j |j |j fd}|dk rt||k rt||t ||||k r|S||k r|SdS)Nzattribute node already owned) rr6r7ZInuseAttributeErrrrrrremoveAttributeNoderr~r_set_attribute_node)r r Zold1Zold2r r r r s    zElement.setAttributeNodecCsP|jdkrtjz|j|}Wntk r@tjYnX||dSr%)rr6r7r?rrir)r rr r r r removeAttributes  zElement.removeAttributecCsT|jdkrtjz|j||f}Wntk rDtjYnX||dSr%)rr6r7r?rir)r r~rr r r r removeAttributeNS%s  zElement.removeAttributeNScCs^|dkrtjz|j|jWntk r@tjYnXt|||j|_|Sr%) r6r7r?rrrirArQrXrr r r r.s zElement.removeAttributeNodecCs|jdkrdS||jkSNFrrr r r hasAttribute>s zElement.hasAttributecCs|jdkrdS||f|jkSr)rrr r r hasAttributeNSCs zElement.hasAttributeNScCst||tSr%rrwrr r r getElementsByTagNameHszElement.getElementsByTagNamecCst|||tSr%rrwrr r r getElementsByTagNameNSKs zElement.getElementsByTagNameNScCsd|jt|fS)Nz)rrr r r r rOszElement.__repr__rcCs||d|j|}|D],}|d|t|||j|dq$|jr|dt|jdkr|jdjt j t j fkr|jd |dddn4|||jD]}| |||||q|||d|j|fn|d |dS) Nrz %s="rrr1rrz%sz/>%s) rr_get_attributesrrrr'rrr rOrr)r r$r" addindentr#rZa_namerHr r r rRs*       zElement.writexmlcCs|t|j|j|Sr%)rrrrr r r r r!mszElement._get_attributescCs|jr dSdSdSrrr r r r hasAttributesqszElement.hasAttributescCs||}||dSr%)r setIdAttributeNode)r ridAttrr r r setIdAttributeys zElement.setIdAttributecCs|||}||dSr%)rr$)r r~rr%r r r setIdAttributeNS}s zElement.setIdAttributeNScCsj|dks||jstjt|dk r4tj|jsfd|_|jd7_|j j d7_ t |dS)NTr1) rdrr6r7r?_get_containing_entrefNoModificationAllowedErrrrrXrrA)r r%r r r r$s   zElement.setIdAttributeNode)rrr).r{r|r}rr rSrrrrrrrrOrrr5rrrrarrQr r rrr rr ZsetAttributeNodeNSrrrZremoveAttributeNodeNSrrrr rrr!r#r&r'r$r r r r rsT     rrz*NamedNodeMap of attributes on the element.z%Namespace-local name of this element.cCs8t||||j|j<||j|j|jf<||_dSr%)rArrrrr~rr)elementr r r r rs  rc@sfeZdZdZdZdZeZdZdZ ddZ ddZ dd Z d d Z d d ZddZddZddZdS) ChildlesszMixin that makes childless-ness easy to implement and avoids the complexity of the Node methods that deal with children. r NcCsdSr%r r r r r r,szChildless._get_firstChildcCsdSr%r r r r r r/szChildless._get_lastChildcCstj|jddS)Nz nodes cannot have childrenr6r7r8rrr r r r<szChildless.appendChildcCsdSrr r r r r r(szChildless.hasChildNodescCstj|jddSNz nodes do not have childrenr,r rErFr r r r4szChildless.insertBeforecCstj|jddSr-)r6r7r?rrNr r r r;szChildless.removeChildcCsdSr%r r r r r rTszChildless.normalizecCstj|jddSr-r,r rErKr r r rLszChildless.replaceChild)r{r|r}rrrZ EmptyNodeListr'rrr,r/r<r(r4r;rTrLr r r r r+sr+c@s\eZdZejZdZddZddZddZ e ee Z dd Z d d Z e e e Zdd dZdS)ProcessingInstructiontargetrPcCs||_||_dSr%r1)r r2rPr r r rszProcessingInstruction.__init__cCs|jSr%rPr r r r _get_nodeValuesz$ProcessingInstruction._get_nodeValuecCs ||_dSr%r3rr r r _set_nodeValuesz$ProcessingInstruction._set_nodeValuecCs|jSr%r2r r r r _get_nodeNamesz#ProcessingInstruction._get_nodeNamecCs ||_dSr%r6rr r r _set_nodeNamesz#ProcessingInstruction._set_nodeNamercCs|d||j|j|fdS)Nz %s%s)rr2rPr r$r"r"r#r r r rszProcessingInstruction.writexmlN)rrr)r{r|r}r rrrrr4r5rrr7r8rrr r r r r0s  r0c@sreZdZdZddZddZeZddZdd Ze eeZ Z d d Z d d Z ddZddZddZddZdS) CharacterData)_datarXr:rDrCcCs,d|_|_d|_|_d|_t|dSr)rXr:rDrCr;r rr r r r rs  zCharacterData.__init__cCs t|jSr%)rrPr r r r rszCharacterData._get_lengthcCs|jSr%r;r r r r _get_dataszCharacterData._get_datacCs ||_dSr%r<r rPr r r _set_dataszCharacterData._set_datacCs6|j}t|dkrd}nd}d|jj|dd|fS)N z...rzr)rPrrr{)r rPZ dotdotdotr r r rs  zCharacterData.__repr__cCsT|dkrtjd|t|jkr.tjd|dkrBtjd|j|||SNroffset cannot be negative#offset cannot be beyond end of datacount cannot be negativer6r7 IndexSizeErrrrPr offsetcountr r r substringDatas   zCharacterData.substringDatacCs|j||_dSr%r3)r argr r r appendDataszCharacterData.appendDatacCsZ|dkrtjd|t|jkr.tjd|rVd|jd|||j|df|_dS)NrrBrC%s%s%srE)r rHrKr r r insertData s    zCharacterData.insertDatacCsl|dkrtjd|t|jkr.tjd|dkrBtjd|rh|jd||j||d|_dSrArErGr r r deleteDatas   zCharacterData.deleteDatacCsr|dkrtjd|t|jkr.tjd|dkrBtjd|rnd|jd|||j||df|_dS)NrrBrCrDrMrE)r rHrIrKr r r replaceDatas    zCharacterData.replaceDataN)r{r|r}rrrrr=r?rrPrrrJrLrNrOrPr r r r r:s    r:zLength of the string data.c@sHeZdZdZejZdZdZddZ dddZ d d Z d d Z d dZ dS)rr z#textNcCs|dks|t|jkr"tjd|}|j|d|_|j|_|j}|jr~||jj kr~|dkrp|j |n|j |||jd||_|S)Nrzillegal offset value) rrPr6r7rFrrXrCr:r'r<r4)r rHZnewTextnextr r r splitText1s zText.splitTextrcCst|d||j|fdS)NrM)rrPr9r r r r@sz Text.writexmlcCs|jg}|j}|dk rB|jtjtjfkrB|d|j|j}qqBq|j}|dk rz|jtjtjfkrz||j|j}qHqzqHd |S)Nrr) rPrDrr rOrrBrCrRjoin)r rUrr r r _get_wholeTextEs zText._get_wholeTextcCs|j}|j}|dk r@|jtjtjfkr@|j}|||}q q@q |j}|sT|||dk r|jtjtjfkr|j}|||}qTqqT|r||_|SdSdSr%) r:rDrr rOrr;rCrP)r ZcontentrrrQr r r replaceWholeTextWs*   zText.replaceWholeTextcCsF|jrdSt|}|dkr"dS|j|}|dkr:dS|SdSr)rPstrip_get_containing_elementrXrisElementContent)r rrr r r !_get_isWhitespaceInElementContentss  z&Text._get_isWhitespaceInElementContent)rrr)r{r|r}rr rOrrrrRrrTrUrYr r r r r*s rZisWhitespaceInElementContentzKTrue iff this text node contains only whitespace and is in element content.Z wholeTextz.The text of all logically-adjacent text nodes.cCs*|j}|dk r&|jtjkr|S|j}qdSr%)r:rr rSrHrGr r r rWs  rWcCs*|j}|dk r&|jtjkr|S|j}qdSr%)r:rr rrZr r r r(s  r(c@s(eZdZejZdZddZdddZdS) Commentz#commentcCst|||_dSr%)r:rr;r>r r r rs zComment.__init__rcCs,d|jkrtd|d||j|fdS)Nz--z%'--' is not allowed in a comment nodez %s%s)rPr>rr9r r r rs zComment.writexmlN)rrr) r{r|r}r rrrrrr r r r r[sr[c@s$eZdZdZejZdZdddZdS) CDATASectionr z#cdata-sectionrcCs,|jddkrtd|d|jdS)Nz]]>rz$']]>' not allowed in a CDATA sectionz)rPfindr>rr9r r r rszCDATASection.writexmlN)rrr) r{r|r}rr rrrrr r r r r\sr\c@szeZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZdS)ReadOnlySequentialNamedNodeMap_seqr cCs ||_dSr%r_)r seqr r r rsz'ReadOnlySequentialNamedNodeMap.__init__cCs t|jSr%rr`r r r r rsz&ReadOnlySequentialNamedNodeMap.__len__cCs t|jSr%rbr r r r rsz*ReadOnlySequentialNamedNodeMap._get_lengthcCs"|jD]}|j|kr|SqdSr%)r`rrr r r rs  z+ReadOnlySequentialNamedNodeMap.getNamedItemcCs,|jD] }|j|kr|j|kr|SqdSr%)r`r~rrr r r rs z-ReadOnlySequentialNamedNodeMap.getNamedItemNScCs4t|tr|j|}n ||}|dkr0t||Sr%)rr3rrri)r Z name_or_tuplerHr r r rs    z*ReadOnlySequentialNamedNodeMap.__getitem__cCs4|dkr dSz |j|WStk r.YdSXdSr+)r`rrr r r rs  z#ReadOnlySequentialNamedNodeMap.itemcCstjddSNz"NamedNodeMap instance is read-onlyr6r7r)rr r r rsz.ReadOnlySequentialNamedNodeMap.removeNamedItemcCstjddSrcrdrr r r rsz0ReadOnlySequentialNamedNodeMap.removeNamedItemNScCstjddSrcrdrr r r rsz+ReadOnlySequentialNamedNodeMap.setNamedItemcCstjddSrcrdrr r r rsz-ReadOnlySequentialNamedNodeMap.setNamedItemNScCs|jgSr%r_r r r r rsz+ReadOnlySequentialNamedNodeMap.__getstate__cCs|d|_dSr+r_rr r r rsz+ReadOnlySequentialNamedNodeMap.__setstate__N)r )r{r|r}rrrrrrrrrrrrrrr r r r r^s  r^z&Number of entries in the NamedNodeMap.c@s,eZdZdZdZddZddZddZd S) Identifiedz@Mix-in class that supports the publicId and systemId attributes.publicIdsystemIdcCs||_||_dSr%rf)r rgrhr r r _identified_mixin_initsz!Identified._identified_mixin_initcCs|jSr%)rgr r r r _get_publicIdszIdentified._get_publicIdcCs|jSr%)rhr r r r _get_systemIdszIdentified._get_systemIdN)r{r|r}rrrirjrkr r r r res rec@sHeZdZejZdZdZdZdZ dZ ddZ ddZ ddZ d d d ZdS) DocumentTypeNcCs2t|_t|_|r&t|\}}||_|j|_dSr%)r^entities notationsrrr)r rrrr r r r s  zDocumentType.__init__cCs|jSr%)internalSubsetr r r r _get_internalSubsetsz DocumentType._get_internalSubsetcCs|jdkrtd}|j|_|j|_tjjj}|rg|j_ g|j _ |j j D]2}t |j|j |j }|j j |||||qH|jj D]N}t|j|j |j |j}|j|_|j|_|j|_|jj |||||q|||||SdSdSr%)rXrlrrr6r7UserDataHandler NODE_CLONEDrmr`rnNotationrgrhrRrvEntity notationNameactualEncodingrr_)r rYclonertrnotationeentityr r r rZs0    zDocumentType.cloneNodercCs|d||j|jr8|d||j||jfn|jrR|d||jf|jdk r||d||j|d|d|dS)Nz srtc@seZdZejZdZddZdS)rsNcCs||_|||dSr%)rri)r rrgrhr r r rjszNotation.__init__)r{r|r}r rrrrr r r r rsfsrsc@sHeZdZddddddddgZd d Zd d Zd dZddZddZdS)DOMImplementation)core1.0)r2.0)rN)r6r)r6r)r6N)ls-loadz3.0)rNcCs|dkr d}||f|jkSr)lower _featuresr]r r r r\zszDOMImplementation.hasFeaturec Cs|r|jdk rtjd|}|dko8|dko8|dk }|sP|rPtjd|rt|\}}|dkr||dkr|tjd|r|stjd|||}|r| || ||r||_|_ ||_ ||_ |S)Nz(doctype object owned by another DOM treezElement with no namer6z$http://www.w3.org/XML/1998/namespacezillegal use of 'xml' prefixz(illegal use of prefix without namespaces) r:r6r7WrongDocumentErr_create_documentZInvalidCharacterErrrrcreateElementNSr<rXdoctyper[) r r~rrrZadd_root_elementrrr*r r r createDocuments>       z DOMImplementation.createDocumentcCst|}||_||_|Sr%)rlrgrh)r rrgrhrr r r createDocumentTypesz$DOMImplementation.createDocumentTypecCs||dr|SdSdSr%)r\rer r r rfs zDOMImplementation.getInterfacecCstSr%)Documentr r r r rsz"DOMImplementation._create_documentN) r{r|r}rr\rrrfrr r r r ros -rc@s\eZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ dS) ElementInfozObject that represents content-model information for an element. This implementation is not expected to be used in practice; DOM builders should provide implementations which do the right thing using information available to it. rcCs ||_dSr%rrr r r rszElementInfo.__init__cCstSr%rr Zanamer r r rszElementInfo.getAttributeTypecCstSr%rrr r r rszElementInfo.getAttributeTypeNScCsdSrr r r r r rXszElementInfo.isElementContentcCsdS)zQReturns true iff this element is declared to have an EMPTY content model.Fr r r r r isEmptyszElementInfo.isEmptycCsdS)z7Returns true iff the named attribute is a DTD-style ID.Fr rr r r rszElementInfo.isIdcCsdS)z|jtjkr|jd|_nt|r:|jjd|j_dSr%)rr r _id_cacheclear_id_search_stackrrXrr r r rAs    rAc@sreZdZdZejejejejfZ e Z ej Z dZdZdZdZdZZdZdZdZdZdZdZdZdZddZdd Zd d Zd d ZddZ ddZ!ddZ"ddZ#ddZ$ddZ%ddZ&ddZ'ddZ(d d!Z)d"d#Z*d$d%Z+d&d'Z,d(d)Z-d*d+Z.d,d-Z/d.d/Z0d0d1Z1d2d3Z2d4d5Z3d6d7Z4d8d9Z5d:d;Z6dd?Z8d@dAZ9dBdCZ:dIdEdFZ;dGdHZ|j||jtj kr^| r^tjdt ||S)Nr0z two document elements disallowed) rr5r6r7r8r9r:r;r rS_get_documentElementr<rr r r r<3s    zDocument.appendChildcCsVz|j|Wntk r.tjYnXd|_|_d|_|j |krRd|_ |Sr%) r'rMr>r6r7r?rCrDr:documentElementrNr r r r;Cs  zDocument.removeChildcCs$|jD]}|jtjkr|SqdSr%)r'rr rSrr r r rOs  zDocument._get_documentElementcCs(|jdk r|jd|_t|dSr%)rrQr r r r r rQTs  zDocument.unlinkcCs|sdS|jddd}|j|_|j|_|j|_|jD]n}t|||}|j|sVt |j ||j t j kr~|jdkst n |j t jkr|jdkst ||_||_q6|tjjj|||Sr%)r[rrrr_r'rWrXrdAssertionErrorrRrr rrr|rr:rvr6r7rqrr)r rYrwrZ childcloner r r rZZs*      zDocument.cloneNodecCst}||_|Sr%)rrX)r ror r r createDocumentFragmentoszDocument.createDocumentFragmentcCst|}||_|Sr%)rrX)r rryr r r createElementtszDocument.createElementcCs(t|tstdt}||_||_|SNznode contents must be a string)rrrrrPrX)r rPtr r r createTextNodeys  zDocument.createTextNodecCs(t|tstdt}||_||_|Sr)rrrr\rPrXr rPrGr r r createCDATASections  zDocument.createCDATASectioncCst|}||_|Sr%)r[rXrr r r createCommentszDocument.createCommentcCst||}||_|Sr%)r0rX)r r2rPpr r r createProcessingInstructions z$Document.createProcessingInstructioncCst|}||_d|_|Sr)rrXr)r rar r r createAttributeszDocument.createAttributecCs"t|\}}t|||}||_|Sr%)rrrX)r r~rrrryr r r rs  zDocument.createElementNScCs*t|\}}t||||}||_d|_|Sr)rrrXr)r r~rrrrr r r createAttributeNSs  zDocument.createAttributeNScCst||||}||_|Sr%)rtrX)r rrgrhruryr r r _create_entityszDocument._create_entitycCst|||}||_|Sr%)rsrX)r rrgrhrr r r _create_notations zDocument._create_notationcCs||jkr|j|S|js$|js$dS|j}|dkrB|jg}||_n|sJdSd}|r|}|dd|jD||}|rB|j D]}|j r| |j |j r||j|j<|j|kr|}n |jsqq||jr ||j|j<|j|kr|}n|js>qq|jr||j|j<|j|kr.|}q|jdkrqqn>|jr|j D]*}|jrT||j|j<|j|krT|}qT|dk rNqqN|S)NcSsg|]}|jtkr|qSr )rr@).0rVr r r s z+Document.getElementById..r1)rrrrrpopextendr'rrrr~rrrrrrr)r rstackresultrHrr r r r getElementByIdsZ              zDocument.getElementByIdcCst||tSr%rrr r r rszDocument.getElementsByTagNamecCst|||tSr%rrr r r r s zDocument.getElementsByTagNameNScCs|j||Sr%)r[r\r]r r r r`szDocument.isSupportedcCs>|jtjkrtjdn|jtjkr2tjdt|||S)Nzcannot import document nodesz!cannot import document type nodes)rr rr6r7NotSupportedErrr|rW)r rHrYr r r importNodes    zDocument.importNodercCsJ|dkr|d|n|d||f|jD]}|||||q0dS)Nzz%%s)rr'r)r r$r"r"r#rrHr r r rs zDocument.writexmlcCsJ|j|k r tjd||jf|jtjtjfkr>tjd|t krd|kr| dd\}}|dkr|tjj krtj dq|dkr|tjj kr|jtjkrtj dd}|}nd}d}|jtjkr|j }|dk r|j}||nd}||_||_||_||_|jtjkr||_n*||_|dk rF|||rF|||S)Nz?cannot rename nodes from other documents; expected %s, found %sz8renameNode() only applies to element and attribute nodesrr1rzillegal use of 'xmlns' prefixz$illegal use of the 'xmlns' attribute)rXr6r7rrr rSrrrrrrrrrrrr~rrrr r$)r rr~rrrr*Zis_idr r r renameNode sb         zDocument.renameNode)rrrN)=r{r|r}rr rSrrr|r5rr[rrrrrr:rDrCrvrrr_rrrrrrr~rrrrrrrr<r;rrQrZrrrrrrrrrrrrrr r`rrrr r r r rsj   : rrz#Top-level element of this document.c Cs|j|rtjjj}n tjjj}|jtj kr| |j |j }|j D]0}||j |j |j||j |j}|j|_qH|r|jD]}t|||}||qn|jtjkr|}|r|jD]}t|||}||qn|jtjkr||j}n|jtjkr||j}n|jtjkr>||j |j}nz|jtj!kr\|"|j}n\|jtj#kr|$|j |j }d|_|j|_n,|jtj%kr|j|k st&tjjj}|j'(|j)|j*|j+}||_|rg|j,_-g|j._-|j.j-D]F} t/| j | j*| j+} || _|j.j-0| t1| dr| 2|| | q|j,j-D]b} t3| j | j*| j+| j4} | j5| _5| j6| _6| j7| _7|| _|j,j-0| t1| dr>| 2|| | q>ntj8dt9|t1|dr|2||||S)zo Clone a node and give it the new owner document. Called by Node.cloneNode and Document.importNode TrvzCannot clone node %s):rXrdr6r7rqrrZ NODE_IMPORTEDrr rSrr~rrrrrrrrr'rWr<r2rrOrrPrrrrr2rrrrr|rr[rrrgrhrmr`rnrsrRrqrvrtrurvrr_rr9) rHrYZnewOwnerDocumentrtrwr rrVrGrrxryrzr r r rWBs                  rWcCs,|dd}t|dkr|Sd|dfSdS)Nrr1r)rr)rZfieldsr r r rs  rcCs,|||}|\}}||||Sr%)ZgetEventZ expandNoder)funcargskwargsZeventsZtoktypeZrootNoder r r _do_pulldom_parses    rcCsH|dkr"|s"ddlm}||Sddlm}t|j|f||dSdS)z3Parse a file into a DOM by filename or file object.Nr expatbuilderpulldom)parserbufsize)xml.domrparserr)filerrrrr r r rs     rcCsB|dkrddlm}||Sddlm}t|j|fd|iSdS)z&Parse a file into a DOM from a string.Nrrrr)rr parseStringrr)stringrrrr r r rs    rcCs@|r:t|trt|}|D]\}}tj||sdSqtjSr%)rrrZ_parse_feature_stringrr[r\)Zfeaturesfvr r r getDOMImplementations   r)NN)N)N)7rrrr6rrrrZxml.dom.minicompatZxml.dom.xmlbuilderrrr7r rSrr@Z defpropertyrJrrrrrrobjectrZ AttributeListrrrrr+r0r:rrWr(r[r\r^rerlrtrsrrrArrWrrrrrr r r r sv  y$ x )GU  ><( O*PR