B
    u9a/«  ã               @   sÔ   d dl Z 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rÐe ¡  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   ú)/usr/lib/python3.7/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   z<?>)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 )Nr   r   r   r   r   )r   r   r	   )r   r   r   r   r   !   s    z$BadObjectUnicodeEncodeError.__init__N)r   r   r   r   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Úend)r   r   r   r   r   '   s    z NoEndUnicodeDecodeError.__init__N)r   r   r   r   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 )Nr   r   r   r   r   )r   r   r   r	   )r   r   r   r   r   -   s    z$BadObjectUnicodeDecodeError.__init__N)r   r   r   r   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__N)r   r   r   r   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 )Nr   r   r   r   )r   r   r   )r   r   r   r   r   9   s    z#NoEndUnicodeTranslateError.__init__N)r   r   r   r   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 )Nr   r   r   r   )r   r   r	   )r   r   r   r   r   ?   s    z&NoObjectUnicodeTranslateError.__init__N)r   r   r   r   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%dGdH„ Z&dIS )JÚCodecCallbackTestc             C   s0   d}|   | dd¡d¡ |   | dd¡d¡ d S )Nu   ã‚¹ãƒ‘ãƒ¢ Ã¤nd eggsr   Úxmlcharrefreplaces&   &#12473;&#12497;&#12514; &#228;nd eggsz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 }x`| j| j| j… D ]J}y| dtjj	t
|ƒ  ¡ W q. tk
rv   | dt
|ƒ ¡ Y q.X q.W d |¡| jfS )Nzdon't know how to handle %rz&%s;z&#%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;zlatin-1s   «&real;» = &lang;&#4660;¤&rang;ziso-8859-15)ÚcodecsÚregister_errorr#   r$   )r   r0   Ú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   sd   t | tƒstd|  ƒ‚g }x4| j| j| j… D ]}| t |dt	|ƒ ¡¡ q.W dd 
|¡ | jfS )Nzdon't know how to handle %rz0x%xz
[1m%s[0mz, )r'   r   r(   r	   r
   r   r)   ÚunicodedataÚnamer+   r-   )r   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[0mzlatin-1sA   ¬[1mETHIOPIC SYLLABLE SEE[0m¤[1mCJK UNIFIED IDEOGRAPH-8000[0mziso-8859-15)r1   r2   r#   r$   )r   r8   r3   r4   r   r   r   Útest_uninamereplacem   s    	z%CodecCallbackTest.test_uninamereplacec             C   sP   d}d}|   | dd¡|¡ d}|   | dd¡|¡ d}|   | dd¡|¡ d S )	Nu   aÂ¬áˆ´â‚¬è€€ô¿¿s!   a\xac\u1234\u20ac\u8000\U0010ffffr   Úbackslashreplaces   a¬\u1234\u20ac\u8000\U0010ffffzlatin-1s   a¬\u1234¤\u8000\U0010ffffziso-8859-15)r#   r$   )r   r3   r4   r   r   r   Útest_backslashescape‹   s    z&CodecCallbackTest.test_backslashescapec             C   sP   d}d}|   | dd¡|¡ d}|   | dd¡|¡ d}|   | dd¡|¡ d S )	Nu   aÂ¬áˆ´â‚¬è€€ô¿¿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}\U0010ffffzlatin-1sD   a¬\N{ETHIOPIC SYLLABLE SEE}¤\N{CJK UNIFIED IDEOGRAPH-8000}\U0010ffffziso-8859-15)r#   r$   )r   r3   r4   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 )Nzdon't know how to handle %ré   s   À€ú )r'   r   r(   r	   r
   )r   r   r   r   Úrelaxedutf8­   s
    
z>CodecCallbackTest.test_decoding_callbacks.<locals>.relaxedutf8ztest.relaxedutf8s   a bÀ€cÃ¼À€À€u	   a b cÃ¼  zutf-8s   À€À)r1   r2   r#   ÚdecodeÚassertRaisesr   )r   r@   r3   r4   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 )r>   r   N)r+   ÚbytesÚupper)Ú.0r/   r   r   r   ú	<genexpr>Æ   s    z7CodecCallbackTest.test_charmapencode.<locals>.<genexpr>ZabcdefghÚabcs   AABBCCÚstrictr   ZabcAs   XYZú?ZabcDEFs   AABBCCXYZXYZXYZÚreplaceZXYZ)Údictr#   r1   Úcharmap_encoderB   ÚUnicodeErrorr+   r(   )r   Úcharmapr3   r4   r   r   r   Útest_charmapencodeÁ   s    z$CodecCallbackTest.test_charmapencodec          	   C   s¦   t j dtf¡Œ |  tdjd¡ td d¡ƒdkr˜dd„ }|  	d dd¡d¡ |  	d dd	¡d
¡ |  	d dd¡d¡ t
 d|¡ |  	d dd¡d¡ W d Q R X d S )Nz*unicode_internal codec has been deprecateds        zunicode-internalr?   é   c             S   s   t | tƒstd|  ƒ‚dS )Nzdon't know how to handle %r)úr   )r'   r   r(   )r   r   r   r   Úhandler_unicodeinternalß   s    
zMCodecCallbackTest.test_decodeunicodeinternal.<locals>.handler_unicodeinternalÚignorerK   u    ï¿½r:   z \x00ztest.huiz  )ÚtestÚsupportÚcheck_warningsÚDeprecationWarningrB   r   rA   r   r$   r#   r1   r2   )r   rS   r   r   r   Útest_decodeunicodeinternalÖ   s*    




z,CodecCallbackTest.test_decodeunicodeinternalc             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>)r+   r	   )rF   r   )r   r   r   ú
<listcomp>þ   s    zFCodecCallbackTest.test_callbacks.<locals>.handler1.<locals>.<listcomp>c                s   g | ]}d ˆ j |  ‘qS )z<%d>)r	   )rF   r   )r   r   r   rZ      s    zdon't know how to handle %rz[%s]r   )Úranger
   r   r'   r   r   r(   r-   )r   Úrr.   r   )r   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 )Nzdon't know how to handle %rc                s   g | ]}d ˆ j |  ‘qS )z<%d>)r	   )rF   r   )r   r   r   rZ   
  s    zFCodecCallbackTest.test_callbacks.<locals>.handler2.<locals>.<listcomp>z[%s]r   r   )r'   r   r(   r[   r
   r   r-   )r   r.   r   )r   r   Úhandler2  s    
z2CodecCallbackTest.test_callbacks.<locals>.handler2ztest.handler2s    €ÿr   z [<129>][<128>][<255>]z [<129>][<128>]s   \u3042\u3xxxz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>])r1   r2   r#   rA   Úcharmap_decoder+   r$   )r   r]   r^   r%   r   r   r   Útest_callbacksú   s4    






z CodecCallbackTest.test_callbacksc                s¬   ddddddg}x"|D ]}t  d| t  |¡¡ qW d‰ |d	d
„ |D ƒ7 }x\‡ fdd
„dD ƒD ]F}x@dD ]8}x2|D ]*}y| ||¡ W qr tk
rš   Y qrX qrW qhW q^W d S )NrI   rT   rK   r"   r:   r<   ztest.iè  c             S   s   g | ]}d | ‘qS )ztest.r   )rF   Úerrr   r   r   rZ   <  s    z6CodecCallbackTest.test_longstrings.<locals>.<listcomp>c                s   g | ]}|ˆ  ‘qS r   r   )rF   r%   )r.   r   r   rZ   =  s    )Úxu   ã‚u   aÃ¤)r   zlatin-1z
iso-8859-1ziso-8859-15zutf-8zutf-7zutf-16zutf-32)r1   r2   Úlookup_errorr$   rN   )r   Úerrorsrc   ZuniÚencr   )r.   r   Útest_longstrings3  s    


z"CodecCallbackTest.test_longstringsc       
      C   sæ   | j t|f|d d… žŽ  | j t|f|dg žŽ  dddddd g}x†tt|ƒƒD ]v}xp|D ]h}t|ƒt|| ƒkrtqZg }x6tt|ƒƒD ]&}||krž| |¡ q†| || ¡ q†W | j t|f|žŽ  qZW qPW ||Ž }	|  t|	ƒ|¡ d S )Néÿÿÿÿztoo muchZspams   eggss   spamé*   g      ð?)rB   r(   r[   r   Útyper)   r#   Ústr)
r   ÚexctypeÚargsÚmsgZ	wrongargsÚiZwrongargZcallargsÚjr   r   r   r   Úcheck_exceptionobjectargsF  s    
z+CodecCallbackTest.check_exceptionobjectargsc             C   s”   |   tdddddgd¡ |   tdddddgd¡ |   tdd	d
ddgd¡ |   tddd
ddgd¡ |   tddd
ddgd¡ |   tddd
ddgd¡ d S )Nr   u   gÃ¼rkr   r>   Úouchz?'ascii' codec can't encode character '\xfc' in position 1: ouchrQ   z;'ascii' codec can't encode characters in position 1-3: ouchu   Ã¼xr   z?'ascii' codec can't encode character '\xfc' in position 0: ouchu   Ä€xzA'ascii' codec can't encode character '\u0100' in position 0: ouchu   ï¿¿xzA'ascii' codec can't encode character '\uffff' in position 0: ouchu   ð€€xzE'ascii' codec can't encode character '\U00010000' in position 0: ouch)rr   r   )r   r   r   r   Útest_unicodeencodeerror_  s0    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   gürkr   r>   rs   z8'ascii' codec can't decode byte 0xfc in position 1: ouché   z6'ascii' codec can't decode bytes in position 1-2: ouch)rr   r   r   )r   r   r   r   Útest_unicodedecodeerror  s    z)CodecCallbackTest.test_unicodedecodeerrorc             C   sr   |   tddddgd¡ |   tddddgd¡ |   tddddgd	¡ |   td
dddgd¡ |   tddddgd¡ d S )Nu   gÃ¼rkr   r>   rs   z4can't translate character '\xfc' in position 1: ouchu   gÄ€rkz6can't translate character '\u0100' in position 1: ouchu   gï¿¿rkz6can't translate character '\uffff' in position 1: ouchu   gð€€rkz:can't translate character '\U00010000' in position 1: ouchru   z0can't translate characters in position 1-2: ouch)rr   r   )r   r   r   r   Útest_unicodetranslateerror‹  s(    




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 )Nrj   rs   r   u   ã‚r   r   ó   ÿ)	rB   r(   r1   Ústrict_errorsÚ	Exceptionr   r   r   r   )r   r   r   r   Útest_badandgoodstrictexceptions¦  s(    
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 )	Nrj   rs   r   u   aã‚br   r>   )r   r>   s   aÿb)
rB   r(   r1   Úignore_errorsrN   r#   r   r   r   r   )r   r   r   r   Útest_badandgoodignoreexceptionsÅ  s(    
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 )
Nrj   rs   r   u   aã‚br   r>   )rJ   r>   s   aÿb)u   ï¿½r>   )rB   r(   r1   Úreplace_errorsrN   r   r   r#   r   r   r   r   )r   r   r   r   Ú test_badandgoodreplaceexceptionsã  s8    
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 )Nrj   rs   r   rx   r   r   u   ã‚)r   r   é	   é
   éc   éd   iç  iè  i'  i'  iŸ† i † i?B i@B )i Ø  iÿß  r   c             s   s   | ]}t |ƒV  qd S )N)Úchr)rF   r/   r   r   r   rG   '  s    zOCodecCallbackTest.test_badandgoodxmlcharrefreplaceexceptions.<locals>.<genexpr>r_   Úbc             s   s   | ]}d | V  qdS )z&#%d;Nr   )rF   r/   r   r   r   rG   -  s    )rB   r(   r1   Úxmlcharrefreplace_errorsrN   r   r   r   r-   r#   r   r   )r   Úcsr%   r   r   r   Ú*test_badandgoodxmlcharrefreplaceexceptions  s0    
z<CodecCallbackTest.test_badandgoodxmlcharrefreplaceexceptionsc             C   sD  |   ttjd¡ |   ttjtdƒ¡ ddddddd	d
ddddg}xš|D ]’\}}| j|dx |  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 R X qFW ddddg}xV|D ]N\}}| j|d4 |  t t
dtd| d ƒdddƒ¡|df¡ W d Q R X qîW d S )Nrj   rs   )u   ã‚z\u3042)Ú
z\x0a)r_   z\x61)r?   z\x00)õ   Ã¿z\xff)u   Ä€z\u0100)u   ï¿¿z\uffff)u   ð€€z
\U00010000)u   ô¿¿z
\U0010ffff)u   í €z\ud800)u   í¿¿z\udfff)u   í €í¿¿z\ud800\udfff)rl   r   r_   r…   r   )ó   az\x61)ó   
z\x0a)ó    z\x00)rx   z\xff)rD   r‹   ó   br>   )rB   r(   r1   Úbackslashreplace_errorsrN   ÚsubTestr#   r   r   r   r   r   )r   Útestsr%   r\   r…   r   r   r   Ú)test_badandgoodbackslashreplaceexceptions0  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ƒ¡ dd	d
dddddg}xb|D ]Z\}}| j|d@ |  	t t
dd| d ddt|ƒ dƒ¡|dt|ƒ f¡ W d Q R X qxW d S )Nrj   rs   r   rx   r   r   u   ã‚)u   ã‚z\N{HIRAGANA LETTER A})r?   z\x00)u   ï¯¹zW\N{ARABIC LIGATURE UIGHUR KIRGHIZ YEH WITH HAMZA ABOVE WITH ALEF MAKSURA ISOLATED FORM})u   ó ¿z\N{CANCEL TAG})u   ô¿¿z
\U0010ffff)u   í €z\ud800)u   í¿¿z\udfff)u   í €í¿¿z\ud800\udfff)rl   r_   r…   )rB   r(   r1   Únamereplace_errorsrN   r   r   r   r   r#   r   r   )r   r‘   r%   r\   r   r   r   Ú$test_badandgoodnamereplaceexceptionsj  s>    
z6CodecCallbackTest.test_badandgoodnamereplaceexceptionsc             C   sà   t  d¡}|  t|d¡ |  t|tdƒ¡ |  t|tddddƒ¡ x>dD ]6}| j|d  |  t|td	|dddƒ¡ W d Q R X qHW |  |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Úsurrogateescaperj   rs   u   í²€r   r   )r_   u   í±¿u   í´€)rl   r   u   aí²€br>   )ó   €r>   r‹   s   a€b)u   í²€r>   )r1   re   rB   r(   rN   r   r   r   r#   r   r   )r   Zsurrogateescape_errorsr%   r   r   r   Ú(test_badandgoodsurrogateescapeexceptions˜  s>    


 z:CodecCallbackTest.test_badandgoodsurrogateescapeexceptionsc             C   s¼  t  d¡}|  t|d¡ |  t|tdƒ¡ |  t|tddddƒ¡ x^dD ]V}| j|d@ |  t|t|d	dddƒ¡ |  t|t|d	 	|¡dddƒ¡ W d Q R X qHW xBd
D ]:}| j|d$ |  t|td|dt
|ƒdƒ¡ W d Q R X q¨W dddddddddddddddg}x®|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 Q R X qW d S ) NÚsurrogatepassrj   rs   u   í €r   r   )zutf-8zutf-16lezutf-16bezutf-32lezutf-32be)Úencodingr_   )u   í €u   í¿¿u   í €í¿¿)rl   r   )zutf-8u   í €s   í €ru   )zutf-16leu   í €s    Ør>   )zutf-16beu   í €s   Ø r>   )zutf-32leu   í €s    Ø  rQ   )zutf-32beu   í €s     Ø rQ   )zutf-8u   í¿¿s   í¿¿ru   )zutf-16leu   í¿¿s   ÿßr>   )zutf-16beu   í¿¿s   ßÿr>   )zutf-32leu   í¿¿s   ÿß  rQ   )zutf-32beu   í¿¿s     ßÿrQ   )zutf-8u   í €í¿¿s   í €í¿¿ru   )zutf-16leu   í €í¿¿s    Øÿßr>   )zutf-16beu   í €í¿¿s   Ø ßÿr>   )zutf-32leu   í €í¿¿s    Ø  ÿß  rQ   )zutf-32beu   í €í¿¿s     Ø   ßÿrQ   )r™   rl   rD   r…   r‹   rŽ   )r1   re   rB   r(   rN   r   r   r   r   r$   r   r#   r   )r   Zsurrogatepass_errorsrg   r%   r‘   r…   Únr   r   r   Ú&test_badandgoodsurrogatepassexceptionsÄ  sp    


&
$z8CodecCallbackTest.test_badandgoodsurrogatepassexceptionsc                sˆ   d}d}xz|D ]r‰ t  d‡ fdd„¡ x|D ]}|  tdj|d¡ q,W x8dD ]0\}}tj ¡  |  t|j|d¡ W d Q R X qLW qW d S )N)	rj   Úfoo)r   r>   ru   )rœ   r   ru   )rœ   N)rœ   )rœ   r   ru   )rœ   N)rœ   )r   zlatin-1z
iso-8859-1ziso-8859-15ztest.badhandlerc                s   ˆ S )Nr   )rd   )Úresr   r   Ú<lambda>  r   z:CodecCallbackTest.test_badhandlerresults.<locals>.<lambda>u   ã‚))r   rx   )zutf-8rx   )zutf-7s   +x-)zunicode-internalr   )	r1   r2   rB   r(   r$   rU   rV   rW   rA   )r   ÚresultsZencsrg   rD   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 )NrI   rT   r"   r:   r<   )r#   r1   ry   re   r|   r†   r   r“   )r   r   r   r   Útest_lookup(  s    zCodecCallbackTest.test_lookupc             C   s8   dd„ }t  d|¡ xdD ]}|  tdj|d¡ qW d S )Nc             S   s$   t | tƒrd| jfS td|  ƒ‚d S )Nu   ä‰‚zdon't know how to handle %r)r'   r   r   r(   )r   r   r   r   Ú	unencrepl:  s    

z@CodecCallbackTest.test_unencodablereplacement.<locals>.unencreplztest.unencreplhandler)r   z
iso-8859-1ziso-8859-15u   ä‰‚)r1   r2   rB   r   r$   )r   r¢   rg   r   r   r   Útest_unencodablereplacement9  s    
z-CodecCallbackTest.test_unencodablereplacementc             C   s&   |   ttjd¡ |   ttjdd¡ d S )Nrj   z
test.dummy)rB   r(   r1   r2   )r   r   r   r   Útest_badregistercallH  s    z&CodecCallbackTest.test_badregistercallc             C   s   |   ttj¡ d S )N)rB   r(   r1   re   )r   r   r   r   Útest_badlookupcallO  s    z$CodecCallbackTest.test_badlookupcallc             C   s   |   ttjd¡ d S )Nztest.unknown)rB   ÚLookupErrorr1   re   )r   r   r   r   Útest_unknownhandlerT  s    z%CodecCallbackTest.test_unknownhandlerc             C   sR   d}d  dd„ |D ƒ¡}t dtj¡ x&dD ]}xdD ]}| ||¡ q6W q,W d S )N)r   é   r   é2   rƒ   iô  iè  iˆ  i'  iPÃ  i † i ¡ i@B r   c             S   s   g | ]}t |ƒ‘qS r   )r„   )rF   rd   r   r   r   rZ   _  s    z;CodecCallbackTest.test_xmlcharrefvalues.<locals>.<listcomp>ztest.xmlcharrefreplace)r   ziso-8859-15)r"   ztest.xmlcharrefreplace)r-   r1   r2   r†   r$   )r   Úvr%   rg   rc   r   r   r   Útest_xmlcharrefvaluesY  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 )"Nrx   r   ztest.unknownc             S   s   dS )Nrj   r   )r   r   r   r   Úbaddecodereturn1k  s    z=CodecCallbackTest.test_decodehelper.<locals>.baddecodereturn1ztest.baddecodereturn1ó   \zunicode-escapes   \x0s   \x0ys
   \Uffffeeees   \uyyyyzraw-unicode-escapec             S   s   dS )N)rJ   Nr   )r   r   r   r   Úbaddecodereturn2u  s    z=CodecCallbackTest.test_decodehelper.<locals>.baddecodereturn2ztest.baddecodereturn2ztest.posreturnri   s   ÿ0z<?>0éþÿÿÿz<?><?>éýÿÿÿr   r>   z<?>ru   é   s   \uyyyy0c               @   s   e Zd Zdd„ ZdS )z.CodecCallbackTest.test_decodehelper.<locals>.Dc             S   s   t ‚d S )N)Ú
ValueError)r   Úkeyr   r   r   Ú__getitem__š  s    z:CodecCallbackTest.test_decodehelper.<locals>.D.__getitem__N)r   r   r   r´   r   r   r   r   ÚD™  s   rµ   rI   éÿ   )rB   r¦   rA   r1   r2   r(   r   r   r   r#   Ú
IndexErrorrL   rN   ra   r²   ÚsysÚ
maxunicode)r   r¬   r®   Úhandlerrµ   r   r   r   Útest_decodehelpere  s@    z#CodecCallbackTest.test_decodehelperc          	   C   sz  |   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ƒ}xTdD ]L}|   ttjd|dd i¡ |   ttjd||ƒ ¡ |   ttjd|ddi¡ q&W d S )NrŠ   r   ztest.unknownc             S   s   dS )Nrj   r   )r   r   r   r   Úbadencodereturn1¦  s    z=CodecCallbackTest.test_encodehelper.<locals>.badencodereturn1ztest.badencodereturn1c             S   s   dS )N)rJ   Nr   )r   r   r   r   Úbadencodereturn2«  s    z=CodecCallbackTest.test_encodehelper.<locals>.badencodereturn2ztest.badencodereturn2ztest.posreturnri   u   Ã¿0s   <?>0r¯   s   <?><?>r°   r   r>   s   <?>ru   r   c               @   s   e Zd Zdd„ ZdS )z.CodecCallbackTest.test_encodehelper.<locals>.Dc             S   s   t ‚d S )N)r²   )r   r³   r   r   r   r´   Î  s    z:CodecCallbackTest.test_encodehelper.<locals>.D.__getitem__N)r   r   r   r´   r   r   r   r   rµ   Í  s   rµ   )rI   rK   r"   r:   r<   ztest.posreturnr¶   i,  )rB   r¦   r$   r1   r2   r(   r   r   r   r#   r·   rL   rN   rM   r²   )r   r¼   r½   rº   rµ   rc   r   r   r   Útest_encodehelper   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 )N)r²   )r   r³   r   r   r   r´   Ý  s    z=CodecCallbackTest.test_translatehelper.<locals>.D.__getitem__N)r   r   r   r´   r   r   r   r   rµ   Ü  s   rµ   rŠ   r¶   r   r   )rL   rB   r²   Ú	translater¸   r¹   r(   )r   rµ   r   r   r   Útest_translatehelperÖ  s    z&CodecCallbackTest.test_translatehelperc             C   sH   t dƒdt dƒdt dƒdt dƒdi}xd	D ]}d
| }| |¡ q*W d S )Nú&z&amp;ú<z&lt;ú>z&gt;ú"z&quot;)r   r   rƒ   iè  zabc<def>ghi)r+   r¿   )r   rO   rš   Útextr   r   r   Útest_bug828737ã  s    
z CodecCallbackTest.test_bug828737c             C   sÆ   ddddddddg}d	d
„ }t  d|¡ tj ¡ : x2|D ]*\}}|  t¡ | |d¡ W d Q R X q:W W d Q R X dd„ }t  d|¡ tj ¡ , x$|D ]\}}|  | |d¡d¡ q˜W W d Q R X d S )N)r   rx   )zutf-7s   ++)zutf-8rx   )zutf-16rx   )zutf-32rx   )zunicode-escapes   \u123g)zraw-unicode-escapes   \u123g)zunicode-internalrx   c             S   s$   t | tƒrd| _dS td|  ƒ‚d S )Nrj   )u   ä‰‚r   zdon't know how to handle %r)r'   r   r	   r(   )r   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   )u   ä‰‚r   zdon't know how to handle %r)r'   r   r	   r(   )r   r   r   r   Úmutating	  s    
z>CodecCallbackTest.test_mutatingdecodehandler.<locals>.mutatingztest.mutatingu   ä‰‚)	r1   r2   rU   rV   rW   rB   r(   rA   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 )Nu   ï¿½r   zdon't know how to handle %r)r'   r   r
   r(   )r   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           u   ï¿½zdon't know how to handle %r)r'   r   r	   r
   r(   )r   r   r   r   Úreplace_with_long9  s    

zICodecCallbackTest.test_crashing_decode_handler.<locals>.replace_with_longztest.replace_with_longr   zutf-16u   ï¿½    zutf-32u   ï¿½  )r1   r2   r#   rA   )r   rË   rÌ   r   r   r   Útest_crashing_decode_handler  s6    

z.CodecCallbackTest.test_crashing_decode_handlerc                sð   t jt jt jt jt jt jt  d¡t  d¡g}x¾tt	t
fD ]°‰ G ‡ fdd„dtƒ}x6|D ].}| j|ˆ d |  t||ƒ ¡ W d Q R X qVW G ‡ fdd„dtƒ}xJ|D ]B}| j|ˆ d* |  t|f¡ ||ƒ ƒ W d Q R X W d Q R X q¢W q8W d 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   ÚFakeUnicodeErrorW  s   rÐ   )rº   Zerror_classc                   s   e Zd Z” ZdS )zACodecCallbackTest.test_fake_error_class.<locals>.FakeUnicodeErrorN)r   r   r   rÎ   r   )rÏ   r   r   rÐ   \  s   )r1   ry   r|   r~   r   r“   r†   re   r   r   r   rl   r   rB   r(   rz   )r   ZhandlersrÐ   rº   r   )rÏ   r   Útest_fake_error_classK  s$    

z'CodecCallbackTest.test_fake_error_classN)'r   r   r   r&   r5   r9   r;   r=   rC   rP   rY   rb   rh   rr   rt   rv   rw   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__)r1   Zhtml.entitiesr*   r¸   Ztest.supportrU   r6   Zunittestr   r   r   r   r   r   r   r   r   r   r    ZTestCaser!   r   Úmainr   r   r   r   Ú<module>   s0           )