
    ^h>~                     <   S SK JrJrJr  S SKJr  S SKJrJr  S SKrS SK	r	S SK
JrJr  S SKrSSKJrJrJrJr  SSKJr  SS	KJr  \" \ V s/ s H  o R/                  S
5      PM     sn 5      r\" \ V s/ s H  o R/                  S
5      PM     sn 5      r\" \ V s/ s H  o R/                  S
5      PM     sn 5      r\\" SS/5      -  rSr\R:                  (       aB  \S   S:X  a  \R=                  S5      S:X  d   e\	R>                  " \SS \ " S5      -   S-   5      r!O\	R>                  " \5      r!1 Skr"\	R>                  " S5      r#0 r$ " S S\%5      r&S r' " S S\%5      r( " S S\(5      r) " S S\*5      r+ " S S\%5      r, " S S\%5      r-S  r.gs  sn f s  sn f s  sn f )!    )absolute_importdivisionunicode_literals)	text_type)http_clienturllibN)BytesIOStringIO   )EOFspaceCharactersasciiLettersasciiUppercase)_ReparseException)_utilsascii   >   <u   [---﷐-﷯￾￿🿾🿿𯿾𯿿𿿾𿿿񏿾񏿿񟿾񟿿񯿾񯿿񿿾񿿿򏿾򏿿򟿾򟿿򯿾򯿿򿿾򿿿󏿾󏿿󟿾󟿿󯿾󯿿󿿾󿿿􏿾􏿿]]z"\uD800-\uDFFF">            	 
               	 
       z[	- -/:-@\[-`{-~]c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)BufferedStream3   zBuffering for streams that do not have buffering of their own

The buffer is implemented as a list of chunks on the assumption that
joining many strings will be slow since it is O(n**2)
c                 0    Xl         / U l        SS/U l        g )Nr   r   )streambufferposition)selfr;   s     ^/home/james-whalen/.local/lib/python3.13/site-packages/bleach/_vendor/html5lib/_inputstream.py__init__BufferedStream.__init__:   s    Q    c                     SnU R                   S U R                  S     H  nU[        U5      -  nM     XR                  S   -  nU$ Nr   r   )r<   r=   len)r>   poschunks      r?   tellBufferedStream.tell?   sJ    [[!2$--"23E3u:C 4}}Q
rB   c                     XR                  5       ::  d   eUnSn[        U R                  U   5      U:  a>  U[        U R                  U   5      -  nUS-  n[        U R                  U   5      U:  a  M>  X2/U l        g rD   )_bufferedBytesrE   r<   r=   )r>   rF   offsetis       r?   seekBufferedStream.seekF   sx    ))++++$++a.!F*c$++a.))FFA $++a.!F* rB   c                 (   U R                   (       d  U R                  U5      $ U R                  S   [        U R                   5      :X  a:  U R                  S   [        U R                   S   5      :X  a  U R                  U5      $ U R	                  U5      $ )Nr   r   r   )r<   _readStreamr=   rE   _readFromBufferr>   bytess     r?   readBufferedStream.readO   st    {{##E**mmA#dkk"22mmA#dkk"o"66##E**''..rB   c                 j    [        U R                   Vs/ s H  n[        U5      PM     sn5      $ s  snf N)sumr<   rE   )r>   items     r?   rK   BufferedStream._bufferedBytesX   s'    $++6+$CI+6776s   0c                     U R                   R                  U5      nU R                  R                  U5        U R                  S==   S-  ss'   [        U5      U R                  S'   U$ rD   )r;   rU   r<   appendr=   rE   )r>   rT   datas      r?   rQ   BufferedStream._readStream[   sS    {{&4 aAt9arB   c                 $   Un/ nU R                   S   nU R                   S   nU[        U R                  5      :  a  US:w  a  US:  d   eU R                  U   nU[        U5      U-
  ::  a  UnXEU-   /U l         O%[        U5      U-
  nU[        U5      /U l         US-  nUR                  XeXW-    5        X'-  nSnU[        U R                  5      :  a  US:w  a  M  U(       a   UR                  U R	                  U5      5        SR                  U5      $ )Nr   r   rB   )r=   rE   r<   r]   rQ   join)r>   rT   remainingBytesrvbufferIndexbufferOffsetbufferedDatabytesToReads           r?   rR   BufferedStream._readFromBufferb   s   mmA&}}Q'C,,11D!A%%%;;{3L\!2\!AA,!,[.H I!,/,>!,c,.? @q IIl0JKL)NL C,,11D  IId&&~67xx|rB   )r<   r=   r;   N)__name__
__module____qualname____firstlineno____doc__r@   rH   rN   rU   rK   rQ   rR   __static_attributes__ rB   r?   r8   r8   3   s*     
$/8rB   r8   c                 0   [        U [        R                  5      (       dR  [        U [        R                  R
                  5      (       a,  [        U R                  [        R                  5      (       a  SnOA[        U S5      (       a   [        U R                  S5      [        5      nO[        U [        5      nU(       aJ  U Vs/ s H  o3R                  S5      (       d  M  UPM     nnU(       a  [        SU-  5      e[        U 40 UD6$ [        U 40 UD6$ s  snf )NFrU   r   	_encodingz3Cannot set an encoding with a unicode input, set %r)
isinstancer   HTTPResponser   responseaddbasefphasattrrU   r   endswith	TypeErrorHTMLUnicodeInputStreamHTMLBinaryInputStream)sourcekwargs	isUnicodex	encodingss        r?   HTMLInputStreamr   }   s     	6;3344	FFOO33	4	4	FII{77	8	8			 	 v{{1~y9	vy1	 &B1**[*AQ	BQT]]^^%f777$V6v66 Cs   DDc                   f    \ rS rSrSrSrS rS rS rS r	S r
S	 rSS jrS rS rSS jrS rSrg
)rz      Provides 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.

i (  c                 "   [         R                  (       d  SU l        O2[        S5      S:X  a  U R                  U l        OU R
                  U l        S/U l        [        S5      S4U l        U R                  U5      U l
        U R                  5         g)  Initialises the HTMLInputStream.

HTMLInputStream(source, [encoding]) -> Normalized stream from source
for use by html5lib.

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

The optional encoding parameter must be a string that indicates
the encoding.  If specified, that encoding will be used,
regardless of any BOM or later declaration (such as in a meta
element)

Nu   􏿿r   r   utf-8certain)r   supports_lone_surrogatesreportCharacterErrorsrE   characterErrorsUCS4characterErrorsUCS2newLineslookupEncodingcharEncoding
openStream
dataStreamreset)r>   r|   s     r?   r@   HTMLUnicodeInputStream.__init__   sv     .. *.D&!#)-)A)AD&)-)A)AD& +G4i@//&1

rB   c                 f    SU l         SU l        SU l        / U l        SU l        SU l        S U l        g )N r   )rG   	chunkSizechunkOffseterrorsprevNumLinesprevNumCols_bufferedCharacterr>   s    r?   r   HTMLUnicodeInputStream.reset   s;    
  #'rB   c                 F    [        US5      (       a  UnU$ [        U5      nU$ zfProduces a file object from source.

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

rU   )rw   r
   r>   r|   r;   s      r?   r   !HTMLUnicodeInputStream.openStream   s.     66""F  f%FrB   c                     U R                   nUR                  SSU5      nU R                  U-   nUR                  SSU5      nUS:X  a  U R                  U-   nXF4$ XS-   -
  nXF4$ )N
r   r   r   )rG   countr   rfindr   )r>   rL   rG   nLinespositionLinelastLinePospositionColumns          r?   	_position HTMLUnicodeInputStream._position   sy    

T1f-((61kk$62"!--6N -- $Q7N--rB   c                 J    U R                  U R                  5      u  pUS-   U4$ )z:Returns (line, col) of the current position in the stream.r   )r   r   )r>   linecols      r?   r=   HTMLUnicodeInputStream.position   s&    NN4#3#34	q#rB   c                     U R                   U R                  :  a  U R                  5       (       d  [        $ U R                   nU R                  U   nUS-   U l         U$ )zZRead one character from the stream or queue if available. Return
EOF when EOF is reached.
r   )r   r   	readChunkr   rG   )r>   r   chars      r?   r   HTMLUnicodeInputStream.char   sR    
 t~~->>##
&&zz+&&?rB   Nc                 n   Uc  U R                   nU R                  U R                  5      u  U l        U l        SU l        SU l        SU l        U R                  R                  U5      nU R                  (       a  U R                  U-   nS U l	        OU(       d  g[        U5      S:  a3  [        US   5      nUS:X  d  SUs=::  a  S::  a  O  OUS   U l	        US S nU R                  (       a  U R                  U5        UR                  S	S
5      nUR                  SS
5      nX l        [        U5      U l        g)Nr   r   Fr   r         i  z
r   T)_defaultChunkSizer   r   r   r   rG   r   r   rU   r   rE   ordr   replace)r>   r   r^   lastvs       r?   r    HTMLUnicodeInputStream.readChunk   s   ..I.2nnT^^.L+4+
##I. ""**T1D&*D#t9q=RME}% 96 9*.r('CRy%%&&t, ||FD)||D$'
TrB   c                     [        [        [        R                  U5      5      5       H  nU R                  R                  S5        M      g )Ninvalid-codepoint)rangerE   invalid_unicode_refindallr   r]   )r>   r^   _s      r?   r   *HTMLUnicodeInputStream.characterErrorsUCS4  s5    s-55d;<=AKK23 >rB   c                    Sn[         R                  U5       H  nU(       a  M  [        UR                  5       5      nUR	                  5       n[
        R                  " XUS-    5      (       aD  [
        R                  " XUS-    5      nU[        ;   a  U R                  R                  S5        SnM  US:  a5  US::  a/  U[        U5      S-
  :X  a  U R                  R                  S5        M  SnU R                  R                  S5        M     g )NF   r   Tr   i  r   )r   finditerr   groupstartr   isSurrogatePairsurrogatePairToCodepointnon_bmp_invalid_codepointsr   r]   rE   )r>   r^   skipmatch	codepointrF   char_vals          r?   r   *HTMLUnicodeInputStream.characterErrorsUCS2#  s     '006EEKKM*I++-C%%dsQw&788!::4C!G;LM99KK&&':;v%)v*=TQ&""#67""#67# 7rB   c           
          [         X4   n/ n UR                  U R                  U R                  5      nUc  U R                  U R                  :w  a  OONUR                  5       nXR                  :w  a/  UR                  U R                  U R                  U 5        Xl        O@UR                  U R                  U R                  S 5        U R                  5       (       d  OM  SR                  U5      n	U	$ ! [         a     U H  n[        U5      S:  a  M   e   SR                  U Vs/ s H  nS[        U5      -  PM     Os  snf sn5      nU(       d  SU-  n[        R
                  " SU-  5      =n[         X4'    GNtf = f)zReturns a string of characters from the stream up to but not
including any character in 'characters' or EOF. 'characters' must be
a container that supports the 'in' method and iteration over its
characters.
   r   z\x%02xz^%sz[%s]+N)charsUntilRegExKeyErrorr   ra   recompiler   rG   r   r   endr]   r   )
r>   
charactersoppositecharscregexrc   mr   rs
             r?   
charsUntil!HTMLUnicodeInputStream.charsUntil:  se   		Z#Z$:;E DJJ(8(89Ay ##t~~5 6 eeg ..(IIdjj)9)9#>?'*$ IIdjj!1!1!234>>##+ . GGBKG  	Z#Aq6C<(< $GGDAYQ/DEE>@jjSX>YYEOZ$:;	Zs#   
C5 5FF)E
<F Fc                     U[         Lan  U R                  S:X  a)  XR                  -   U l        U =R                  S-  sl        g U =R                  S-  sl        U R                  U R                     U:X  d   eg g rD   )r   r   rG   r   )r>   r   s     r?   ungetHTMLUnicodeInputStream.ungeti  sj     s?1$ "JJ.
!#  A% zz$"2"23t;;; rB   )r   r   rG   r   r   r   r   r   r   r   r   rX   )F)ri   rj   rk   rl   rm   r   r@   r   r   r   r=   r   r   r   r   r   r   rn   ro   rB   r?   rz   rz      sI     @'	.
$L48.-^<rB   rz   c                   P    \ rS rSrSr   SS jrS rS rSS jrS r	S	 r
S
 rSrg)r{   iz  r   Nc                 6   U R                  U5      U l        [        R                  X R                  5        SU l        SU l        X l        X0l        X@l        XPl	        X`l
        U R                  U5      U l        U R                  S   c   eU R                  5         g)r   i   d   r   N)r   	rawStreamrz   r@   numBytesMetanumBytesChardetoverride_encodingtransport_encodingsame_origin_parent_encodinglikely_encodingdefault_encodingdetermineEncodingr   r   )r>   r|   r   r   r   r   r   
useChardets           r?   r@   HTMLBinaryInputStream.__init__  s    $ 0''nn=
 !"!2"4+F(. 0 !22:>  #/// 	

rB   c                     U R                   S   R                  R                  U R                  S5      U l        [
        R                  U 5        g )Nr   r   )r   
codec_infostreamreaderr   r   rz   r   r   s    r?   r   HTMLBinaryInputStream.reset  s:    ++A.99FFt~~W`a$$T*rB   c                     [        US5      (       a  UnO[        U5      n UR                  UR                  5       5        U$ ! [         a    [        U5      n U$ f = fr   )rw   r	   rN   rH   	Exceptionr8   r   s      r?   r    HTMLBinaryInputStream.openStream  s]     66""FV_F	,KK&   	,#F+F	,s   A AAc                    U R                  5       S4nUS   b  U$ [        U R                  5      S4nUS   b  U$ [        U R                  5      S4nUS   b  U$ U R	                  5       S4nUS   b  U$ [        U R
                  5      S4nUS   b%  US   R                  R                  S5      (       d  U$ [        U R                  5      S4nUS   b  U$ U(       a   SSK	J
n  / nU" 5       nUR                  (       dy  U R                  R                  U R                  5      n[        U[         5      (       d   eU(       d  O5UR#                  U5        UR%                  U5        UR                  (       d  My  UR'                  5         [        UR(                  S   5      nU R                  R+                  S5        Ub  US4$  [        U R.                  5      S4nUS   b  U$ [        S5      S4$ ! [,         a     N8f = f)Nr   r   	tentativezutf-16)UniversalDetectorencodingwindows-1252)	detectBOMr   r   r   detectEncodingMetar   name
startswithr   chardet.universaldetectorr   doner   rU   r   rr   rT   r]   feedcloseresultrN   ImportErrorr   )r>   chardetr   r   buffersdetectorr<   r   s           r?   r   'HTMLBinaryInputStream.determineEncoding  s    ~~'2?& &d&<&<=yH?& &d&=&=>	I?& ..0+=?& &d&F&FGT?&|A/C/C/N/Nx/X/X &d&:&:;[H?& 1G ,."--!^^001E1EFF%fe4444!NN6*MM&) #---  )(//**EF##A&'#[00 ( &d&;&;<kI?& n-{::1  s   G, ,
G98G9c                    U R                   S   S:w  d   e[        U5      nUc  g UR                  S;   a  [        S5      nUc   eg XR                   S   :X  a  U R                   S   S4U l         g U R                  R	                  S5        US4U l         U R                  5         [        SU R                   S   < SU< 35      e)Nr   r   utf-16beutf-16ler   r   zEncoding changed from z to )r   r   r   r   rN   r   r   )r>   newEncodings     r?   changeEncoding$HTMLBinaryInputStream.changeEncoding  s      #y000$[177(1K***--a00!%!2!21!5y ADNN"!,i 8DJJL#HYHYZ[H\^i$jkkrB   c           
      6   [         R                  S[         R                  S[         R                  S[         R                  S[         R
                  S0nU R                  R                  S5      n[        U[        5      (       d   eUR                  USS 5      nSnU(       d0  UR                  U5      nSnU(       d  UR                  USS	 5      nS	nU(       a&  U R                  R                  U5        [        U5      $ U R                  R                  S
5        g)zAttempts 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 Noner   r  r  zutf-32lezutf-32be   N   r   r   )codecsBOM_UTF8BOM_UTF16_LEBOM_UTF16_BEBOM_UTF32_LEBOM_UTF32_BEr   rU   rr   rT   getrN   r   )r>   bomDictstringr   rN   s        r?   r   HTMLBinaryInputStream.detectBOM  s    
 OOWV-@-@*V-@-@*
 $$Q'&%(((( ;;vbqz*{{6*HD";;vbqz2 NN%!(++NN"rB   c                 &   U R                   R                  U R                  5      n[        U[        5      (       d   e[        U5      nU R                   R                  S5        UR                  5       nUb  UR                  S;   a  [        S5      nU$ )z9Report the encoding declared by the meta element
        r   r  r   )
r   rU   r   rr   rT   EncodingParserrN   getEncodingr   r   )r>   r<   parserr   s       r?   r   (HTMLBinaryInputStream.detectEncodingMeta3  s|     $$T%6%67&%(((('A%%'HMM5M$M%g.HrB   )
r   r   r   r   r   r   r   r   r   r   )NNNNr   T)T)ri   rj   rk   rl   rm   r@   r   r   r   r  r   r   rn   ro   rB   r?   r{   r{   z  s;     KOCG=A(T+&<;|l  DrB   r{   c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 r\" \\5      rS r\" \5      r\4S jrS rS rS rSrg)EncodingBytesiB  zString-like object with an associated position and various extra methods
If the position is ever greater than the string length then an exception is
raisedc                 v    [        U[        5      (       d   e[        R                  XR                  5       5      $ rX   )rr   rT   __new__lowerr>   values     r?   r(  EncodingBytes.__new__F  s*    %''''}}T;;=11rB   c                     SU l         g )Nr   r   r*  s     r?   r@   EncodingBytes.__init__J  s	    rB   c                     U $ rX   ro   r   s    r?   __iter__EncodingBytes.__iter__N  s    rB   c                 |    U R                   S-   =ol         U[        U 5      :  a  [        eUS:  a  [        eXUS-    $ )Nr   r   r   rE   StopIterationry   r>   ps     r?   __next__EncodingBytes.__next__Q  s@    !^^a//ND	>UOa!e}rB   c                 "    U R                  5       $ rX   )r8  r   s    r?   nextEncodingBytes.nextY  s    }}rB   c                     U R                   nU[        U 5      :  a  [        eUS:  a  [        eUS-
  =U l         nXUS-    $ rD   r4  r6  s     r?   previousEncodingBytes.previous]  sF    NND	>UOU"a!e}rB   c                 N    U R                   [        U 5      :  a  [        eXl         g rX   r   rE   r5  )r>   r=   s     r?   setPositionEncodingBytes.setPositionf  s    >>SY&!rB   c                 z    U R                   [        U 5      :  a  [        eU R                   S:  a  U R                   $ g )Nr   rA  r   s    r?   getPositionEncodingBytes.getPositionk  s1    >>SY&>>Q>>!rB   c                 8    X R                   U R                   S-    $ Nr   )r=   r   s    r?   getCurrentByteEncodingBytes.getCurrentByteu  s    MM$--!"344rB   c                     U R                   nU[        U 5      :  a*  XUS-    nX1;  a  X l        U$ US-  nU[        U 5      :  a  M*  X l        g)zSkip past a list of charactersr   Nr=   rE   r   r>   r   r7  r   s       r?   r   EncodingBytes.skipz  sR    MM#d)mq1uA~!"FA #d)m rB   c                     U R                   nU[        U 5      :  a*  XUS-    nX1;   a  X l        U$ US-  nU[        U 5      :  a  M*  X l        g rH  rL  rM  s       r?   	skipUntilEncodingBytes.skipUntil  sR    MM#d)mq1uAz!"FA #d)m rB   c                     U R                  XR                  5      nU(       a  U =R                  [        U5      -  sl        U$ )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  r=   rE   )r>   rT   rc   s      r?   
matchBytesEncodingBytes.matchBytes  s0     __UMM2MMSZ'M	rB   c                      U R                  XR                  5      [        U5      -   S-
  U l        g! [         a    [
        ef = f)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 matchr   T)indexr=   rE   r   
ValueErrorr5  rS   s     r?   jumpToEncodingBytes.jumpTo  sE    	 !ZZ}}=E
JQNDN   	 	 s	   /2 Ar.  N)ri   rj   rk   rl   rm   r(  r@   r1  r8  r;  r>  rB  rE  propertyr=   rI  currentBytespaceCharactersBytesr   rP  rS  rX  rn   ro   rB   r?   r&  r&  B  se    2"
 [1H5 >*K- 
	rB   r&  c                   N    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rSrg)r!  i  z?Mini parser for detecting character encoding from meta elementsc                 2    [        U5      U l        SU l        g)z3string - the data to work on for encoding detectionN)r&  r^   r   r>   r^   s     r?   r@   EncodingParser.__init__  s    !$'	rB   c                 0   SU R                   ;  a  g SU R                  4SU R                  4SU R                  4SU R                  4SU R                  4SU R
                  44nU R                    Hj  nSn U R                   R                  S5        U H/  u  pEU R                   R                  U5      (       d  M'   U" 5       n  O   U(       a  M_    U R                  $    U R                  $ ! [         a       U R                  $ f = f! [         a    Sn   MP  f = f)	Ns   <metas   <!--s   </s   <!s   <?r   TF)
r^   handleComment
handleMetahandlePossibleEndTaghandleOtherhandlePossibleStartTagrX  r5  rS  r   )r>   methodDispatchr   keepParsingkeymethods         r?   r"  EncodingParser.getEncoding  s"   499$ d(()t'D--.D$$%D$$%4../1 AK		  &  .99'',,&,h	  . ;}}# " }} !  }} ) &+s$   4C(9D(
D DDDc                 8    U R                   R                  S5      $ )zSkip over commentss   -->r^   rX  r   s    r?   rb  EncodingParser.handleComment  s    yy''rB   c                    U R                   R                  [        ;  a  gSnS n U R                  5       nUc  gUS   S:X  a  US   S:H  nU(       a
  Ub  X l        gOuUS   S:X  a  US   n[        U5      nUb  XPl        gOQUS   S:X  aH  [        [        US   5      5      nUR                  5       nUb  [        U5      nUb  U(       a  XPl        gUnM  )	NTFr   s
   http-equivr   s   content-type   charsets   content)	r^   r[  r\  getAttributer   r   ContentAttrParserr&  parse)r>   	hasPragmapendingEncodingattrtentativeEncodingcodeccontentParsers          r?   rc  EncodingParser.handleMeta  s    99  (<<	$$&D|7m+ $Q? :I _%@(7$!W
*(,Q%*+<=E((-$ ) !W
*$5mDG6L$MM(5(;(;(=%(4 ./@ A ,(05',277 rB   c                 $    U R                  S5      $ )NF)handlePossibleTagr   s    r?   rf  %EncodingParser.handlePossibleStartTag  s    %%e,,rB   c                 N    [        U R                  5        U R                  S5      $ )NT)r;  r^   r|  r   s    r?   rd  #EncodingParser.handlePossibleEndTag  s    TYY%%d++rB   c                 <   U R                   nUR                  [        ;  a(  U(       a   UR                  5         U R	                  5         gUR                  [        5      nUS:X  a  UR                  5         gU R                  5       nUb  U R                  5       nUb  M  g)NTr   )r^   r[  asciiLettersBytesr>  re  rP  spacesAngleBracketsrq  )r>   endTagr^   r   rv  s        r?   r|   EncodingParser.handlePossibleTag  s    yy#44   "NN./9 MMO  $$&D"((* "rB   c                 8    U R                   R                  S5      $ )Nr   rm  r   s    r?   re  EncodingParser.handleOther  s    yy%%rB   c                    U R                   nUR                  [        [        S/5      -  5      nUb  [	        U5      S:X  d   eUS;   a  g/ n/ n US:X  a  U(       a  OU[        ;   a  UR                  5       nOeUS;   a  SR                  U5      S4$ U[        ;   a   UR                  UR                  5       5        OUc  gUR                  U5        [        U5      nM  US:w  a#  UR                  5         SR                  U5      S4$ [        U5        UR                  5       nUS;   a}  Un [        U5      nX%:X  a-  [        U5        SR                  U5      SR                  U5      4$ U[        ;   a   UR                  UR                  5       5        OUR                  U5        Mz  US	:X  a  SR                  U5      S4$ U[        ;   a   UR                  UR                  5       5        OUc  gUR                  U5         [        U5      nU[        ;   a"  SR                  U5      SR                  U5      4$ U[        ;   a   UR                  UR                  5       5        OUc  gUR                  U5        Mx  )
zWReturn a name,value pair for the next attribute in the stream,
if one is found, or None   /Nr   )r   N   =)r  r   rB   )   '   "r   )r^   r   r\  	frozensetrE   ra   asciiUppercaseBytesr]   r)  r;  r>  r  )r>   r^   r   attrName	attrValue	quoteChars         r?   rq  EncodingParser.getAttribute  s7    yyII*Yv->>?yCFaK''	DyX**IIKl"xx)3..))	*"T
A! $ 9MMO88H%s**T
IIKIJ>J88H-sxx	/BBB--$$QWWY/ $$Q'  $Y88H%s**%%QWWY'YQT
A''xx)388I+>>>))  +  # rB   )r^   r   N)ri   rj   rk   rl   rm   r@   r"  rb  rc  rf  rd  r|  re  rq  rn   ro   rB   r?   r!  r!    s4    I
<("8H-,.&J$rB   r!  c                        \ rS rSrS rS rSrg)rr  i`  c                 >    [        U[        5      (       d   eXl        g rX   )rr   rT   r^   r_  s     r?   r@   ContentAttrParser.__init__a  s    $&&&&	rB   c                     U R                   R                  S5        U R                   =R                  S-  sl        U R                   R                  5         U R                   R                  S:X  d  g U R                   =R                  S-  sl        U R                   R                  5         U R                   R                  S;   a  U R                   R                  nU R                   =R                  S-  sl        U R                   R                  nU R                   R                  U5      (       a"  U R                   X R                   R                   $ g U R                   R                  n U R                   R                  [        5        U R                   X R                   R                   $ ! [         a    U R                   US  s $ f = f! [         a     g f = f)Nrp  r   r  )r  r  )r^   rX  r=   r   r[  rP  r\  r5  )r>   	quoteMarkoldPositions      r?   rs  ContentAttrParser.parsee  sa   	 IIZ(II!#IINN99((D0II!#IINNyy$$4 II11			""a'""ii0099##I..99[1C1CDD #ii003II''(<=99[1C1CDD$ 399[\223  		s>   A.G	 1CG	 G	 )A F* *GG	 GG	 	
GG)r^   N)ri   rj   rk   rl   r@   rs  rn   ro   rB   r?   rr  rr  `  s    rB   rr  c                     [        U [        5      (       a   U R                  S5      n U b   [        R
                  " U 5      $ g! [         a     gf = f! [         a     gf = f)zwReturn the python codec name corresponding to an encoding or None if the
string doesn't correspond to a valid encoding.r   N)rr   rT   decodeUnicodeDecodeErrorwebencodingslookupAttributeError)r   s    r?   r   r     sn     (E""	w/H 	&&x00  " 		  		s"   A A 
AA
A A )/
__future__r   r   r   bleach.six_shimr   r   r   r  r   ior	   r
   r  	constantsr   r   r   r   r   r   r   r  encoder\  r  r  r  invalid_unicode_no_surrogater   r   r   evalr   r   ascii_punctuation_rer   objectr8   r   rz   r{   rT   r&  r!  rr  r   )rZ   s   0r?   <module>r     s   B B % /  	    I I (  !?!S?4++g"6?!ST M{{73MN . Q.$W!5. QR *Yd|-DD   j 	""
 (+s27S7Y7YZ]7^bc7ccc$@"$E$()<$=%>$'%( ) $@A2  zz"mn  GV GT7.c<V c<LE2 EP_E _Dy$V y$x$ $Nm "TM Qs   F2FF