abc@`s'dZddlmZmZmZddlZddlZddlZddlm Z ddl m Z ddlm Z dd lm Z dd lmZddlj Z eZejd Ze jd jZd efdYZdefdYZdZdZde jfdYZdS(uModule 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 i(tabsolute_importtdivisiontunicode_literalsNi(tbasei(tDataLossWarning(t constants(tetree(t _ihatexmlu {([^}]*)}(.*)uasdt DocumentTypecB`seZdZRS(cC`s||_||_||_dS(N(tnametpublicIdtsystemId(tselfR R R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt__init__#s  (t__name__t __module__R (((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR"stDocumentcB`s/eZdZdZdZeeZRS(cC`sd|_g|_dS(N(tNonet _elementTreet _childNodes(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR *s cC`s|jjj|jdS(N(Rtgetroottaddnextt_element(R telement((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt appendChild.scC`s|jS(N(R(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt_getChildNodes1s(RRR RRtpropertyt childNodes(((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR)s   c`sJgtjdtdfd|ddjS(NtpreventDoubleDashCommentsic `sMt|dst|dr jd|jjr|jjpL|jjsbd|jj}n%d|jj|jj|jjf}jdd|d|fn|j}x"|jdk r|j}qWx|dk r ||d|j }qWqIt |t s+t |t rqt |t sStjd dksStjd d||fqIjd x|D]}||dqWn|jtkr jd d||jft|d rI|jrIjd d||jfqIn=t |tjs$ttjj|j}|dk r|jd}|jd}tj|}jdd||j|fn'jdd|j|jft|drg}x|jjD]\} } tj| }|dk rN|j \}} j| } tj|}d|| f} nj| } |j| | fqWx?t!|D].\} } jdd|d| | fqWn|jrjd d|d|jfn|d7}x|D]} | |qWt|d rI|jrIjd d|d|jfndS(Nutagugetrootu #documentu uu|%s%su iiu|%s"%s"u#document-fragmentu|%sutailiu |%s<%s %s>u|%s<%s>uattribu%s %su |%s%s="%s"("thasattrtappendtdocinfot internalDTDt public_idt system_urlt root_nameRt getpreviousRtgetnextt isinstancetstrtbytestsyst version_infotAssertionErrorttagt comment_typettextttailRt_Elementtetree_builderst tag_regexptmatchtgroupRtprefixest fromXmlNametattribtitemstgroupstsorted( Rtindenttdtd_strt next_elementtnsmatchtnsR,tprefixt attributesR tvaluet attr_stringtchild(t infosetFiltertrvtserializeElement(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRG;st      " (  $    ) %  u (Rt InfosetFiltertTruetjoin(R((RERFRGsP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyttestSerializer7s F c`s/gfd|djS(u4Serialize an element and its child nodes to a stringc`st|dsi|jjrV|jjr6|jj}nd|jj}j|n|jn|jtkrjd|j fn|j sjd|jfnUdj g|j j D]\}}d||f^q}jd|j|f|j r&j|j nx|D]}|q-Wjd|jft|d r|j rj|j ndS( Nutagu u u<%s>u u%s="%s"u<%s %s>uutail(RRR tdoctypeR#RRR,R-R.R7RJR8R/(RR<R RBtattrRD(RFRG(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRGs*    2  u(RJ(R((RFRGsP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyttostrings t TreeBuildercB`seZeZeZd Zd ZeZ e Z e dZ dZdZdZdZdZd dZd dZdZRS( c`stjtd|tjdt|_||_dtffdYdj ffdY}dj ffdY}||_ ||_ t jj||dS( NtfullTreeRt Attributesc`s)eZdfdZfdZRS(c`s|dkri}n||_tj||xo|jD]a\}}t|trzd|dj|df}nj|}||jjj|unameuGlxml cannot represent doctype with a different name to the root elementu$udatau namespaceu{%s}%sN( RLR R+R RR REt coercePubidtfindRzR{RtreplaceRt fromstringRrRnt addpreviousRt documentClassRst getroottreeRtgettdefaultNamespaceR,RmRRRuRRq( R R}tdocStrtsysidtroott comment_tokentcommentR RXt etree_tagt root_element((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt insertRoot7sL    *        N(RRRRRR|RRmRnt fragmentClassRtimplementationtFalseR RoRKRtRyRRpRR(((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyROs L      (t__doc__t __future__RRRRztreR)tRRRRR1Rt lxml.etreeRIRPtcompileR2RgR,R-tobjectRRRKRNRO(((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt s$    O )