\e[c@`shddlmZmZmZddlmZddlmZmZm Z dZ ie ee fd6e eee ddfgBe fd6e eee ddfe ddfgBe fd 6e e ddfe dd fge fd 6e e dd fe dd fgefd 6ZdefdYZdefdYZdefdYZdS(i(tabsolute_importtdivisiontunicode_literals(t text_typei(tscopingElementsttableInsertModeElementst namespacesuhtmlubuttonuoluululistutableuoptgroupuoptionuselecttNodecB`skeZdZdZdZdZdZd dZdZ dZ dZ d Z d Z RS( uRepresents an item in the treecC`s:||_d|_d|_i|_g|_g|_dS(uRCreates a Node :arg name: The tag name associated with the node N(tnametNonetparenttvaluet attributest childNodest_flags(tselfR((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt__init__s      cC`sadjg|jjD]\}}d||f^q}|rRd|j|fSd|jSdS(Nu u%s="%s"u<%s %s>u<%s>(tjoinR titemsR(RRR t attributesStr((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt__str__-s  2cC`s d|jS(Nu<%s>(R(R((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt__repr__6scC`s tdS(u[Insert node as a child of the current node :arg node: the node to insert N(tNotImplementedError(Rtnode((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt appendChild9scC`s tdS(uBInsert data as text in the current node, positioned before the start of node insertBefore or to the end of the node's text. :arg data: the data to insert :arg insertBefore: True if you want to insert the text before the node and False if you want to insert it after the node N(R(Rtdatat insertBefore((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt insertTextAs cC`s tdS(uInsert node as a child of the current node, before refNode in the list of child nodes. Raises ValueError if refNode is not a child of the current node :arg node: the node to insert :arg refNode: the child node to insert the node before N(R(RRtrefNode((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyRMs cC`s tdS(uhRemove node from the children of the current node :arg node: the child node to remove N(R(RR((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt removeChildYscC`s.x|jD]}|j|q Wg|_dS(uMove all the children of the current node to newParent. This is needed so that trees that don't store text as nodes move the text in the correct way :arg newParent: the node to move all this node's children to N(R R(Rt newParenttchild((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pytreparentChildrenas cC`s tdS(uReturn a shallow copy of the current node i.e. a node with the same name and attributes but with no parent or child nodes N(R(R((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt cloneNodenscC`s tdS(uFReturn true if the node has children or text, false otherwise N(R(R((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt hasContenttsN(t__name__t __module__t__doc__RRRRR RRRR R!R"(((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyRs     tActiveFormattingElementscB`seZdZdZRS(cC`sd}|tkrxj|dddD]R}|tkr<Pn|j||r[|d7}n|dkr&|j|Pq&q&Wntj||dS(Niiii(tMarkert nodesEqualtremovetlisttappend(RRt equalCounttelement((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyR+{s      cC`s0|j|jkstS|j|jks,tStS(N(t nameTupletFalseR tTrue(Rtnode1tnode2((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyR(s (R#R$R+R((((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyR&zs t TreeBuildercB`seZdZdZdZdZdZdZdZ dZ ddZ dZ dZ dZdZdZdd Zd Zd Zd ZeeeZd ZdZddZdZddZdZdZdZRS(uBase treebuilder implementation * documentClass - the class to use for the bottommost node of a document * elementClass - the class to use for HTML Elements * commentClass - the class to use for comments * doctypeClass - the class to use for doctypes cC`s)|rd|_n d|_|jdS(umCreate a TreeBuilder :arg namespaceHTMLElements: whether or not to namespace HTML elements uhttp://www.w3.org/1999/xhtmlN(tdefaultNamespaceR treset(RtnamespaceHTMLElements((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyRs  cC`sCg|_t|_d|_d|_t|_|j|_ dS(N( t openElementsR&tactiveFormattingElementsR t headPointert formPointerR/tinsertFromTablet documentClasstdocument(R((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyR5s      cC`st|d}|sOt|tr7td|f}nt|tsOtnt|\}}x^t|jD]M}|r||krt S| r|j |krt S||j |kArot SqoWt stdS(Nu nameTupleuhtml( thasattrt isinstanceRRttupletAssertionErrortlistElementsMaptreversedR7R0R.R/(Rttargettvariantt exactNodet listElementstinvertR((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pytelementInScopescC`s'|js dSt|jd}|j|}|tksH||jkrLdSxL|tkr||jkr|dkrd}Pn|d8}|j|}qOWxtr"|d7}|j|}|j}|jidd6|jd6|jd6|j d6}||j|<||jdkrPqqWdS( NiiiuStartTagutypeunameu namespaceudata( R8tlenR'R7R0R!t insertElementRt namespaceR (RtitentrytcloneR-((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt#reconstructActiveFormattingElementss.           cC`s>|jj}x(|jr9|tkr9|jj}qWdS(N(R8tpopR'(RRN((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pytclearActiveFormattingElementsscC`sHxA|jdddD])}|tkr-Pq|j|kr|SqWtS(uCheck if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return falseNi(R8R'RR/(RRtitem((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt!elementInActiveFormattingElements s  cC`s3|j|}|jj||jj|dS(N(t createElementR7R+R=R(RttokenR-((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt insertRootscC`sG|d}|d}|d}|j|||}|jj|dS(NunameupublicIdusystemId(t doctypeClassR=R(RRVRtpublicIdtsystemIdtdoctype((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt insertDoctype s    cC`s:|dkr|jd}n|j|j|ddS(Niudata(R R7Rt commentClass(RRVR ((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt insertComment(s cC`sB|d}|jd|j}|j||}|d|_|S(u.Create an element but don't insert it anywhereunameu namespaceudata(tgetR4t elementClassR (RRVRRLR-((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyRU-s   cC`s|jS(N(t_insertFromTable(R((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt_getInsertFromTable5scC`s.||_|r|j|_n |j|_dS(usSwitch the function used to insert an element from the normal one to the misnested table one and back againN(RatinsertElementTableRKtinsertElementNormal(RR ((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt_setInsertFromTable8s cC`s|d}t|ts)td||jd|j}|j||}|d|_|jdj||jj ||S(NunameuElement %s not unicodeu namespaceudatai( R?RRAR_R4R`R R7RR+(RRVRRLR-((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyRdCs  cC`s|j|}|jdjtkr2|j|S|j\}}|dkr`|j|n|j|||jj ||S(u-Create an element and insert it into the treeiN( RUR7RRRdtgetTableMisnestedNodePositionR RRR+(RRVR-R R((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyRcMs  cC`s{|dkr|jd}n|j sE|jrU|jdjtkrU|j|n"|j\}}|j||dS(uInsert text data.iN(R R7R;RRRRf(RRR R((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyR]s   cC`sd}d}d}x7|jdddD]}|jdkr)|}Pq)q)W|r|jrm|j}|}q|j|jj|d}n |jd}||fS(usGet the foster parent element, and sibling to insert before (or None) when inserting a misnested table nodeNiutableii(R R7RR tindex(Rt lastTablet fosterParentRtelm((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyRfls    c C`sO|jdj}|td krK||krK|jj|j|ndS( Niuddudtuliuoptionuoptgroupupurpurt(uddudtuliuoptionuoptgroupupurpurt(R7Rt frozensetRQtgenerateImpliedEndTags(RtexcludeR((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyRls   cC`s|jS(uReturn the final tree(R=(R((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt getDocumentscC`s$|j}|jdj||S(uReturn the final fragmenti(t fragmentClassR7R (Rtfragment((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyt getFragments cC`s tdS(uSerialize the subtree of node in the format required by unit tests :arg node: the node from which to start serializing N(R(RR((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyttestSerializersN(R#R$R%R R<R`R]RXRoRR5RIRPRRRTRWR\R^RURbRetpropertyR;RdRcRRfRlRnRqRr(((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyR3s6  .             N(t __future__RRRtpip._vendor.sixRt constantsRRRR R'RkR/tsetR0RBtobjectRR*R&R3(((sE/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treebuilders/base.pyts*! c