o
    gޣ                     @   s   d dl Z d dlZd dlZd dlZd dlZG dd dZG dd deZG dd deZ	G dd	 d	e
ZG d
d de
ZG dd deZG dd deZG dd deZG dd dejZedkrfe  dS dS )    Nc                   @   s   e Zd Zdd Zdd ZdS )	PosReturnc                 C   s
   d| _ d S )Nr   )posself r   N/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/test_codeccallbacks.py__init__   s   
zPosReturn.__init__c                 C   s>   | j }|}|dk rt|j| }||jkrt|j| _ d|fS )Nr   <?>)r   lenobjectstart)r   excZoldposZrealposr   r   r   handle   s   
zPosReturn.handleN)__name__
__module____qualname__r   r   r   r   r   r   r      s    r   c                   @      e Zd Zdd ZdS )BadStartUnicodeEncodeErrorc                 C      t | ddddd g | _d S Nascii r      bad)UnicodeEncodeErrorr   r   r   r   r   r   r         
z#BadStartUnicodeEncodeError.__init__Nr   r   r   r   r   r   r   r   r          r   c                   @   r   )BadObjectUnicodeEncodeErrorc                 C   r   r   )r   r   r   r   r   r   r   r   !   r   z$BadObjectUnicodeEncodeError.__init__Nr   r   r   r   r   r       r   r   c                   @   r   )NoEndUnicodeDecodeErrorc                 C   s    t | dtdddd | `d S Nr       r   r   r   )UnicodeDecodeErrorr   	bytearrayendr   r   r   r   r   '   s   z NoEndUnicodeDecodeError.__init__Nr   r   r   r   r   r   &   r   r   c                   @   r   )BadObjectUnicodeDecodeErrorc                 C   s"   t | dtdddd g | _d S r    )r"   r   r#   r   r   r   r   r   r   -   s   
z$BadObjectUnicodeDecodeError.__init__Nr   r   r   r   r   r%   ,   r   r%   c                   @   r   )NoStartUnicodeTranslateErrorc                 C      t | dddd | `d S Nr   r   r   r   )UnicodeTranslateErrorr   r   r   r   r   r   r   3      z%NoStartUnicodeTranslateError.__init__Nr   r   r   r   r   r&   2   r   r&   c                   @   r   )NoEndUnicodeTranslateErrorc                 C   r'   r(   )r)   r   r$   r   r   r   r   r   9   r*   z#NoEndUnicodeTranslateError.__init__Nr   r   r   r   r   r+   8   r   r+   c                   @   r   )NoObjectUnicodeTranslateErrorc                 C   r'   r(   )r)   r   r   r   r   r   r   r   ?   r*   z&NoObjectUnicodeTranslateError.__init__Nr   r   r   r   r   r,   >   r   r,   c                   @   s$  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGS )HCodecCallbackTestc                 C   s0   d}|  |ddd |  |ddd d S )Nu   スパモ änd eggsr   xmlcharrefreplaces&   &#12473;&#12497;&#12514; &#228;nd eggslatin-1s!   &#12473;&#12497;&#12514; nd eggsassertEqualencode)r   sr   r   r   test_xmlcharrefreplaceE   s   

z(CodecCallbackTest.test_xmlcharrefreplacec                 C   d   dd }t d| d}d}| |dd| d}| |dd| d	}| |d
d| d S )Nc              	   S   s   t | tstd|  g }| j| j| j D ]#}z|dtjj	t
|   W q ty9   |dt
|  Y qw d|| jfS )Ndon't know how to handle %rz&%s;&#%d;r   )
isinstancer   	TypeErrorr   r   r$   appendhtmlZentitiesZcodepoint2nameordKeyErrorjoinr   lcr   r   r   xmlcharnamereplaceW   s   
zECodecCallbackTest.test_xmlcharnamereplace.<locals>.xmlcharnamereplaceztest.xmlcharnamereplaceu   «ℜ» = 〈ሴ€〉s0   &laquo;&real;&raquo; = &lang;&#4660;&euro;&rang;r   s$   &real; = &lang;&#4660;&euro;&rang;r/   s   &real; = &lang;&#4660;&rang;iso-8859-15codecsregister_errorr1   r2   )r   rB   sinsoutr   r   r   test_xmlcharnamereplaceS   s   z)CodecCallbackTest.test_xmlcharnamereplacec                 C   r5   )Nc              	   S   s`   t | tstd|  g }| j| j| j D ]}|t|dt	|  qdd
| | jfS )Nr6   z0x%xz
[1m%s[0mz, )r8   r   r9   r   r   r$   r:   unicodedatanamer<   r>   r?   r   r   r   uninamereplacev   s   
z=CodecCallbackTest.test_uninamereplace.<locals>.uninamereplaceztest.uninamereplaceu   ¬ሴ€耀sN   [1mNOT SIGN, ETHIOPIC SYLLABLE SEE, EURO SIGN, CJK UNIFIED IDEOGRAPH-8000[0mr   sE   [1mETHIOPIC SYLLABLE SEE, EURO SIGN, CJK UNIFIED IDEOGRAPH-8000[0mr/   sA   [1mETHIOPIC SYLLABLE SEE[0m[1mCJK UNIFIED IDEOGRAPH-8000[0mrC   rD   )r   rL   rG   rH   r   r   r   test_uninamereplacem   s   	z%CodecCallbackTest.test_uninamereplacec                 C   P   d}d}|  |dd| d}|  |dd| d}|  |dd| d S )	N   a¬ሴ€耀􏿿s!   a\xac\u1234\u20ac\u8000\U0010ffffr   backslashreplaces   a\u1234\u20ac\u8000\U0010ffffr/   s   a\u1234\u8000\U0010ffffrC   r0   r   rG   rH   r   r   r   test_backslashescape   s   z&CodecCallbackTest.test_backslashescapec                 C   rN   )	NrO   s[   a\N{NOT SIGN}\N{ETHIOPIC SYLLABLE SEE}\N{EURO SIGN}\N{CJK UNIFIED IDEOGRAPH-8000}\U0010ffffr   namereplacesP   a\N{ETHIOPIC SYLLABLE SEE}\N{EURO SIGN}\N{CJK UNIFIED IDEOGRAPH-8000}\U0010ffffr/   sD   a\N{ETHIOPIC SYLLABLE SEE}\N{CJK UNIFIED IDEOGRAPH-8000}\U0010ffffrC   r0   rQ   r   r   r   test_nameescape   s   z!CodecCallbackTest.test_nameescapec                 C   sJ   dd }t d| d}d}| |dd| d}| t|jdd d S )Nc                 S   sB   t | tstd|  | j| j| jd  dkrd| jd fS | )Nr6      s    )r8   r"   r9   r   r   r   r   r   r   relaxedutf8   s
   
z>CodecCallbackTest.test_decoding_callbacks.<locals>.relaxedutf8ztest.relaxedutf8s   a bcüu	   a b cü  utf-8s   )rE   rF   r1   decodeassertRaisesr"   )r   rX   rG   rH   r   r   r   test_decoding_callbacks   s   
z)CodecCallbackTest.test_decoding_callbacksc                 C   s   t dd dD }d}d}| t|d|d | d}| ttj|d| d	|td
< d}d}| t|d|d | d|td
< | ttj|d| d S )Nc                 s   s*    | ]}t |td |  dfV  qdS )rU   r   N)r<   bytesupper.0rA   r   r   r   	<genexpr>   s   ( z7CodecCallbackTest.test_charmapencode.<locals>.<genexpr>Zabcdefghabcs   AABBCCstrictr   ZabcAs   XYZ?ZabcDEFs   AABBCCXYZXYZXYZreplaceZXYZ)dictr1   rE   charmap_encoder[   UnicodeErrorr<   r9   )r   charmaprG   rH   r   r   r   test_charmapencode   s   z$CodecCallbackTest.test_charmapencodec                 C   s   dd }t d| dd }t d| d}| |ddd	 | |ddd
 | dddd | dddd | t ddtddid d | dddd | dddd d S )Nc                    sj   t  j j}t tr fdd|D }nt tr% fdd|D }ntd  dd|  jfS )Nc                    s   g | ]}d t  j|  qS z<%d>)r<   r   r`   r   rW   r   r   
<listcomp>   s    zFCodecCallbackTest.test_callbacks.<locals>.handler1.<locals>.<listcomp>c                       g | ]	}d  j |  qS rk   r   rl   rW   r   r   rm          r6   [%s]r   )ranger   r$   r8   r   r"   r9   r>   )r   rr@   r   rW   r   handler1   s   

z2CodecCallbackTest.test_callbacks.<locals>.handler1ztest.handler1c                    sJ   t  tstd   fddt j jD }dd|  jd fS )Nr6   c                    rn   rk   ro   rl   rW   r   r   rm      rp   zFCodecCallbackTest.test_callbacks.<locals>.handler2.<locals>.<listcomp>rq   r   r   )r8   r"   r9   rr   r   r$   r>   )r   r@   r   rW   r   handler2   s   
z2CodecCallbackTest.test_callbacks.<locals>.handler2ztest.handler2s    r   z [<129>][<128>][<255>]z [<129>][<128>]s   \u3042\u3xxxunicode-escapeu   あ[<92><117><51>]xxxs   \u3042\u3xxu   あ[<92><117><51>]xxs   abcazr   zz[<98>][<99>]u   güßrks   g[<252><223>]rku   güßs   g[<252><223>])rE   rF   r1   rZ   charmap_decoder<   r2   )r   rt   ru   r3   r   r   r   test_callbacks   sB   






z CodecCallbackTest.test_callbacksc                    s   g d}|D ]}t d| t | qd |dd |D 7 } fdddD D ]}dD ]}|D ]}z||| W q0 tyC   Y q0w q,q(d S )	N)rc   ignorere   r.   rP   rS   test.  c                 S   s   g | ]}d | qS )r|   r   )r`   errr   r   r   rm         z6CodecCallbackTest.test_longstrings.<locals>.<listcomp>c                    s   g | ]}|  qS r   r   )r`   r3   r@   r   r   rm     r   )x   あu   aä)r   r/   
iso-8859-1rC   rY   utf-7utf-16utf-32)rE   rF   lookup_errorr2   rh   )r   errorsr~   Zuniencr   r   r   test_longstrings  s    z"CodecCallbackTest.test_longstringsc           
      C   s   | j t|g|d d R   | j t|g|dg R   g d}tt|D ]8}|D ]3}t|t|| u r6q)g }tt|D ]}||krJ|| q>|||  q>| j t|g|R   q)q%|| }	| t|	| d S )Nztoo much)Zspams   eggss   spam*   g      ?N)r[   r9   rr   r
   typer:   r1   str)
r   exctypeargsmsgZ	wrongargsiZwrongargZcallargsjr   r   r   r   check_exceptionobjectargs"  s    z+CodecCallbackTest.check_exceptionobjectargsc                 C   sp   |  tg dd |  tg dd |  tg dd |  tg dd |  tg d	d
 |  tg dd d S )N)r      gürkr   rU   ouchz?'ascii' codec can't encode character '\xfc' in position 1: ouch)r   r   r      r   z;'ascii' codec can't encode characters in position 1-3: ouch)r   u   üxr   r   r   z?'ascii' codec can't encode character '\xfc' in position 0: ouch)r   u   Āxr   r   r   zA'ascii' codec can't encode character '\u0100' in position 0: ouch)r   u   ￿xr   r   r   zA'ascii' codec can't encode character '\uffff' in position 0: ouch)r   u   𐀀xr   r   r   zE'ascii' codec can't encode character '\U00010000' in position 0: ouch)r   r   r   r   r   r   test_unicodeencodeerror;  s<   z)CodecCallbackTest.test_unicodeencodeerrorc                 C   s<   |  tdtddddgd |  tdtddddgd d S )	Nr   s   grkr   rU   r   z8'ascii' codec can't decode byte 0xfc in position 1: ouch   z6'ascii' codec can't decode bytes in position 1-2: ouch)r   r"   r#   r   r   r   r   test_unicodedecodeerror[  s   z)CodecCallbackTest.test_unicodedecodeerrorc                 C   s^   |  tg dd |  tg dd |  tg dd |  tg dd |  tg d	d
 d S )N)r   r   rU   r   z4can't translate character '\xfc' in position 1: ouch)u   gĀrkr   rU   r   z6can't translate character '\u0100' in position 1: ouch)u   g￿rkr   rU   r   z6can't translate character '\uffff' in position 1: ouch)u   g𐀀rkr   rU   r   z:can't translate character '\U00010000' in position 1: ouch)r   r   r   r   z0can't translate characters in position 1-2: ouch)r   r)   r   r   r   r   test_unicodetranslateerrorg  s2   z,CodecCallbackTest.test_unicodetranslateerrorc              
   C   s~   |  ttjd |  ttjtd |  ttjtddddd |  ttjtdtdddd |  ttjtdddd d S )Nr   r   r   r   r   r      )	r[   r9   rE   strict_errors	Exceptionr   r"   r#   r)   r   r   r   r   test_badandgoodstrictexceptions  s2   z1CodecCallbackTest.test_badandgoodstrictexceptionsc              
   C   s   |  ttjd |  ttjtd | ttdddddd | ttdtddddd | tt	ddddd d S )	Nr   r   r      aあbr   rU   )r   rU      ab)
r[   r9   rE   ignore_errorsrh   r1   r   r"   r#   r)   r   r   r   r   test_badandgoodignoreexceptions  s8   z1CodecCallbackTest.test_badandgoodignoreexceptionsc              
   C   s   |  ttjd |  ttjtd |  ttjt  |  ttjt  | ttdddddd | tt	dt
ddddd	 | ttddddd	 d S )
Nr   r   r   r   r   rU   )rd   rU   r   )   �rU   )r[   r9   rE   replace_errorsrh   r   r%   r1   r   r"   r#   r)   r   r   r   r    test_badandgoodreplaceexceptions  sL   z2CodecCallbackTest.test_badandgoodreplaceexceptionsc                 C   s   |  ttjd |  ttjtd |  ttjtdtdddd |  ttjtdddd d}|d	7 }d
dd |D }| 	tt
dd| d ddt| dd
dd |D dt| f d S )Nr   r   r   r   r   r   r   )r   r   	   
   c   d   i  r}   i'  '  i 順 i?B @B )i   i  r   c                 s   s    | ]}t |V  qd S Nchrr_   r   r   r   ra         zOCodecCallbackTest.test_badandgoodxmlcharrefreplaceexceptions.<locals>.<genexpr>rw   bc                 s   s    | ]}d | V  qdS )r7   Nr   r_   r   r   r   ra   	  r   )r[   r9   rE   xmlcharrefreplace_errorsrh   r"   r#   r)   r>   r1   r   r
   )r   Zcsr3   r   r   r   *test_badandgoodxmlcharrefreplaceexceptions  s>   z<CodecCallbackTest.test_badandgoodxmlcharrefreplaceexceptionsc                 C   sL  |  ttjd |  ttjtd g d}|D ]S\}}| j|dA | ttdd| d ddt| d|dt| f | tt	d| d ddt| d|dt| f W d    q1 sfw   Y  qg d	}|D ]1\}}| j|d
 | tt
dtd| d ddd|df W d    qr1 sw   Y  qrd S )Nr   r   ))r   z\u3042)
\x0a)rw   \x61rV   \x00)   ÿ\xff)u   Āz\u0100)u   ￿z\uffff)u   𐀀z
\U00010000u   􏿿z
\U0010ffff   z\ud800   z\udfff   z\ud800\udfffr   r   rw   r   r   ))   ar   )   
r   )    r   )r   r   )r]   r      brU   )r[   r9   rE   backslashreplace_errorsrh   subTestr1   r   r
   r)   r"   r#   )r   testsr3   rs   r   r   r   r   )test_badandgoodbackslashreplaceexceptions  sV   z;CodecCallbackTest.test_badandgoodbackslashreplaceexceptionsc                 C   s   |  ttjd |  ttjtd |  ttjtdtdddd |  ttjtdddd g d}|D ]7\}}| j|d	% | 	tt
dd
| d ddt| d|dt| f W d    q51 sgw   Y  q5d S )Nr   r   r   r   r   r   r   ))r   z\N{HIRAGANA LETTER A}r   )u   ﯹzW\N{ARABIC LIGATURE UIGHUR KIRGHIZ YEH WITH HAMZA ABOVE WITH ALEF MAKSURA ISOLATED FORM})u   󠁿z\N{CANCEL TAG}r   r   r   r   r   rw   r   )r[   r9   rE   namereplace_errorsrh   r"   r#   r)   r   r1   r   r
   )r   r   r3   rs   r   r   r   $test_badandgoodnamereplaceexceptionsF  sB   z6CodecCallbackTest.test_badandgoodnamereplaceexceptionsc                 C   s   t d}| t|d | t|td | t|tdddd dD ]%}| j|d | t|td	|ddd W d    q#1 sCw   Y  q#| |td	d
dddd | t	|t	d	t
dddd | |t	d	t
ddddd d S )Nsurrogateescaper   r      r   r   )rw   u   u   r   r   u   abrU   )   rU   r   s   ab)r   rU   )rE   r   r[   r9   rh   r)   r   r   r1   r"   r#   )r   Zsurrogateescape_errorsr3   r   r   r   (test_badandgoodsurrogateescapeexceptionst  sR   
z:CodecCallbackTest.test_badandgoodsurrogateescapeexceptionsc                 C   s  t d}| t|d | t|td | t|tdddd dD ]5}| j|d% | t|t|d	ddd | t|t|d		|ddd W d    q#1 sSw   Y  q#d
D ]'}| j|d | t|td|dt
|d W d    q[1 s}w   Y  q[g d}|D ]\\}}}}| j|||dF | |t|d	| d ddt
| d|dt
| f | |t|td|d |  d dd| d|d d d| f W d    q1 sw   Y  qd S )Nsurrogatepassr   r   r   r   r   )rY   utf-16leutf-16beutf-32leutf-32be)encodingrw   )r   r   r   r   r   ))rY   r   s   r   )r   r   s    rU   )r   r   s    rU   )r   r   s      r   )r   r   s      r   )rY   r   s   r   )r   r   s   rU   )r   r   s   rU   )r   r   s     r   )r   r   s     r   )rY   r   s   r   )r   r   s    rU   )r   r   s    rU   )r   r   s        r   )r   r   s        r   )r   r   r]   r   r   r   )rE   r   r[   r9   rh   r)   r   r   r"   r2   r
   r1   r#   )r   Zsurrogatepass_errorsr   r3   r   r   nr   r   r   &test_badandgoodsurrogatepassexceptions  st   

z8CodecCallbackTest.test_badandgoodsurrogatepassexceptionsc                    sf   d}d}|D ]* t d fdd |D ]}| tdj|d qdD ]\}}| t|j|d q"qd S )N)	r   foo)r   rU   r   r   r   r   r   Nr   r   r   r   )r   r/   r   rC   ztest.badhandlerc                    s    S r   r   )r   resr   r   <lambda>  s    z:CodecCallbackTest.test_badhandlerresults.<locals>.<lambda>r   )r   r   rY   r   )r   s   +x-)rE   rF   r[   r9   r2   rZ   )r   resultsZencsr   r]   r   r   r   test_badhandlerresults  s(   z(CodecCallbackTest.test_badhandlerresultsc                 C   s|   |  tjtd |  tjtd |  tjtd |  tjtd |  tjtd |  tjtd d S )Nrc   r{   r.   rP   rS   )r1   rE   r   r   r   r   r   r   r   r   r   r   test_lookup  s   zCodecCallbackTest.test_lookupc                 C   s4   dd }t d| dD ]}| tdj|d qd S )Nc                 S   s    t | tr
d| jfS td|  )N   䉂r6   )r8   r   r$   r9   rW   r   r   r   	unencrepl  s   

z@CodecCallbackTest.test_unencodablereplacement.<locals>.unencreplztest.unencreplhandler)r   r   rC   r   )rE   rF   r[   r   r2   )r   r   r   r   r   r   test_unencodablereplacement  s   z-CodecCallbackTest.test_unencodablereplacementc                 C   s&   |  ttjd |  ttjdd d S )Nr   z
test.dummy)r[   r9   rE   rF   r   r   r   r   test_badregistercall!  s   z&CodecCallbackTest.test_badregistercallc                 C   s   |  ttj d S r   )r[   r9   rE   r   r   r   r   r   test_badlookupcall(  s   z$CodecCallbackTest.test_badlookupcallc                 C   s   |  ttjd d S )Ntest.unknown)r[   LookupErrorrE   r   r   r   r   r   test_unknownhandler-  s   z%CodecCallbackTest.test_unknownhandlerc                 C   sJ   d}d dd |D }tdtj dD ]}dD ]}||| qqd S )N)r      r   2   r   i  r}   i  r   iP  r   i  r   r   c                 S   s   g | ]}t |qS r   r   )r`   r   r   r   r   rm   8  r   z;CodecCallbackTest.test_xmlcharrefvalues.<locals>.<listcomp>test.xmlcharrefreplace)r   rC   )r.   r   )r>   rE   rF   r   r2   )r   vr3   r   r~   r   r   r   test_xmlcharrefvalues2  s   z'CodecCallbackTest.test_xmlcharrefvaluesc              	   C   s  |  tdjdd dd }td| |  tdjdd |  tdjdd |  td	jdd |  td
jdd |  tdjdd |  tdjdd dd }td| |  tdjdd t }td|j d|_| 	dddd d|_| 	dddd d|_|  t
djdd d|_| 	dddd d|_| 	dddd d|_|  t
djdd d|_| 	dddd G dd dt}|  ttjdd d!d i |  ttjdd |  |  ttjdd d!tjd i d S )"Nr   r   r   c                 S      dS Nr   r   rW   r   r   r   baddecodereturn1D     z=CodecCallbackTest.test_decodehelper.<locals>.baddecodereturn1ztest.baddecodereturn1   \rv   s   \x0s   \x0ys
   \Uffffeeees   \uyyyyraw-unicode-escapec                 S   r   N)rd   Nr   rW   r   r   r   baddecodereturn2N  r   z=CodecCallbackTest.test_decodehelper.<locals>.baddecodereturn2ztest.baddecodereturn2test.posreturnr   s   0z<?>0z<?><?>r   rU   r	   r      s   \uyyyy0c                   @   r   )z.CodecCallbackTest.test_decodehelper.<locals>.Dc                 S      t r   
ValueErrorr   keyr   r   r   __getitem__s  r   z:CodecCallbackTest.test_decodehelper.<locals>.D.__getitem__Nr   r   r   r  r   r   r   r   Dr  r   r  rc      )r[   r   rZ   rE   rF   r9   r   r   r   r1   
IndexErrorrf   rh   ry   r  sys
maxunicode)r   r   r   handlerr  r   r   r   test_decodehelper>  s@   "z#CodecCallbackTest.test_decodehelperc              	   C   st  |  tdjdd dd }td| |  tdjdd dd }td	| |  tdjdd	 t }td
|j d|_| 	ddd
d d|_| 	ddd
d d|_|  t
djdd
 d|_| 	ddd
d d|_| 	ddd
d d|_|  t
djdd
 d|_G dd dt}dD ]%}|  ttjd|dd i |  ttjd||  |  ttjd|ddi qd S )Nr   r   r   c                 S   r   r   r   rW   r   r   r   badencodereturn1  r   z=CodecCallbackTest.test_encodehelper.<locals>.badencodereturn1ztest.badencodereturn1c                 S   r   r   r   rW   r   r   r   badencodereturn2  r   z=CodecCallbackTest.test_encodehelper.<locals>.badencodereturn2ztest.badencodereturn2r   r   u   ÿ0s   <?>0r   s   <?><?>r   r   rU   s   <?>r   r   c                   @   r   )z.CodecCallbackTest.test_encodehelper.<locals>.Dc                 S   r   r   r   r  r   r   r   r    r   z:CodecCallbackTest.test_encodehelper.<locals>.D.__getitem__Nr  r   r   r   r   r    r   r  )rc   re   r.   rP   rS   r   r  i,  )r[   r   r2   rE   rF   r9   r   r   r   r1   r  rf   rh   rg   r  )r   r  r  r  r  r~   r   r   r   test_encodehelpery  s8   z#CodecCallbackTest.test_encodehelperc                 C   sB   G dd dt }| tdjdtjd i | tdjddi d S )Nc                   @   r   )z1CodecCallbackTest.test_translatehelper.<locals>.Dc                 S   r   r   r   r  r   r   r   r    r   z=CodecCallbackTest.test_translatehelper.<locals>.D.__getitem__Nr  r   r   r   r   r    r   r  r   r  r   r   )rf   r[   r  	translater	  r
  r9   )r   r  r   r   r   test_translatehelper  s   z&CodecCallbackTest.test_translatehelperc                 C   sD   t ddt ddt ddt ddi}d	D ]}d
| }|| qd S )N&z&amp;<z&lt;>z&gt;"z&quot;)r   r   r   r}   zabc<def>ghi)r<   r  )r   ri   r   textr   r   r   test_bug828737  s   z CodecCallbackTest.test_bug828737c              	   C   s   g d}dd }t d| |D ]\}}| t ||d W d    q1 s*w   Y  qdd }t d| |D ]\}}| ||dd q<d S )	N)r   )r   s   ++r   )r   r   )r   r   )rv      \u123g)r   r  c                 S       t | tr
d| _dS td|  )Nr   r   r   r6   r8   r"   r   r9   rW   r   r   r   	replacing     
z?CodecCallbackTest.test_mutatingdecodehandler.<locals>.replacingztest.replacingc                 S   r  )Nr!   r  r6   r  rW   r   r   r   mutating  r  z>CodecCallbackTest.test_mutatingdecodehandler.<locals>.mutatingztest.mutatingr   )rE   rF   r[   r9   rZ   r1   )r   Zbaddatar  r   datar  r   r   r   test_mutatingdecodehandler  s   
z,CodecCallbackTest.test_mutatingdecodehandlerc                 C   s   dd }t d| | dddd | dddd | d	d
dd | dddd dd }t d| | dddd | dddd d S )Nc                 S   s$   t | trd| jd fS td|  )Nr   r   r6   )r8   r"   r   r9   rW   r   r   r   forward_shorter_than_end  s   
zPCodecCallbackTest.test_crashing_decode_handler.<locals>.forward_shorter_than_endztest.forward_shorter_than_ends      z	utf-16-leu   ����Ø s      z	utf-16-bes         z	utf-32-leu   ���ᄑ s         z	utf-32-bec                 S   s&   t | trd| _d| jfS td|  )Ns           r   r6   )r8   r"   r   r   r9   rW   r   r   r   replace_with_long  s   

zICodecCallbackTest.test_crashing_decode_handler.<locals>.replace_with_longztest.replace_with_longr   r   u   �    r   u   �  )rE   rF   r1   rZ   )r   r!  r"  r   r   r   test_crashing_decode_handler  sL   

z.CodecCallbackTest.test_crashing_decode_handlerc                    s   t jt jt jt jt jt jt dt dg}tt	t
fD ]r G  fdddt}|D ]!}| j| d | t||  W d    q)1 sEw   Y  q)G  fdddt}|D ]5}| j| d$ | t|f ||  W d    n1 sxw   Y  W d    qW1 sw   Y  qWqd S )Nr   r   c                          e Zd Z ZdS zACodecCallbackTest.test_fake_error_class.<locals>.FakeUnicodeErrorNr   r   r   	__class__r   clsr   r   FakeUnicodeError+      r*  )r  Zerror_classc                       r$  r%  r&  r   r(  r   r   r*  0  r+  )rE   r   r   r   r   r   r   r   r   r"   r)   r   r   r[   r9   r   )r   handlersr*  r  r   r(  r   test_fake_error_class  s2   
z'CodecCallbackTest.test_fake_error_classN)&r   r   r   r4   rI   rM   rR   rT   r\   rj   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r   r#  r-  r   r   r   r   r-   C   sH    9 (%:.,H;6$3r-   __main__)rE   Zhtml.entitiesr;   r	  rJ   Zunittestr   r   r   r   r"   r   r%   r)   r&   r+   r,   ZTestCaser-   r   mainr   r   r   r   <module>   s0           |