+
    	i~a                        ^ RI t ^ RIt^ RIHtHt ^ RIHt ^ RIHtH	t	 ^ RI
t
^RIHtHtHt ]! R ] 4       4      t]! R ] 4       4      t]! R ]	 4       4      t]]! R	R
.4      ,          t]P(                  ! R4      t0 RkRkRkRkRkRkRkRkRkRkRkRkRkRkRkRkRkRkRkRkR kR!kR"kR#kR$kR%kR&kR'kR(kR)kR*kR+kt]P(                  ! R,4      t/ tR- t ! R. R/4      t ! R0 R1]4      t ! R2 R3]4      t ! R4 R54      t ! R6 R74      tR8 t R# )9    N)BytesIOStringIO)Path)ascii_lettersascii_uppercase)EOFReparseErrorspace_charactersc              #   @   "   T F  qP                  4       x  K  	  R # 5iNencode.0items   & [/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/tinyhtml5/inputstream.py	<genexpr>r      s     "N=MT;;===M   c              #   @   "   T F  qP                  4       x  K  	  R # 5ir   r   r   s   & r   r   r      s     H-$-r   c              #   @   "   T F  qP                  4       x  K  	  R # 5ir   r   r   s   & r   r   r      s     !LOD++--Or      >   <u   [---﷐-﷯￾￿🿾🿿𯿾𯿿𿿾𿿿񏿾񏿿񟿾񟿿񯿾񯿿񿿾񿿿򏿾򏿿򟿾򟿿򯿾򯿿򿿾򿿿󏿾󏿿󟿾󟿿󯿾󯿿󿿾󿿿􏿾􏿿-]i i i i i i i i i i i i i i i i i	 i	 i
 i
 i i i i i i i i i i i i z[	- -/:-@\[-`{-~]c                    \        V \        4      '       dS   \        V 4      ^8  dC   \        V 4      P	                  4       '       d$   \        \        V 4      P                  4       3/ VB # \        V \        4      '       d   \        V P                  4       3/ VB # \        \        V R4      '       d   V P                  ^ 4      MT \        4      '       d   \        V 3/ VB # \        V 3/ VB # )   read)

isinstancestrlenr   is_fileHTMLUnicodeInputStream	read_texthasattrr   HTMLBinaryInputStream)sourcekwargss   &,r   HTMLInputStreamr&   &   s    &#3v;#4f9M9M9O9O%d6l&<&<&>I&II	FD	!	!%f&6&6&8CFCC	gff&=&=FKKN63	O	O%f777$V6v66    c                   ^   a  ] tR t^1t o RtR tR tR tR tR t	R t
R tRR	 ltR
 tRtV tR# )r    zProvides a Unicode stream of characters to the HTMLTokenizer.

This class takes care of character encoding and removing or replacing
incorrect byte-sequences and also provides column and line tracking.

c                    ^ .V n         \        R4      R3V n        V P                  V4      V n        V P                  4        R# )zInitialise the HTMLInputStream.

Create a normalized stream from source for use by tinyhtml5.

source can be either a file-object, local filename or a string.

utf-8certainN)	new_lineslookup_encodingencodingopen_streamstreamreset)selfr$   r%   s   &&,r   __init__HTMLUnicodeInputStream.__init__9   s9     (19=&&v.

r'   c                h    R V n         ^ V n        ^ V n        . V n        ^ V n        ^ V n        RV n        R# ) N)chunk
chunk_sizechunk_offseterrorsprevious_number_linesprevious_number_columns_buffered_characterr2   s   &r   r1   HTMLUnicodeInputStream.resetI   s;    
 &'"'($ $( r'   c                @    \        VR4      '       d   V# \        V4      # )zeProduce a file object from source.

source can be either a file object, local filename or a string.

r   )r"   r   r2   r$   s   &&r   r/   "HTMLUnicodeInputStream.open_streamW   s      !00vFhv6FFr'   c                    V P                   pVP                  R ^ V4      pV P                  V,           pVP                  R ^ V4      pVR8X  d   V P                  V,           pWF3# W^,           ,
          pWF3# )
)r7   countr;   rfindr<   )r2   offsetr7   number_linesposition_linelast_line_positionposition_columns   &&     r   	_position HTMLUnicodeInputStream._position_   s{    

{{4F322\A"[[q&9#"::VCO // %Q(>?O//r'   c                R    V P                  V P                  4      w  rV^,           V3# )z9Return (line, col) of the current position in the stream.)rM   r9   )r2   linecolumns   &  r   positionHTMLUnicodeInputStream.positionj   s'    ~~d&7&78q&!!r'   c                    V P                   V P                  8  d   V P                  4       '       g   \        # V P                   pV P                  V,          pV^,           V n         V# )z\Read one character from the stream or queue if available.

Return EOF when EOF is reached.

)r9   r8   
read_chunkr   r7   )r2   r9   	characters   &  r   rV    HTMLUnicodeInputStream.charactero   sT     /??$$
((JJ|,	(1,r'   c                   V P                  V P                  4      w  V n        V n        R V n        ^ V n        ^ V n        V P                  P                  R4      pV P                  '       d   V P                  V,           pRV n        M
V'       g   R# \        V4      ^8  d?   \        VR,          4      pV^8X  g   RTu;8:  d   R8:  d   M MVR,          V n        VRR p\        \        \        P                  V4      4      4       F  pV P                  P                  R4       K   	  VP!                  RR4      pVP!                  R	R4      pWn        \        V4      V n        R
# )r6   i (  NFi   i  zinvalid-codepointz
rD   TrE   )rM   r8   r;   r<   r7   r9   r0   r   r=   r   ordrangeinvalid_unicode_refindallr:   appendreplace)r2   datalast_s   &   r   rU   !HTMLUnicodeInputStream.read_chunk   s'   CG>>OOD@"D$@ 
{{& ###++d2D'+D$t9q=tBx=Dt|v77+/8(CRy s-55d;<=AKK23 > ||FD)||D$'
d)r'   c           
         \         W3,          p. p VP                  V P                  V P                  4      pVf   V P                  V P                  8w  d   MMOVP                  4       pWpP                  8w  d0   VP                  V P                  V P                  V 4       Wpn        MAVP                  V P                  V P                  R 4       V P                  4       '       d   K   RP                  V4      #   \         dl    RP                  T Uu. uF  pR\        T4      R 2NK  	  Mu upi up4      pT'       g   RT 2p\        P
                  ! RT R24      pT;p\         Y3&    EL`i ; i)zReturn a string of characters from the stream.

String goes up to but does not include any character in 'characters' or
EOF. 'characters' must be a container that supports the 'in' method and
iteration over its characters.

r6   z\x02x^[z]+N)characters_until_regexKeyErrorjoinrZ   recompilematchr7   r9   r8   endr^   rU   )r2   
charactersoppositerV   regexresultrm   rn   s   &&&     r   chars_until"HTMLUnicodeInputStream.chars_until   sO   	P/0FGJ $$TZZ1B1BCE} $$7 8 iik //)MM$**T->->s"CD(+% MM$**T%6%6%789??$$wwvA  	PGGTIs3y>#"67TUEE7JJ5'}-EJOOJ/0FG	Ps#   C; ;E1D.
-E1+E10E1c                   V\         Jd   V P                  ^ 8X  d3   WP                  ,           V n        V ;P                  ^,          un        R# V ;P                  ^,          un        V P                  V P                  ,          V8X  g   Q hR# R# r   N)r   r9   r7   r8   )r2   chars   &&r   ungetHTMLUnicodeInputStream.unget   sj     s?  A%
 "JJ.
1$!!Q&!zz$"3"34<<< r'   )
r=   r7   r9   r8   r.   r:   r,   r<   r;   r0   N)F)__name__
__module____qualname____firstlineno____doc__r3   r1   r/   rM   rR   rV   rU   rs   rx   __static_attributes____classdictcell____classdict__s   @r   r    r    1   s?      (G	0"
"#J,\= =r'   r    c                   ^   a a ] tR t^t oRtR
R ltV 3R ltR tR tR t	R t
R tR	tVtV ;t# )r#   zProvide a binary stream of characters to the HTMLTokenizer.

This class takes care of character encoding and removing or replacing
incorrect byte-sequences and also provides column and line tracking.

c                    V P                  V4      V n        R V n        W n        W0n        W@n        WPn        W`n        V P                  4       V n	        V P                  ^ ,          f   Q hV P                  4        R# )i   N)r/   
raw_streamnumber_bytes_metaoverride_encodingtransport_encodingsame_origin_parent_encodinglikely_encodingdefault_encodingdetermine_encodingr.   r1   )r2   r$   r   r   r   r   r   r%   s   &&&&&&&,r   r3   HTMLBinaryInputStream.__init__   sp    
 **62
 "&!2"4+F(. 0 //1}}Q+++ 	

r'   c                   < V P                   ^ ,          P                  P                  pV! V P                  R4      V n        \
        SV `  4        R# )r   r_   N)r.   
codec_infostreamreaderr   r0   superr1   )r2   r   	__class__s   & r   r1   HTMLBinaryInputStream.reset  s8    }}Q'22??"4??I>r'   c                    \        VR 4      '       d;   \        VR4      '       d   VP                  4       '       d   V# VP                  4       p\        V4      # )r   seekable)r"   r   r   r   rA   s   &&r   r/   !HTMLBinaryInputStream.open_stream	  sB    66""vz**v/@/@[[]Fvr'   c                P   V P                  4       R 3pV^ ,          e   V# \        V P                  4      R 3pV^ ,          e   V# \        V P                  4      R 3pV^ ,          e   V# V P	                  4       R3pV^ ,          e   V# \        V P
                  4      R3pV^ ,          e+   V^ ,          P                  P                  R4      '       g   V# \        V P                  4      R3pV^ ,          e   V# \        V P                  4      R3pV^ ,          e   V# \        R4      R3# )r+   	tentativezutf-16windows-1252)

detect_bomr-   r   r   detect_encoding_metar   name
startswithr   r   )r2   r.   s   & r   r   (HTMLBinaryInputStream.determine_encoding  s2    ??$i/A;"O #4#9#9:IEA;"O #4#:#:;YFA;"O ,,.;A;"O #4#C#CDkQA;"8A;+;+;+F+Fx+P+PO #4#7#78+EA;"O #4#8#89;FA;"O ~.;;r'   c                   V P                   ^,          R8w  g   Q h\        V4      ;pf   R# VP                  R9   d   \        R4      pVf   Q hR# WP                   ^ ,          8X  d   V P                   ^ ,          R3V n         R# V P                  P	                  ^ 4       VR3V n         V P                  4        \        RV P                   ^ ,           RV 24      h)   r+   Nr*   zEncoding changed from z to utf-16beutf-16le)r.   r-   r   r   seekr1   r	   )r2   new_encodings   &&r   change_encoding%HTMLBinaryInputStream.change_encoding8  s    }}Q9,,,+L99LB 88*73L+++]]1--!]]1-y9DMOO  #)95DMJJL(q)9(:$|nMO Or'   c           
        \         P                  R\         P                  R\         P                  R\         P                  R\         P
                  R/pV P                  P                  ^4      p\        V\        4      '       g   Q hR FG  pVP                  VRV 4      ;p'       g   K!  V P                  P                  V4       \        V4      u # 	  V P                  P                  ^ 4       R# )zAttempt to detect at BOM at the start of the stream.

If an encoding can be determined from the BOM return the name of the
encoding otherwise return None.

r*   r   r   zutf-32lezutf-32beN)         )codecsBOM_UTF8BOM_UTF16_LEBOM_UTF16_BEBOM_UTF32_LEBOM_UTF32_BEr   r   r   bytesgetr   r-   )r2   bomsstringr   r.   s   &    r   r    HTMLBinaryInputStream.detect_bomH  s     OOW
 %%a(&%(((( D88F5DM22x22$$T*&x00	  	Qr'   c                ,   V P                   P                  V P                  4      p\        V\        4      '       g   Q h\        V4      pV P                   P                  ^ 4       VP                  4       pVe   VP                  R9   d   \        R4      pV# )z1Report the encoding declared by the meta element.r*   r   )
r   r   r   r   r   EncodingParserr   get_encodingr   r-   )r2   bufferparserr.   s   &   r   r   *HTMLBinaryInputStream.detect_encoding_metae  sz    %%d&<&<=&%(((('Q&&(HMM5M$M&w/Hr'   )	r   r.   r   r   r   r   r   r0   r   )NNNNr   )rz   r{   r|   r}   r~   r3   r1   r/   r   r   r   r   r   r   __classcell__)r   r   s   @@r   r#   r#      s4     2
&<PO  : r'   r#   c                      a  ] tR tRt o RtR tR tR tR tR t	R t
]! ]
]	4      t]R	 4       t]3R
 ltR tR tR tRtV tR# )EncodingBytesis  zBytes-like object with an associated position and various extra methods.

If the position is ever greater than the string length then an exception is
raised.

c                x    \        V\        4      '       g   Q h\        P                  WP                  4       4      # r   )r   r   __new__lower)clsvalues   &&r   r   EncodingBytes.__new__{  s*    %''''}}S++-00r'   c                    RV n         R# )r   NrE   rM   )r2   r   s   &&r   r3   EncodingBytes.__init__  s	    r'   c                v    V P                   ^,           ;qn         V\        V 4      8  d   \        hWV^,            # r   rM   r   StopIterationr2   rR   s   & r   __next__EncodingBytes.__next__  s6    $(NNQ$66>s4y X\**r'   c                L    V P                   ^,
          ;V n         pWV^,            # r   r   r   s   & r   previousEncodingBytes.previous  s&    $(NNQ$66X\**r'   c                h    V P                   \        V 4      8  d   \        h\        ^ V4      V n         R# rv   )rM   r   r   maxr   s   &&r   set_positionEncodingBytes.set_position  s&    >>SY&Q)r'   c                    V P                   \        V 4      8  d   \        hV P                   ^ 8  d   V P                   # R# rv   r   r>   s   &r   get_positionEncodingBytes.get_position  s3    >>SY&>>Q>>! r'   c                @    W P                   V P                   ^,            # r   )rR   r>   s   &r   current_byteEncodingBytes.current_byte  s    MM$--!"344r'   c                    V P                   pV\        V 4      8  d%   WV^,            pW19  d	   W n        V# V^,          pK4  W n        R# )zSkip past a list of characters.NrR   r   rM   r2   ro   rR   rV   s   &&  r   skipEncodingBytes.skip  sG    ==T"hl3I*!)  MH!r'   c                    V P                   pV\        V 4      8  d%   WV^,            pW19   d	   W n        V# V^,          pK4  W n        R# )r   Nr   r   s   &&  r   
skip_untilEncodingBytes.skip_until  sG    ==T"hl3I&!)  MH!r'   c                    V P                  WP                  4      ;p'       d#   V ;P                  \        V4      ,          un        V# )zLook for a sequence of bytes at the start of a string.

If the bytes are found return True and advance the position to the byte
after the match. Otherwise return False and leave the position alone.

)r   rR   r   )r2   r   rr   s   && r   match_bytesEncodingBytes.match_bytes  s3     __UMM::6:MMSZ'Mr'   c                     V P                  WP                  4      \        V4      ,           ^,
          V n        R#   \         d    \
        hi ; i)zLook for the next sequence of bytes matching a given sequence.

If a match is found advance the position to the last byte of the match.

T)indexrR   r   rM   
ValueErrorr   )r2   r   s   &&r   jump_toEncodingBytes.jump_to  sE    	 !ZZ}}=E
JQNDN   	 	 s	   7; Ar   N)rz   r{   r|   r}   r~   r   r3   r   r   r   r   propertyrR   r   space_characters_bytesr   r   r   r   r   r   r   s   @r   r   r   s  sf     1++*
" l3H5 5 5 
		
 
r'   r   c                   Z   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tRtV tR# )r   i  z@Mini parser for detecting character encoding from meta elements.c                4    \        V4      V n        R V n        R # r   )r   r`   r.   r2   r`   s   &&r   r3   EncodingParser.__init__  s    !$'	r'   c                L   R V P                   9  d   R# RV P                  R V P                  RV P                  RV P                  RV P                  RV P
                  /pV P                    Fz  pRp V P                   P                  R4       TP                  4        F0  w  rET P                   P                  T4      '       g   K(   T! 4       p M	  T'       d   Ko   T P                  # 	  V P                  #   \         d      T P                  # i ; i  \         d    Rp  KS  i ; i)	s   <metaNs   <!--s   </s   <!s   <?r   TF)r`   handle_commenthandle_metahandle_possible_end_taghandle_otherhandle_possible_start_tagr   r   itemsr   r.   )r2   method_dispatchrb   keep_parsingkeymethods   &     r   r   EncodingParser.get_encoding  s   499$ T((d&&4//4$$4$$$00
 AL		!!$'  /44699((--'-x	  7  <}}# " }} !  }} ) ',s$   0C4D4DDD#"D#c                8    V P                   P                  R4      # )zSkip over comments.s   -->r`   r   r>   s   &r   r   EncodingParser.handle_comment  s    yy  ((r'   c                
   V P                   P                  \        9  d   R # RpRp V P                  4       ;pf   R # V^ ,          R8X  d%   V^,          R8H  pV'       d   Ve	   W n        R# KG  KI  V^ ,          R8X  d#   V^,          p\        V4      pVe	   WPn        R# Ky  V^ ,          R8X  g   K  \        \        V^,          4      4      pVP                  4       ;pf   K  \        V4      pVf   K  V'       d	   WPn        R# TpK  )TFNs
   http-equivs   content-type   charsets   content)	r`   r   r   get_attributer.   r-   ContentAttributeParserr   parse)r2   
has_pragmapending_encoding	attributetentative_encodingcodeccontent_parsers   &      r   r   EncodingParser.handle_meta  s    99!!)??
!//11	:|},&q\_<
"2">$4M  #?: 1+%.q\"'(:;$$)M  % 1+!7iPQl8S!T*8*>*>*@@&M+,>?E(%,1M#(+0(r'   c                &    V P                  R R7      # )Fend_tag)handle_possible_tagr>   s   &r   r   (EncodingParser.handle_possible_start_tag  s    '''66r'   c                P    \        V P                  4       V P                  R R7      # )Tr  )nextr`   r  r>   s   &r   r   &EncodingParser.handle_possible_end_tag  s!    TYY'''55r'   c                $   V P                   pVP                  \        9  d+   V'       d!   VP                  4        V P	                  4        R # VP                  \        4      pVR8X  d   VP                  4        R #  V P                  4       e   K   R # )Tr   )r`   r   ascii_letters_bytesr   r   r   spaces_angle_bracketsr  )r2   r  r`   rV   s   &&  r   r  "EncodingParser.handle_possible_tag  sx    yy$77 !!#OO$9:	 MMO  %%'/r'   c                8    V P                   P                  R 4      # )r   r   r>   s   &r   r   EncodingParser.handle_other5  s    yy  &&r'   c                $   V P                   pVP                  \        \        R.4      ,          4      pVe   \	        V4      ^8X  g   Q hVR9   d   R# . p. p VR8X  d
   V'       d   MV\        9   d   VP                  4       pMiVR9   d   RP                  V4      R3# V\        9   d!   VP                  VP                  4       4       MVf   R# VP                  V4       \        V4      pK  VR8w  d$   VP                  4        RP                  V4      R3# \        V4       VP                  4       pT;pR9   d    \        V4      pW%8X  d.   \        V4       RP                  V4      RP                  V4      3# V\        9   d"   VP                  VP                  4       4       Kk  VP                  V4       K~  VR8X  d   RP                  V4      R3# V\        9   d!   VP                  VP                  4       4       MVf   R# VP                  V4        \        V4      pV\        9   d#   RP                  V4      RP                  V4      3# V\        9   d"   VP                  VP                  4       4       Ke  Vf   R# VP                  V4       K~  )	zkReturn a (name, value) pair for the next attribute in the stream.

If no attribute is found, return None.

   /Nr      =r'   )r   N)r  r   )   '   ")r`   r   r   	frozensetr   rj   ascii_uppercase_bytesr^   r   r  r   r  )r2   r`   rV   attribute_nameattribute_valuequotes   &     r   r  EncodingParser.get_attribute8  s5    yyII4y$7HHI	 C	Na$777$D ^44 IIK	l*xx/4433%%ioo&78"%%i0T
IMMO88N+S00T
IIK	E</ J	%J88N3SXXo5NNN"77#**9??+<= $**95$88N+S00//""9??#45""9-T
I11xx//1JJJ33&&y'89"&&y1r'   )r`   r.   N)rz   r{   r|   r}   r~   r3   r   r   r   r   r   r  r   r  r   r   r   s   @r   r   r     s=     J>)1B76.'L2 L2r'   r   c                   ,   a  ] tR tRt o R tR tRtV tR# )r  i  c                B    \        V\        4      '       g   Q hWn        R # r   )r   r   r`   r   s   &&r   r3   ContentAttributeParser.__init__  s    $&&&&	r'   c                    V P                   P                  R 4       V P                   ;P                  ^,          un        V P                   P                  4        V P                   P                  R8X  g   R# V P                   ;P                  ^,          un        V P                   P                  4        V P                   P                  R9   d   V P                   P                  pV P                   ;P                  ^,          un        V P                   P                  pV P                   P                  V4      '       d#   V P                   W P                   P                   # R# V P                   P                  p V P                   P                  \        4       V P                   W P                   P                   #   \         d    T P                   TR u # i ; i  \         d     R# i ; i)r  r  N)r   r  )r`   r   rR   r   r   r   r   r   )r2   r%  old_positions   &  r   r  ContentAttributeParser.parse  s_   	IIj)II!#IINN99))T1II!#IINNyy%%5		..		""a'"#yy1199$$U++99\))2D2DEE  $yy114II(()?@99\))2D2DEE$ 499\]334  		sD   A3G 7CG ?!G #G :A F; ;GG GG G*)G*)r`   N)rz   r{   r|   r}   r3   r  r   r   r   s   @r   r  r    s      r'   r  c                    \        V \        4      '       d    V P                  R4      p V e    \        P
                  ! V 4      # R#   \         d     R# i ; i  \         d     R# i ; i)zReturn the Python codec name corresponding to an encoding.

Return None if the string doesn't correspond to a valid encoding.

asciiN)r   r   decodeUnicodeDecodeErrorwebencodingslookupAttributeError)r.   s   &r   r-   r-     sn     (E""	w/H 	&&x00  " 		  		s"   A A AAA'&A')!r   rk   ior   r   pathlibr   r   r   r   r1  	constantsr   r	   r
   r!  r   r  r"  r  rl   r\   non_bmp_invalid_codepointsascii_punctuation_rerh   r&   r    r#   r   r   r   r  r-    r'   r   <module>r:     s5    	    1  : : #"N=M"NN H-HH !!LO!LL .D$<1HH ZZ=> NNNN&N(/N18N:ANCJNNNN&N(/N18N:ANCJN N N N  'N )0N 29N ;BN DKN 	N 	N 	N  '	N )0	N 29	N ;C	N EM	N  zzOQ   7o= o=dM2 M`VE Vrx2 x2v# #Lr'   