a
    3jޣ                     @   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re  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   T/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_codeccallbacks.py__init__   s    zPosReturn.__init__c                 C   s>   | j }|}|dk r t|j| }||jkr6t|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                   @   s   e Zd Zdd ZdS )BadStartUnicodeEncodeErrorc                 C   s   t | ddddd g | _d S Nascii r      bad)UnicodeEncodeErrorr   r   r   r   r   r   r      s    z#BadStartUnicodeEncodeError.__init__Nr   r   r   r   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )BadObjectUnicodeEncodeErrorc                 C   s   t | ddddd g | _d S r   )r   r   r   r   r   r   r   r   !   s    z$BadObjectUnicodeEncodeError.__init__Nr   r   r   r   r   r       s   r   c                   @   s   e Zd Zdd ZdS )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   &   s   r   c                   @   s   e Zd Zdd ZdS )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!   ,   s   r!   c                   @   s   e Zd Zdd ZdS )NoStartUnicodeTranslateErrorc                 C   s   t | dddd | `d S Nr   r   r   r   )UnicodeTranslateErrorr   r   r   r   r   r   r   3   s    z%NoStartUnicodeTranslateError.__init__Nr   r   r   r   r   r"   2   s   r"   c                   @   s   e Zd Zdd ZdS )NoEndUnicodeTranslateErrorc                 C   s   t | dddd | `d S r#   )r$   r   r    r   r   r   r   r   9   s    z#NoEndUnicodeTranslateError.__init__Nr   r   r   r   r   r%   8   s   r%   c                   @   s   e Zd Zdd ZdS )NoObjectUnicodeTranslateErrorc                 C   s   t | dddd | `d S r#   )r$   r   r   r   r   r   r   r   ?   s    z&NoObjectUnicodeTranslateError.__init__Nr   r   r   r   r   r&   >   s   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   sd   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 ]H}z|dtjj	t
|   W q, tyr   |dt
|  Y q,0 q,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_errorr+   r,   )r   r;   sinsoutr   r   r   test_xmlcharnamereplaceS   s    z)CodecCallbackTest.test_xmlcharnamereplacec                 C   sd   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 ]}|t|dt	|  q,dd
| | jfS )Nr/   z0x%xz
[1m%s[0mz, )r1   r   r2   r   r   r    r3   unicodedatanamer5   r7   r8   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[0mr<   r=   )r   rE   r@   rA   r   r   r   test_uninamereplacem   s    	z%CodecCallbackTest.test_uninamereplacec                 C   sP   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\U0010ffffr<   r*   r   r@   rA   r   r   r   test_backslashescape   s    z&CodecCallbackTest.test_backslashescapec                 C   sP   d}d}|  |dd| d}|  |dd| d}|  |dd| d S )	NrG   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}\U0010ffffr<   r*   rI   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   sF   t | tstd|  | j| j| jd  dkr>d| jd fS | d S )Nr/      s    )r1   r   r2   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   )r>   r?   r+   decodeassertRaisesr   )r   rP   r@   rA   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 )rM   r   N)r5   bytesupper.0r:   r   r   r   	<genexpr>   r   z7CodecCallbackTest.test_charmapencode.<locals>.<genexpr>Zabcdefghabcs   AABBCCstrictr   ZabcAs   XYZ?ZabcDEFs   AABBCCXYZXYZXYZreplaceZXYZ)dictr+   r>   charmap_encoderS   UnicodeErrorr5   r2   )r   charmapr@   rA   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rJ fdd|D }ntd  dd|  jfS )Nc                    s   g | ]}d t  j|  qS z<%d>)r5   r   rX   r   rO   r   r   
<listcomp>   r   zFCodecCallbackTest.test_callbacks.<locals>.handler1.<locals>.<listcomp>c                    s   g | ]}d  j |  qS rc   r   rd   rO   r   r   re      r   r/   [%s]r   )ranger   r    r1   r   r   r2   r7   )r   rr9   r   rO   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 )Nr/   c                    s   g | ]}d  j |  qS rc   rf   rd   rO   r   r   re      r   zFCodecCallbackTest.test_callbacks.<locals>.handler2.<locals>.<listcomp>rg   r   r   )r1   r   r2   rh   r   r    r7   )r   r9   r   rO   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>])r>   r?   r+   rR   charmap_decoder5   r,   )r   rj   rk   r-   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 ]2}|D ](}z||| W q` ty   Y q`0 q`qXqPd S )	N)r[   ignorer]   r(   rH   rK   test.  c                 S   s   g | ]}d | qS )rr   r   )rX   errr   r   r   re     r   z6CodecCallbackTest.test_longstrings.<locals>.<listcomp>c                    s   g | ]}|  qS r   r   )rX   r-   r9   r   r   re     r   )x   あu   aä)r   r)   
iso-8859-1r<   rQ   utf-7utf-16utf-32)r>   r?   lookup_errorr,   r`   )r   errorsrt   Zuniencr   ru   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 ]p}|D ]f}t|t|| u rlqRg }tt|D ]&}||kr|| q||||  q|| j t|g|R   qRqJ|| }	| t|	| d S )Nztoo much)Zspams   eggss   spam*   g      ?N)rS   r2   rh   r
   typer3   r+   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   rM   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   rM   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   rM   r   z4can't translate character '\xfc' in position 1: ouch)u   gĀrkr   rM   r   z6can't translate character '\u0100' in position 1: ouch)u   g￿rkr   rM   r   z6can't translate character '\uffff' in position 1: ouch)u   g𐀀rkr   rM   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   rw   r   r      )	rS   r2   r>   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   rM   )r   rM      ab)
rS   r2   r>   ignore_errorsr`   r+   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   rM   )r\   rM   r   )   �rM   )rS   r2   r>   replace_errorsr`   r   r!   r+   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   rw   )r   r   	   
   c   d   i  rs   i'  '  i 順 i?B @B )i   i  r   c                 s   s   | ]}t |V  qd S NchrrW   r   r   r   rY     r   zOCodecCallbackTest.test_badandgoodxmlcharrefreplaceexceptions.<locals>.<genexpr>rm   bc                 s   s   | ]}d | V  qdS )r0   Nr   rW   r   r   r   rY   	  r   )rS   r2   r>   xmlcharrefreplace_errorsr`   r   r   r$   r7   r+   r   r
   )r   csr-   r   r   r   *test_badandgoodxmlcharrefreplaceexceptions  s>    z<CodecCallbackTest.test_badandgoodxmlcharrefreplaceexceptionsc                 C   sN  |  ttjd |  ttjtd g d}|D ]\}}| j|d | 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    q01 s0    Y  q0g d	}|D ]d\}}| j|d
> | tt
dtd| d ddd|df W d    q1 s>0    Y  qd S )Nr   r   ))rw   z\u3042)
\x0a)rm   \x61rN   \x00)   ÿ\xff)u   Āz\u0100)u   ￿z\uffff)u   𐀀z
\U00010000u   􏿿z
\U0010ffff   z\ud800   z\udfff   z\ud800\udfffr   r   rm   r   r   ))   ar   )   
r   )    r   )r   r   )rU   r      brM   )rS   r2   r>   backslashreplace_errorsr`   subTestr+   r   r
   r$   r   r   )r   testsr-   ri   r   r   r   r   )test_badandgoodbackslashreplaceexceptions  sP    $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 ]n\}}| j|d	J | 	tt
dd
| d ddt| d|dt| f W d    qj1 s0    Y  qjd S )Nr   r   r   r   r   r   rw   ))rw   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   rm   r   )rS   r2   r>   namereplace_errorsr`   r   r   r$   r   r+   r   r
   )r   r   r-   ri   r   r   r   $test_badandgoodnamereplaceexceptionsF  s>    z6CodecCallbackTest.test_badandgoodnamereplaceexceptionsc                 C   s   t d}| t|d | t|td | t|tdddd dD ]J}| j|d* | t|td	|ddd W d    qF1 s0    Y  qF| |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   )rm   u   u   r   r   u   abrM   )   rM   r   s   ab)r   rM   )r>   r|   rS   r2   r`   r$   r   r   r+   r   r   )r   Zsurrogateescape_errorsr-   r   r   r   (test_badandgoodsurrogateescapeexceptionst  sP    
$z:CodecCallbackTest.test_badandgoodsurrogateescapeexceptionsc                 C   s  t d}| t|d | t|td | t|tdddd dD ]j}| j|dJ | t|t|d	ddd | t|t|d		|ddd W d    qF1 s0    Y  qFd
D ]N}| j|d. | t|td|dt
|d W d    q1 s0    Y  qg d}|D ]\}}}}| j|||d | |t|d	| d ddt
| d|dt
| f | |t|td|d |  d dd| d|d d d| f W d    n1 s0    Y  qd S )Nsurrogatepassr   r   r   r   r   )rQ   utf-16leutf-16beutf-32leutf-32be)encodingrm   )r   r   r   r   r   ))rQ   r   s   r   )r   r   s    rM   )r   r   s    rM   )r   r   s      r   )r   r   s      r   )rQ   r   s   r   )r   r   s   rM   )r   r   s   rM   )r   r   s     r   )r   r   s     r   )rQ   r   s   r   )r   r   s    rM   )r   r   s    rM   )r   r   s        r   )r   r   s        r   )r   r   rU   r   r   r   )r>   r|   rS   r2   r`   r$   r   r   r   r,   r
   r+   r   )r   Zsurrogatepass_errorsr~   r-   r   r   nr   r   r   &test_badandgoodsurrogatepassexceptions  sl    
$$
z8CodecCallbackTest.test_badandgoodsurrogatepassexceptionsc                    sf   d}d}|D ]T t d fdd |D ]}| tdj|d q(dD ]\}}| t|j|d qDqd S )N)	r   foo)r   rM   r   r   r   r   r   Nr   r   r   r   )r   r)   rx   r<   ztest.badhandlerc                    s    S r   r   )rv   resr   r   <lambda>  r   z:CodecCallbackTest.test_badhandlerresults.<locals>.<lambda>rw   )r   r   rQ   r   )ry   s   +x-)r>   r?   rS   r2   r,   rR   )r   resultsZencsr~   rU   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 )Nr[   rq   r(   rH   rK   )r+   r>   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|  d S )N   䉂r/   )r1   r   r    r2   rO   r   r   r   	unencrepl  s    

z@CodecCallbackTest.test_unencodablereplacement.<locals>.unencreplztest.unencreplhandler)r   rx   r<   r   )r>   r?   rS   r   r,   )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)rS   r2   r>   r?   r   r   r   r   test_badregistercall!  s    z&CodecCallbackTest.test_badregistercallc                 C   s   |  ttj d S r   )rS   r2   r>   r|   r   r   r   r   test_badlookupcall(  s    z$CodecCallbackTest.test_badlookupcallc                 C   s   |  ttjd d S )Ntest.unknown)rS   LookupErrorr>   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 ]}||| q2q*d S )N)r      r   2   r   i  rs   i  r   iP  r   i  r   r   c                 S   s   g | ]}t |qS r   r   )rX   rv   r   r   r   re   8  r   z;CodecCallbackTest.test_xmlcharrefvalues.<locals>.<listcomp>test.xmlcharrefreplace)r   r<   )r(   r   )r7   r>   r?   r   r,   )r   vr-   r~   rt   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   s   dS Nr   r   rO   r   r   r   baddecodereturn1D  s    z=CodecCallbackTest.test_decodehelper.<locals>.baddecodereturn1ztest.baddecodereturn1   \rl   s   \x0s   \x0ys
   \Uffffeeees   \uyyyyraw-unicode-escapec                 S   s   dS N)r\   Nr   rO   r   r   r   baddecodereturn2N  s    z=CodecCallbackTest.test_decodehelper.<locals>.baddecodereturn2ztest.baddecodereturn2test.posreturnr   s   0z<?>0z<?><?>r   rM   r	   r      s   \uyyyy0c                   @   s   e Zd Zdd ZdS )z.CodecCallbackTest.test_decodehelper.<locals>.Dc                 S   s   t d S r   
ValueErrorr   keyr   r   r   __getitem__s  s    z:CodecCallbackTest.test_decodehelper.<locals>.D.__getitem__Nr   r   r   r   r   r   r   r   Dr  s   r   r[      )rS   r   rR   r>   r?   r2   r   r   r   r+   
IndexErrorr^   r`   ro   r   sys
maxunicode)r   r   r   handlerr   r   r   r   test_decodehelper>  s@    z#CodecCallbackTest.test_decodehelperc              	   C   sv  |  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 ]L}|  ttjd|dd i |  ttjd||  |  ttjd|ddi q$d S )Nr   r   r   c                 S   s   dS r   r   rO   r   r   r   badencodereturn1  s    z=CodecCallbackTest.test_encodehelper.<locals>.badencodereturn1ztest.badencodereturn1c                 S   s   dS r   r   rO   r   r   r   badencodereturn2  s    z=CodecCallbackTest.test_encodehelper.<locals>.badencodereturn2ztest.badencodereturn2r   r   u   ÿ0s   <?>0r   s   <?><?>r   r   rM   s   <?>r   r   c                   @   s   e Zd Zdd ZdS )z.CodecCallbackTest.test_encodehelper.<locals>.Dc                 S   s   t d S r   r   r   r   r   r   r     s    z:CodecCallbackTest.test_encodehelper.<locals>.D.__getitem__Nr   r   r   r   r   r     s   r   )r[   r]   r(   rH   rK   r   r   i,  )rS   r   r,   r>   r?   r2   r   r   r   r+   r   r^   r`   r_   r   )r   r   r   r   r   rt   r   r   r   test_encodehelpery  s6    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                   @   s   e Zd Zdd ZdS )z1CodecCallbackTest.test_translatehelper.<locals>.Dc                 S   s   t d S r   r   r   r   r   r   r     s    z=CodecCallbackTest.test_translatehelper.<locals>.D.__getitem__Nr   r   r   r   r   r     s   r   r   r   r   r   )r^   rS   r   	translater   r   r2   )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   rs   zabc<def>ghi)r5   r  )r   ra   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 sT0    Y  q dd }t d| |D ]\}}| ||dd qxd S )	N)r   )ry   s   ++r   )rz   r   )r{   r   )rl      \u123g)r   r
  c                 S   s$   t | trd| _dS td|  d S )Nr   r   r   r/   r1   r   r   r2   rO   r   r   r   	replacing  s    
z?CodecCallbackTest.test_mutatingdecodehandler.<locals>.replacingztest.replacingc                 S   s$   t | trd| _dS td|  d S )Nr   r  r/   r  rO   r   r   r   mutating  s    
z>CodecCallbackTest.test_mutatingdecodehandler.<locals>.mutatingztest.mutatingr   )r>   r?   rS   r2   rR   r+   )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|  d S )Nr   r   r/   )r1   r   r   r2   rO   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|  d S )Ns           r   r/   )r1   r   r   r   r2   rO   r   r   r   replace_with_long  s    

zICodecCallbackTest.test_crashing_decode_handler.<locals>.replace_with_longztest.replace_with_longr   rz   u   �    r{   u   �  )r>   r?   r+   rR   )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 ] G  fdddt}|D ]B}| j| d  | t||  W d    qR1 s0    Y  qRG  fdddt}|D ]l}| j| dH | t|f ||  W d    n1 s0    Y  W d    q1 s0    Y  qq6d S )Nr   r   c                       s   e Zd Z ZdS zACodecCallbackTest.test_fake_error_class.<locals>.FakeUnicodeErrorNr   r   r   	__class__r   clsr   r   FakeUnicodeError+  s   r  )r   Zerror_classc                       s   e Zd Z ZdS r  r  r   r  r   r   r  0  s   )r>   r   r   r   r   r   r   r|   r   r   r$   r   r   rS   r2   r   )r   handlersr  r   r   r  r   test_fake_error_class  s&    
0z'CodecCallbackTest.test_fake_error_classN)&r   r   r   r.   rB   rF   rJ   rL   rT   rb   rp   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   sF   9 (%:.,H;6$3r'   __main__)r>   Zhtml.entitiesr4   r   rC   Zunittestr   r   r   r   r   r   r!   r$   r"   r%   r&   ZTestCaser'   r   mainr   r   r   r   <module>   s,          |