+
    	i,>                        R t ^ RIHt ^ RIHt ^RIHtHtHt Rt]R,          t	R]
! ]4      R3R]
! ]]	R30,          4      R3R]
! ]]	R	3]	R
30,          4      R3R]
! ]	R3]	R3.4      R3R]
! ]	R3]	R3.4      R3/t]
! R4      t ! R R]4      t ! R R4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R4      tR# )Tree builder.)copy)ElementTree)
namespacesscoping_elementstable_insert_mode_elementsNhtmlFbuttonlistolultableselectoptgroupoptionTc                   &   a  ] tR t^t o R tRtV tR# )ActiveFormattingElementsc                P   ^ pV\         Jd   V RRR1,           Ft  pV\         J d    MiVP                  VP                  8H  ;'       d    VP                  VP                  8H  pV'       d
   V^,          pV^8X  g   Kc  V P                  V4        M	  \        P                  W4       R# )z#Append node to the end of the list.N)Marker
name_tuple
attributesremover
   append)selfnodeequal_countelementnodes_equals   &&   [/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/tinyhtml5/treebuilder.pyr   ActiveFormattingElements.append   s    v"::f$&&$//9 : :&&$//9  1$K!#KK( & 	D     N)__name__
__module____qualname____firstlineno__r   __static_attributes____classdictcell____classdict__s   @r   r   r      s        r!   r   c                      a  ] tR t^,t o RR ltR tR tR t]! ]]4      t	R t
R t]! ]
]4      tR tR	 tR
 tR tRR ltR tR tRtV tR# )ElementNc                    Wn         W n        \        P                  ! V P	                  W4      4      V n        Vf   \        V P                   3V n        MV P                  V P                   3V n        . V n        R V n	        R # N)
name	namespacer   r,   _get_etree_tag_element_htmlr   	_childrenparentr   r/   r0   s   &&&r   __init__Element.__init__-   sc    	"#++D,?,?,PQ#TYY.DO"nndii7DO r!   c                    Vf   V# RV RV 2# )N{}r"   r6   s   &&&r   r1   Element._get_etree_tag:   s     (tF9+Rv.FFr!   c                .    V P                   P                  # r.   )r2   attribr   s   &r   _get_attributesElement._get_attributes=   s    }}###r!   c                    V P                   P                  pVP                  4        V'       dN   VP                  4        F7  w  r4\	        V\
        4      '       d   R V^,           RV^,           2MTpWBV&   K9  	  R# R# )r:   r;   N)r2   r>   clearitems
isinstancetuple)r   r   element_attributeskeyvaluer/   s   &&    r   _set_attributesElement._set_attributes@   sm    !]]11  " )..0
2<S%2H2HCF82c!fX.c+04( 1 r!   c                    V P                   # r.   )r4   r?   s   &r   _get_childrenElement._get_childrenM   s    ~~r!   c                b    V P                   R  . V n        V F  pV P                  V4       K  	  R# ):NNNN)r2   r4   insert_child)r   rI   r   s   && r   _set_childrenElement._set_childrenP   s-    MM!Gg& r!   c                z    \        V P                  P                  ;'       g    \        V P                  4      4      # )z>Return True if the node has children or text, False otherwise.)boolr2   textlenr?   s   &r   has_contentElement.has_contentZ   s(    DMM&&<<#dmm*<==r!   c                    V P                   P                  V4       V P                  P                  VP                  4       Wn        R# )z+Insert node as a child of the current node.N)r4   r   r2   r5   r   r   s   &&r   append_childElement.append_child^   s/    d#T]]+r!   c                    \        V P                  4      P                  VP                  4      pV P                  P                  W1P                  4       Wn        R# )zInsert node as a child of the current node, before reference.

Raise ValueError if reference is not a child of the current node.

N)r
   r2   indexinsertr5   )r   r   	referencer^   s   &&& r   insert_beforeElement.insert_befored   s>     T]]#)))*<*<=UMM2r!   c                    V P                   P                  V4       V P                  P                  VP                  4       RVn        R# )z2Remove node from the children of the current node.N)r4   r   r2   r5   rZ   s   &&r   remove_childElement.remove_childn   s1    d#T]]+r!   c                   \        V P                  4      '       gS   V P                  P                  '       g   RV P                  n        V P                  ;P                  V,          un        R# Vfh   V P                  R,          P                  '       g   RV P                  R,          n        V P                  R,          ;P                  V,          un        R# \	        V P                  4      pVP                  VP                  4      pV^ 8  d}   V P                  V^,
          ,          P                  '       g    RV P                  V^,
          ,          n        V P                  V^,
          ,          ;P                  V,          un        R# V P                  P                  '       g   RV P                  n        V P                  ;P                  V,          un        R# )zInsert data as text in the current node.

Text is positioned before the start of node insert_before or to the end
of the node's text.

If insert_before is a node, insert the text before this node.

 Nr   )rV   r2   rU   tailr
   r^   )r   rU   ra   childrenr^   s   &&&  r   insert_textElement.insert_textt   s2    4==!!==%%%%'"MM$&"==$))))+b!&MM"""d*" DMM*HNN=#9#9:Eqy}}UQY/44446DMM%!),1eai(--5-}}))))+DMM&""d*"r!   c                    \        V 4      ! V P                  V P                  4      pV P                  P                  '       d/   \        V P                  P                  4      VP                  n        V# )zsReturn a shallow copy of the current node.

The node has the same name and attributes, but no parent or children.

)typer/   r0   r2   r>   r   )r   r   s   & r   cloneElement.clone   sN     t*TYY7==&*4==+?+?&@G#r!   c                ,   VP                   '       dJ   VP                   R,          P                  ;P                  V P                  P                  ,          un        M|VP                  P                  '       g   RVP                  n        V P                  P                  e8   VP                  ;P                  V P                  P                  ,          un        RV P                  n        V P                    F  pVP	                  V4       K  	  . V n         R# )zMove all the children of the current node to parent.

This is needed so that trees that don't store text as nodes move the
text in the correct way.

rg   Nr   )ri   r2   rh   rU   r[   )r   r5   childs   && r   reparent_childrenElement.reparent_children   s     ???OOB((--1C1CC-??'''')$}}!!-$$(:(::$]]E& #r!   )r4   r2   ri   r/   r   r0   r5   r.   )r#   r$   r%   r&   r7   r1   r@   rJ   propertyr   rM   rQ   ri   rW   r[   ra   rd   rj   rn   rr   r'   r(   r)   s   @r   r,   r,   ,   sh     G$1 /?;J' }5H>+>	 r!   r,   c                   &   a  ] tR t^t o R tRtV tR# )Commentc                X    \         P                  ! V4      V n        R V n        . V n        R # r.   )r   rv   r2   r5   r4   )r   datas   &&r   r7   Comment.__init__   s$     $++D1r!   )r4   r2   r5   Nr#   r$   r%   r&   r7   r'   r(   r)   s   @r   rv   rv      s      r!   rv   c                   &   a  ] tR t^t o R tRtV tR# )DocumentTypec                    \         P                  V R 4       WP                  n        V P                  P	                  RV4       V P                  P	                  RV4       W n        W0n        R# )z
<!DOCTYPE>publicIdsystemIdN)r,   r7   r2   rU   set	public_id	system_id)r   r/   r   r   s   &&&&r   r7   DocumentType.__init__   sN    |,!*i0*i0""r!   )r   r   Nrz   r)   s   @r   r|   r|      s     # #r!   r|   c                   &   a  ] tR t^t o R tRtV tR# )Documentc                2    \         P                  V R 4       R# )DOCUMENT_ROOTNr,   r7   r?   s   &r   r7   Document.__init__   s    /r!   r"   Nrz   r)   s   @r   r   r      s     0 0r!   r   c                   &   a  ] tR t^t o R tRtV tR# )DocumentFragmentc                2    \         P                  V R 4       R# )DOCUMENT_FRAGMENTNr   r?   s   &r   r7   DocumentFragment.__init__   s    23r!   r"   Nrz   r)   s   @r   r   r      s     4 4r!   r   c                      a  ] tR t^t o RtR tR tRR ltR tR t	R t
R	 tR
 tR tR tR tR t]! ]]4      tR tR tRR ltR tRR ltRR ltR tRtV tR# )TreeBuilderr   c                T    V'       d	   RV n         MRV n         V P                  4        R# )zUCreate a TreeBuilder.

If namespace_html_elements is True, namespace HTML elements.

zhttp://www.w3.org/1999/xhtmlN)default_namespacereset)r   namespace_html_elementss   &&r   r7   TreeBuilder.__init__   s      #%CD"%)D"

r!   c                z    . V n         \        4       V n        R V n        R V n        RV n        \        4       V n        R # )NF)open_elementsr   active_formatting_elementshead_elementform_elementinsert_from_tabler   documentr?   s   &r   r   TreeBuilder.reset   s6    *B*D'  !& 
r!   Nc                   \        VR 4      pV'       g7   \        V\        4      '       d	   \        V3p\        V\        4      '       g   Q h\
        V,          w  rE\        V P                  4       FN  pV'       d
   Wa8X  d    R# V'       g   VP                  V8X  d    R# WVP                  V9   ,          '       g   KM   R# 	  \        h)r   TF)
hasattrrE   strr3   rF   _list_elementsreversedr   r   
ValueError)r   targetvariant
exact_nodelist_elementsinvertr   s   &&&    r   element_in_scopeTreeBuilder.element_in_scope   s     V\2
&#&&fe,,,, .w 7T//0DdnDOOv$=OO}<== 1 r!   c           
     ^   V P                   '       g   R # \        V P                   4      ^,
          pV P                   V,          pV\        J g   W P                  9   d   R # V\        Jd9   W P                  9  d)   V^ 8X  d   RpMV^,          pV P                   V,          pKB   V^,          pV P                   V,          pVP	                  4       pV P                  RRRVP                  RVP                  RVP                  /4      pW@P                   V&   W@P                   R,          8X  g   K  R # )Nrm   StartTagr/   r0   rx   r   )	r   rV   r   r   rn   insert_elementr/   r0   r   )r   ientryrn   r   s   &    r   &reconstruct_active_formatting_elements2TreeBuilder.reconstruct_active_formatting_elements   s    ... //014//2F?e'9'99 6!e3E3E&EAvFA33A6EFA 33A6EKKME ))


U__((	+ G 29++A. 99"==r!   c                    V P                   P                  4       pV P                   '       d)   V\        Jd   V P                   P                  4       pK8  R # R # r.   )r   popr   )r   r   s   & r    clear_active_formatting_elements,TreeBuilder.clear_active_formatting_elements/  sF    //335---%v2E33779E 3F-r!   c                    V P                   RRR1,           F%  pV\        J d    R# VP                  V8X  g   K#  Vu # 	  R# )zFind name between end of active formatting elements and last marker.

If an element with this name exists, return it. Else return False.

NFr   )r   r   r/   )r   r/   items   && r   %element_in_active_formatting_elements1TreeBuilder.element_in_active_formatting_elements4  sI     33DbD99D v~  d" : r!   c                    V P                  V4      pV P                  P                  V4       V P                  P	                  V4       R # r.   )create_elementr   r   r   r[   )r   tokenr   s   && r   insert_rootTreeBuilder.insert_rootC  s8    %%e,!!'*""7+r!   c                    VR ,          pVR,          pVR,          p\        W#V4      pV P                  P                  V4       R# )r/   r~   r   N)r|   r   r[   )r   r   r/   r   r   doctypes   &&    r   insert_doctypeTreeBuilder.insert_doctypeH  s=    V}*%	*%	t	:""7+r!   c                H    VP                  \        VR ,          4      4       R# )rx   N)r[   rv   )r   r   r5   s   &&&r   insert_commentTreeBuilder.insert_commentP  s    GE&M23r!   c                    VR,          pVP                  RV P                  4      p\        W#4      pVR,          Vn        V# )z/Create an element but don't insert it anywhere.r/   r0   rx   )getr   r,   r   r   r   r/   r0   r   s   &&   r   r   TreeBuilder.create_elementS  s<    V}IIk4+A+AB	$*"6]r!   c                    V P                   # r.   )_insert_from_tabler?   s   &r   _get_insert_from_table"TreeBuilder._get_insert_from_table[  s    &&&r!   c                j    Wn         V'       d   V P                  V n        R# V P                  V n        R# )z.Switch the function used to insert an element.N)r   insert_element_tabler   insert_element_normal)r   rI   s   &&r   _set_insert_from_table"TreeBuilder._set_insert_from_table^  s'    "'"&";";D"&"<"<Dr!   c                >   VR ,          p\        V\        4      '       g   Q RV R24       hVP                  RV P                  4      p\	        W#4      pVR,          Vn        V P                  R,          P                  V4       V P                  P                  V4       V# )r/   zElement z not unicoder0   rx   r   )	rE   r   r   r   r,   r   r   r[   r   r   s   &&   r   r   !TreeBuilder.insert_element_normalh  s    V}$$$Cl&CC$IIk4+A+AB	$*"6]2++G4!!'*r!   c                >   V P                  V4      pV P                  R,          P                  \        9  d   V P	                  V4      # V P                  4       w  r4Vf   VP                  V4       MVP                  W$4       V P                  P                  V4       V# )z.Create an element and insert it into the tree.r   )	r   r   r/   r   r   !get_table_misnested_node_positionr[   ra   r   )r   r   r   r5   ra   s   &&   r   r    TreeBuilder.insert_element_tabler  s    %%e,b!&&.HH--e44 %)$J$J$L!F$##G,$$W<%%g.r!   c                    Vf   V P                   R,          pV P                  ;'       d%    V P                   R,          P                  \        9   pV'       d&   V P	                  4       w  r$VP                  W4       R# VP                  V4       R# )zInsert text data.Nr   )r   r   r/   r   r   rj   )r   rx   r5   in_tablera   s   &&&  r   rj   TreeBuilder.insert_text  s    >''+F "" F Fr"''+EE 	  %)$J$J$L!Ft3t$r!   c                f   RpRpRpV P                   RRR1,           F  pVP                  R8X  g   K  Tp M	  V'       d]   VP                  '       d   VP                  pTpW#3# V P                   P                  V4      ^,
          pV P                   V,          p W#3# V P                   ^ ,          pW#3# )zAGet foster parent element and sibling (or None) to insert before.Nr   r   )r   r/   r5   r^   )r   
last_tablefoster_parentra   r   r^   s   &     r   r   -TreeBuilder.get_table_misnested_node_position  s     
))$B$//G||w&$
 0      * 1 1 * ++	 **00<q@ $ 2 25 9 ++ !..q1M++r!   c                    V P                   R,          P                  pV\        9   d6   W!8w  d.   V P                   P                  4        V P	                  V4       R# R# R# )   Nr   )r   r/   _implied_end_tagsr   generate_implied_end_tags)r   excluder/   s   && r   r   %TreeBuilder.generate_implied_end_tags  sO    !!"%**$$""$ **73	 *9$r!   c                    V'       d   V P                   P                  # V P                   P                  P                  V P                  f   R4      # RV P                   R24      # )zReturn the final tree.r   r:   z}html)r   r2   findr   )r   	full_trees   &&r   get_documentTreeBuilder.get_document  s]    ==)))}}%%**,,4F1 	1''(/1 	1r!   c                r    \        4       pV P                  ^ ,          P                  V4       VP                  # )zReturn the final fragment.)r   r   rr   r2   )r   fragments   & r   get_fragmentTreeBuilder.get_fragment  s/    #%1//9   r!   )	r   r   r   r   r   r   r   r   r   r.   )F)r#   r$   r%   r&   __doc__r7   r   r   r   r   r   r   r   r   r   r   r   rt   r   r   r   rj   r   r   r   r   r'   r(   r)   s   @r   r   r      s~     
	#,.`:
,
,4'= !!79OP % ,641! !r!   r   )dddtlir   r   prprt)r   r   	xml.etreer   	constantsr   r   r   r   r3   	frozensetr   r   r
   r   r,   rv   r|   r   r   r   r"   r!   r   <module>r      s     ! O O
 
69%&
.y)eX->,??@%H
Y'E4=5$-*HHI5Qi%5'*:;<eDy5*-x/@ABDI WX  t  &C CLg #7 #0w 0
4w 4
r! r!r!   