U v_9@sdZddlmZmZmZddlZddlZddlZzddlm Z Wn e k r`ddl m Z YnXddl m Z ddlmZdd l mZdd l mZdd l mZddlmZdd lmZmZd ZedZedjZGdddeZGdddeZddZ ddZ!Gddde j"Z"dS)aModule for supporting the lxml.etree library. The idea here is to use as much of the native library as possible, without using fragile hacks like custom element names that break between releases. The downside of this is that we cannot represent all possible trees; specifically the following are known to cause problems: Text or comments as siblings of the root element Docypes with no name When any of these things occur, we emit a DataLossWarning )absolute_importdivisionunicode_literalsN)MutableMapping)base)DataLossWarning) constants)etree) _ihatexml)PY3 binary_typeTz {([^}]*)}(.*)Zasdc@seZdZddZdS) DocumentTypecCs||_||_||_dSN)namepublicIdsystemId)selfrrrr/builddir/build/BUILDROOT/alt-python38-pip-20.2.4-1.el7.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.py__init__)szDocumentType.__init__N)__name__ __module__ __qualname__rrrrrr(src@s,eZdZddZddZddZeeZdS)DocumentcCsd|_g|_dSr) _elementTree _childNodesrrrrr0szDocument.__init__cCs.|j}|jD]}q||jdSr)rgetrootZ itersiblingsZaddnext_element)relementlastrrr appendChild4s zDocument.appendChildcCs|jSr)rrrrr_getChildNodes;szDocument._getChildNodesN)rrrrr#r$property childNodesrrrrr/srcs6gtjdddfdd |ddS)NTZpreventDoubleDashCommentsrc s,t|ds,t|drd|jjrz|jjsF|jjsFd|jj}nd|jj|jj|jjf}dd|d|f|}|dk r|}q|dk r||d| }qnnt |t st |t rt |t st jd dkstd d||fn$d |D]}||dqn|jtkrd d||jft|d r(|jr(d d||jfnt |tjsttj|j}|dk r|d}|d}tj|}dd|||fndd||jft|drg}|jD]d\} } t| }|dk rj|\}} | } tj|}d|| f} n | } || | fq t |D]&\} } dd|d| | fq|jrڈd d|d|jf|d7}|D]} | |qt|d r(|jr(d d|d|jfdS)Ntagrz #document zz|%s%s rrz|%s"%s"z#document-fragmentz|%stailrz |%s<%s %s>z|%s<%s>attribz%s %sz |%s%s="%s")!hasattrappenddocinfo internalDTD public_idZ system_url root_namerZ getpreviousZgetnext isinstancestrbytessys version_infoAssertionErrorr( comment_typetextr+r Z_Elementetree_builders tag_regexpmatchgroupr prefixes fromXmlNamer,itemsgroupssorted) r!indentdtd_strZ next_elementZnsmatchnsr(prefix attributesrvalueZ attr_stringchild infosetFilterrvserializeElementrrrNEs|                       z(testSerializer..serializeElement )r)r InfosetFilterjoinr!rrKrtestSerializerAs  F rScs$gfdd|dS)z4Serialize an element and its child nodes to a stringcst|dsH|jjr:|jjr$|jj}n d|jj}||n|jtkrfd|j fn~|j sd|jfn.d dd|j D}d|j|f|j r|j |D] }|qĈd |jft|d r|j r|j dS) Nr(r)z z<%s>r*cSsg|]\}}d||fqS)z%s="%s"r).0rrIrrr sz6tostring..serializeElement..z<%s %s>zr+)r-r/r0doctyper2r.rr(r9r:r,rQrAr+)r!rEattrrJrMrNrrrNs,        z"tostring..serializeElement)rQrRrrXrtostrings rZcszeZdZeZeZdZdZeZ e Z dddZ ddZ ddZd d Zd d Zd dZdddZdfdd ZddZZS) TreeBuilderNFcstjt|dtjdd|_||_GfdddtGfdddj}Gfdd d j }||_ ||_ t j ||dS) N)fullTreeTr'csPeZdZddZfddZddZddZd d Zd d Zd dZ ddZ dS)z(TreeBuilder.__init__..AttributescSs ||_dSr)r rr!rrrrsz1TreeBuilder.__init__..Attributes.__init__cs4t|tr&d|d|df}n |}|S)N{%s}%srr)r3tupleZcoerceAttribute)rkeyrrLrr _coerceKeys  z3TreeBuilder.__init__..Attributes._coerceKeycSs0|jjj||}ts,t|tr,|d}|S)Nascii)r r,rbr r3rdecoderr`rIrrr __getitem__s z4TreeBuilder.__init__..Attributes.__getitem__cSs||jjj||<dSrr r,rbrerrr __setitem__sz4TreeBuilder.__init__..Attributes.__setitem__cSs|jjj||=dSrrg)rr`rrr __delitem__sz4TreeBuilder.__init__..Attributes.__delitem__cSst|jjjSr)iterr r,rrrr__iter__sz1TreeBuilder.__init__..Attributes.__iter__cSst|jjjSr)lenr r,rrrr__len__sz0TreeBuilder.__init__..Attributes.__len__cSs|jjjSr)r r,clearrrrrrnsz.TreeBuilder.__init__..Attributes.clearN) rrrrrbrfrhrirkrmrnrrarr Attributess rocspeZdZfddZfddZfddZeeeZddZd d Z eee Z dfd d Z ddZ d S)z%TreeBuilder.__init__..Elementcs*|}jj|||d||_dS)N) namespace) coerceElementElementr _attributes)rrrprobuilderrLrrrs z.TreeBuilder.__init__..Element.__init__cs$||_||j|j|j_dSr)rq_nameZ _getETreeTagZ _namespacer r()rrrarr_setNames  z.TreeBuilder.__init__..Element._setNamecs |jSr)r@rvrrarr_getNamesz.TreeBuilder.__init__..Element._getNamecSs|jSr)rsrrrr_getAttributessz4TreeBuilder.__init__..Element._getAttributescSs|j}|||dSr)rHrnupdate)rrIrHrrr_setAttributessz4TreeBuilder.__init__..Element._setAttributesNcs|}j|||dSr)ZcoerceCharactersrr insertText)rdata insertBeforerurLrrr|s z0TreeBuilder.__init__..Element.insertTextcSs0t||j|j}|jjr,|jj|jj|Sr)typerrpr r,rzr]rrr cloneNodesz/TreeBuilder.__init__..Element.cloneNode)N) rrrrrwrxr%rryr{rHr|rrrtrrrrs    rrcs8eZdZfddZfddZddZeeeZdS)z%TreeBuilder.__init__..Commentcs|}j||dSr) coerceCommentCommentrrr}rrrr s z.TreeBuilder.__init__..Comment.__init__cs|}||j_dSr)rr r:rrarr_setDatas z.TreeBuilder.__init__..Comment._setDatacSs|jjSr)r r:rrrr_getDatasz.TreeBuilder.__init__..Comment._getDataN)rrrrrrr%r}rrrrr s r)r;getETreeModuler r rPrLnamespaceHTMLElementsrrrr elementClass commentClassrr[r)rrr\rrrrrtrrs $zTreeBuilder.__init__cCs$tj||j|_g|_d|_dSr)rr[resetinsertCommentInitial insertCommentinitial_commentsrVrrrrrs zTreeBuilder.resetcCst|Sr)rSr]rrrrS#szTreeBuilder.testSerializercCstr |jjS|jjSdSr)r\documentrrrrrr getDocument&szTreeBuilder.getDocumentcCsFg}|jdj}|jr"||j|t||jrB||j|S)Nr) openElementsr r:r.extendlistr+)rfragmentr!rrr getFragment,s   zTreeBuilder.getFragmentcCsh|d}|d}|d}|s0tdtd|_n4|j|}||krPtdt||||}||_dS)Nrrrz#lxml cannot represent empty doctypez%lxml cannot represent non-xml doctype)warningswarnr rVrLrq doctypeClass)rtokenrrrZ coercedNamerVrrr insertDoctype6s   zTreeBuilder.insertDoctypecCs6|dks||jkst|jjdks&t|j|dSr)rr8rrr.rr}parentrrrrFsz TreeBuilder.insertCommentInitialcsB||jkr,|jjdjtkr,tdttt | ||dS)Nz@lxml cannot represent adjacent comments beyond the root elements) rrrr(r9rrr superr[rr __class__rrinsertCommentMainKs   zTreeBuilder.insertCommentMainc Csd}|jr|jjst|d|jj7}|jjdk s>|jjdk r|d|j|jjpRd7}|jjr|jj}|ddkr|ddkrt dt | dd}|ddkr|d |7}q|d |7}n|d 7}|d 7}|jj|d krt dt |d7}t |}|jD] }||d}||jq ||_||j_|d }|d|j}|dkrj|} n d||f} | |_|||} || _|jj| |j| |j|_dS)NrYz rzGlxml cannot represent doctype with a different name to the root elementz$r}rpr^)rVrr8rrrLZ coercePubidfindrrr replacer fromstringrrZ addpreviousr documentClassrZ getroottreergetdefaultNamespacer(rrr.rrr) rrZdocStrsysidroot comment_tokencommentrrpZ etree_tagZ root_elementrrr insertRootQsP              zTreeBuilder.insertRoot)F)N)N)rrrrrrrrr fragmentClassr implementationrrrSrrrrrr __classcell__rrrrr[s \  r[)#__doc__ __future__rrrrrer6collections.abcr ImportError collectionsrYrr r r r;r Z lxml.etreeZpip._vendor.sixr rr\compiler<rr(r9objectrrrSrZr[rrrrs.         O)