B
    u9aJJ  ã               @   sÂ  d dl mZmZmZmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ yd dlZdZW n ek
rì   dZY nX G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deeeƒZG dd„ deƒZ G dd„ dee ƒZ!G dd„ dee ƒZ"G dd„ deƒZ#G dd„ deƒZ$G d d!„ d!eƒZ%erTG 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 d0d1„ d1eƒZ-G d2d3„ d3eƒZ.G d4d5„ d5eƒZ/ej0G d6d7„ d7ej1ƒƒZ2d8d9d:d;hZ3d<d=d>d?hZ4d@dA„ Z5dBdC„ Z6dDdE„ Z7dFdG„ Z8dHdI„ Z9G dJdK„ dKej1ƒZ:dLdM„ Z;e<dNkr¾e;ƒ  dS )Oé    )ÚIMPORT_MAPPINGÚREVERSE_IMPORT_MAPPINGÚNAME_MAPPINGÚREVERSE_NAME_MAPPINGN)Úsupport)ÚAbstractUnpickleTests)ÚAbstractPickleTests)ÚAbstractPickleModuleTests)ÚAbstractPersistentPicklerTests)Ú&AbstractIdentityPersistentPicklerTests)Ú#AbstractPicklerUnpicklerObjectTests)ÚAbstractDispatchTableTests)ÚBigmemPickleTestsTFc               @   s@   e Zd ZeejƒZeejƒZeej	ƒZ
eejƒZejZejZdS )ÚPyPickleTestsN)Ú__name__Ú
__module__Ú__qualname__ÚstaticmethodÚpickleZ_dumpÚdumpZ_dumpsÚdumpsÚ_loadÚloadZ_loadsÚloadsÚ_PicklerÚPicklerÚ
_UnpicklerÚ	Unpickler© r   r   ú!/usr/lib/python3.7/test_pickle.pyr      s   



r   c               @   s6   e Zd ZejZefZeje	e
eejeefZdd„ ZdS )ÚPyUnpicklerTestsc             K   s    t  |¡}| j|f|Ž}| ¡ S )N)ÚioÚBytesIOÚ	unpicklerr   )ÚselfÚbufÚkwdsÚfÚur   r   r   r   /   s    
zPyUnpicklerTests.loadsN)r   r   r   r   r   r#   Ú
IndexErrorÚbad_stack_errorsÚUnpicklingErrorÚEOFErrorÚAttributeErrorÚ
ValueErrorÚstructÚerrorÚImportErrorÚtruncated_errorsr   r   r   r   r   r    '   s   r    c               @   s*   e Zd ZejZejZddd„Zdd„ Z	dS )ÚPyPicklerTestsNc             C   s4   t  ¡ }|  ||¡}| |¡ | d¡ t| ¡ ƒS )Nr   )r!   r"   Úpicklerr   ÚseekÚbytesÚread)r$   ÚargÚprotor'   Úpr   r   r   r   :   s
    

zPyPicklerTests.dumpsc             K   s    t  |¡}| j|f|Ž}| ¡ S )N)r!   r"   r#   r   )r$   r%   r&   r'   r(   r   r   r   r   A   s    
zPyPicklerTests.loads)N)
r   r   r   r   r   r4   r   r#   r   r   r   r   r   r   r3   5   s   
r3   c               @   sB   e Zd ZejefZejeee	e
jeefZddd„Zdd„ ZdZdS )ÚInMemoryPickleTestsNc             C   s   t  ||¡S )N)r   r   )r$   r8   Zprotocolr   r   r   r   O   s    zInMemoryPickleTests.dumpsc             K   s   t j|f|ŽS )N)r   r   )r$   r%   r&   r   r   r   r   R   s    zInMemoryPickleTests.loads)N)r   r   r   r   r+   r)   r*   r,   r-   r.   r/   r0   r1   r2   r   r   Z+test_framed_write_sizes_with_delayed_writerr   r   r   r   r;   G   s   

r;   c               @   s   e Zd Zddd„Zdd„ ZdS )ÚPersistentPicklerUnpicklerMixinNc                s:   G ‡ fdd„dˆ j ƒ}t ¡ }|||ƒ}| |¡ | ¡ S )Nc                   s   e Zd Z‡ fdd„ZdS )z:PersistentPicklerUnpicklerMixin.dumps.<locals>.PersPicklerc                s
   ˆ   |¡S )N)Úpersistent_id)ÚsubselfÚobj)r$   r   r   r=   \   s    zHPersistentPicklerUnpicklerMixin.dumps.<locals>.PersPickler.persistent_idN)r   r   r   r=   r   )r$   r   r   ÚPersPickler[   s   r@   )r4   r!   r"   r   Úgetvalue)r$   r8   r9   r@   r'   r:   r   )r$   r   r   Z   s
    

z%PersistentPicklerUnpicklerMixin.dumpsc                s4   G ‡ fdd„dˆ j ƒ}t |¡}||f|Ž}| ¡ S )Nc                   s   e Zd Z‡ fdd„ZdS )z<PersistentPicklerUnpicklerMixin.loads.<locals>.PersUnpicklerc                s
   ˆ   |¡S )N)Úpersistent_load)r>   r?   )r$   r   r   rB   e   s    zLPersistentPicklerUnpicklerMixin.loads.<locals>.PersUnpickler.persistent_loadN)r   r   r   rB   r   )r$   r   r   ÚPersUnpicklerd   s   rC   )r#   r!   r"   r   )r$   r%   r&   rC   r'   r(   r   )r$   r   r   c   s    
z%PersistentPicklerUnpicklerMixin.loads)N)r   r   r   r   r   r   r   r   r   r<   X   s   
	r<   c               @   s   e Zd ZejZejZdS )ÚPyPersPicklerTestsN)r   r   r   r   r   r4   r   r#   r   r   r   r   rD   l   s   rD   c               @   s4   e Zd ZejZejZej	dd„ ƒZ
ej	dd„ ƒZdS )ÚPyIdPersPicklerTestsc                s^   ‡ fdd„}G dd„ dˆ j ƒ}||ƒ G dd„ dˆ j ƒ}||ƒ G dd„ dˆ j ƒ}||ƒ d S )Nc                s„   xHt tjd ƒD ]6}t ¡ }| ||ƒ}| d¡ ˆ  ˆ  | ¡ ¡d¡ qW | t ¡ ƒ}ˆ  | 	d¡d¡ t
 |¡}~ˆ  |ƒ ¡ d S )Né   ÚabcÚdef)Úranger   ÚHIGHEST_PROTOCOLr!   r"   r   ÚassertEqualr   rA   r=   ÚweakrefÚrefÚassertIsNone)r   r9   r'   r4   Úr)r$   r   r   Úcheck{   s    


z@PyIdPersPicklerTests.test_pickler_reference_cycle.<locals>.checkc               @   s   e Zd Zdd„ ZdS )zFPyIdPersPicklerTests.test_pickler_reference_cycle.<locals>.PersPicklerc             S   s   |S )Nr   )r>   r?   r   r   r   r=   ˆ   s    zTPyIdPersPicklerTests.test_pickler_reference_cycle.<locals>.PersPickler.persistent_idN)r   r   r   r=   r   r   r   r   r@   ‡   s   r@   c               @   s   e Zd Zedd„ ƒZdS )zFPyIdPersPicklerTests.test_pickler_reference_cycle.<locals>.PersPicklerc             S   s   |S )Nr   )Úclsr?   r   r   r   r=      s    zTPyIdPersPicklerTests.test_pickler_reference_cycle.<locals>.PersPickler.persistent_idN)r   r   r   Úclassmethodr=   r   r   r   r   r@   Œ   s   c               @   s   e Zd Zedd„ ƒZdS )zFPyIdPersPicklerTests.test_pickler_reference_cycle.<locals>.PersPicklerc             S   s   | S )Nr   )r?   r   r   r   r=   “   s    zTPyIdPersPicklerTests.test_pickler_reference_cycle.<locals>.PersPickler.persistent_idN)r   r   r   r   r=   r   r   r   r   r@   ’   s   )r4   )r$   rP   r@   r   )r$   r   Útest_pickler_reference_cycley   s    z1PyIdPersPicklerTests.test_pickler_reference_cyclec                s^   ‡ fdd„}G dd„ dˆ j ƒ}||ƒ G dd„ dˆ j ƒ}||ƒ G dd„ dˆ j ƒ}||ƒ d S )Nc                sx   x<t tjd ƒD ]*}| t ˆ  d|¡¡ƒ}ˆ  | ¡ d¡ qW | t ¡ ƒ}ˆ  | d¡d¡ t	 
|¡}~ˆ  |ƒ ¡ d S )NrF   rG   rH   )rI   r   rJ   r!   r"   r   rK   r   rB   rL   rM   rN   )r   r9   r#   rO   )r$   r   r   rP   š   s    
zBPyIdPersPicklerTests.test_unpickler_reference_cycle.<locals>.checkc               @   s   e Zd Zdd„ ZdS )zJPyIdPersPicklerTests.test_unpickler_reference_cycle.<locals>.PersUnpicklerc             S   s   |S )Nr   )r>   Úpidr   r   r   rB   ¥   s    zZPyIdPersPicklerTests.test_unpickler_reference_cycle.<locals>.PersUnpickler.persistent_loadN)r   r   r   rB   r   r   r   r   rC   ¤   s   rC   c               @   s   e Zd Zedd„ ƒZdS )zJPyIdPersPicklerTests.test_unpickler_reference_cycle.<locals>.PersUnpicklerc             S   s   |S )Nr   )rQ   rT   r   r   r   rB   ª   s    zZPyIdPersPicklerTests.test_unpickler_reference_cycle.<locals>.PersUnpickler.persistent_loadN)r   r   r   rR   rB   r   r   r   r   rC   ©   s   c               @   s   e Zd Zedd„ ƒZdS )zJPyIdPersPicklerTests.test_unpickler_reference_cycle.<locals>.PersUnpicklerc             S   s   | S )Nr   )rT   r   r   r   rB   °   s    zZPyIdPersPicklerTests.test_unpickler_reference_cycle.<locals>.PersUnpickler.persistent_loadN)r   r   r   r   rB   r   r   r   r   rC   ¯   s   )r#   )r$   rP   rC   r   )r$   r   Útest_unpickler_reference_cycle˜   s    
z3PyIdPersPicklerTests.test_unpickler_reference_cycleN)r   r   r   r   r   r4   r   r#   r   Úcpython_onlyrS   rU   r   r   r   r   rE   s   s   rE   c               @   s   e Zd ZejZejZdS )ÚPyPicklerUnpicklerObjectTestsN)r   r   r   r   r   Úpickler_classr   Úunpickler_classr   r   r   r   rW   ¶   s   rW   c               @   s   e Zd ZejZdd„ ZdS )ÚPyDispatchTableTestsc             C   s
   t j ¡ S )N)r   Údispatch_tableÚcopy)r$   r   r   r   Úget_dispatch_tableÀ   s    z'PyDispatchTableTests.get_dispatch_tableN)r   r   r   r   r   rX   r]   r   r   r   r   rZ   ¼   s   rZ   c               @   s   e Zd ZejZdd„ ZdS )ÚPyChainDispatchTableTestsc             C   s   t  i tj¡S )N)ÚcollectionsÚChainMapr   r[   )r$   r   r   r   r]   È   s    z,PyChainDispatchTableTests.get_dispatch_tableN)r   r   r   r   r   rX   r]   r   r   r   r   r^   Ä   s   r^   c               @   s,   e Zd ZddlmZmZmZmZmZm	Z	 dS )ÚCPickleTestsr   )r   r   r   r   r   r   N)
r   r   r   Ú_pickler   r   r   r   r   r   r   r   r   r   ra   Í   s   ra   c               @   s"   e Zd ZejZejfZejfZ	dS )ÚCUnpicklerTestsN)
r   r   r   rb   r   r#   r   r+   r*   r2   r   r   r   r   rc   Ð   s   rc   c               @   s   e Zd ZejZejZdS )ÚCPicklerTestsN)r   r   r   rb   r   r4   r   r#   r   r   r   r   rd   Õ   s   rd   c               @   s   e Zd ZejZejZdS )ÚCPersPicklerTestsN)r   r   r   rb   r   r4   r   r#   r   r   r   r   re   Ù   s   re   c               @   s   e Zd ZejZejZdS )ÚCIdPersPicklerTestsN)r   r   r   rb   r   r4   r   r#   r   r   r   r   rf   Ý   s   rf   c               @   s   e Zd ZejZejZdS )ÚCDumpPickle_LoadPickleN)	r   r   r   rb   r   r4   r   r   r#   r   r   r   r   rg   á   s   rg   c               @   s   e Zd ZejZejZdS )ÚDumpPickle_CLoadPickleN)	r   r   r   r   r   r4   rb   r   r#   r   r   r   r   rh   å   s   rh   c               @   s    e Zd ZejZejZdd„ ZdS )ÚCPicklerUnpicklerObjectTestsc          	   C   sX   |   t ¡ ¡}|  t¡ t|_W d Q R X |  t¡ dd i|_W d Q R X dd i|_d S )NéÿÿÿÿrF   )rY   r!   r"   ZassertRaisesÚ	TypeErrorÚobjectZmemor.   )r$   r#   r   r   r   Útest_issue18339í   s    z,CPicklerUnpicklerObjectTests.test_issue18339N)	r   r   r   rb   r   rX   r   rY   rm   r   r   r   r   ri   é   s   ri   c               @   s   e Zd ZejZdd„ ZdS )ÚCDispatchTableTestsc             C   s
   t j ¡ S )N)r   r[   r\   )r$   r   r   r   r]   ø   s    z&CDispatchTableTests.get_dispatch_tableN)r   r   r   r   r   rX   r]   r   r   r   r   rn   ö   s   rn   c               @   s   e Zd ZejZdd„ ZdS )ÚCChainDispatchTableTestsc             C   s   t  i tj¡S )N)r_   r`   r   r[   )r$   r   r   r   r]   ý   s    z+CChainDispatchTableTests.get_dispatch_tableN)r   r   r   r   r   rX   r]   r   r   r   r   ro   û   s   ro   c               @   s"   e Zd ZejZdd„ Zdd„ ZdS )ÚSizeofTestsc             C   s¢   t  d¡}t t ¡ ¡}|  t |¡|¡ t	 
d¡}t	 
d¡}| j}|||| d|  t d¡ ƒ xtdƒD ]}| t|ƒ¡ qnW |||| d|  d ƒ d S )	NZ6P2n3i2n3iPZ3nP0nZP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xxxxxxxxé   é    r   )r   Úcalcobjsizerb   r   r!   r"   rK   rl   Ú
__sizeof__r/   ÚcalcsizeÚcheck_sizeofÚsysÚ	getsizeofrI   r   Úchr)r$   Úbasesizer:   ZMT_sizeZME_sizerP   Úir   r   r   Útest_pickler  s    


zSizeofTests.test_picklerc                s–  t  d¡}tj‰t d¡‰ t d¡‰| j‰xhdD ]`}xZdD ]R}ˆt ¡ ||d}|  	t
 |¡|¡ ˆ||dˆ   t|ƒ d t|ƒ d ƒ q:W q0W |td	ƒ d td
ƒ d ‰‡ ‡‡‡‡fdd„}|dddƒ |dgd ddƒ |dd„ tdƒD ƒddƒ dd„ }||dƒddƒ ||dƒddƒ ||dƒddƒ ||dƒddƒ ||dƒddƒ ˆt t dd¡¡d	d
d}| ¡  ˆ|ˆdˆ   d d ƒ d S )Nz2P2n2P 2P2n2i5P 2P3n6P2n2iÚPÚn)ÚASCIIzUTF-16zlatin-1)ÚstrictÚreplace)ÚencodingÚerrorsrs   rF   r€   r   c                sD   t  | ¡}ˆt |¡ddd}| ¡  ˆ|ˆ|ˆ   |ˆ  ƒ d S )Nr€   r   )rƒ   r„   )r   r   r!   r"   r   )ÚdataZ	memo_sizeZ
marks_sizer   r(   )r~   rP   r   Ústdsizer#   r   r   Úcheck_unpickler%  s
    


z3SizeofTests.test_unpickler.<locals>.check_unpicklerr   éd   é   c             S   s   g | ]}t |ƒ‘qS r   )rz   )Ú.0r|   r   r   r   ú
<listcomp>0  s    z.SizeofTests.test_unpickler.<locals>.<listcomp>é€   c             S   s"   d}xt | ƒD ]}||g}qW |S )Nr   )rI   )Zdeepr…   r|   r   r   r   Úrecurse1  s    z+SizeofTests.test_unpickler.<locals>.recurseé:   é2   é@   é†   Úaé   )r   rt   rb   r   r/   rv   rw   r!   r"   rK   rl   ru   ÚlenrI   r   r   r   )r$   r{   rƒ   r„   r(   r‡   r   r   )r~   rP   r   r†   r#   r   Útest_unpickler  s6    





.
zSizeofTests.test_unpicklerN)r   r   r   r   rw   r}   r•   r   r   r   r   rp      s   rp   )Z_elementtreezxml.etree.ElementTree)ZcPickler   )ÚStringIOr!   )Z	cStringIOr!   )Z__builtin__Z
basestringÚbuiltinsÚstr)Ú
exceptionsÚStandardErrorr—   Ú	Exception)ÚUserDictrœ   r_   rœ   )ÚsocketZ_socketobjectr   Z
SocketTypec             C   s6   | |ft krt | |f \} }n| tkr.t|  } | |fS )N)r   r   )ÚmoduleÚnamer   r   r   ÚmappingP  s
    r    c             C   s6   | |ft krt | |f \} }n| tkr.t|  } | |fS )N)r   r   )rž   rŸ   r   r   r   Úreverse_mappingW  s
    r¡   c             C   s¤   y
t j|  S  tk
rž   yt| ƒ W nl tk
rb } ztjrNtd| |f ƒ t‚W d d }~X Y n2 tk
r’ } ztjr€t|ƒ ‚ W d d }~X Y nX t j|  S X d S )NzCan't import module %r: %s)	rx   ÚmodulesÚKeyErrorÚ
__import__r-   r   ÚverboseÚprintr1   )rž   Úexcr   r   r   Ú	getmodule^  s    
r¨   c             C   s*   t | ƒ}x| d¡D ]}t||ƒ}qW |S )NÚ.)r¨   ÚsplitÚgetattr)rž   rŸ   r?   r   r   r   r   Úgetattributen  s    r¬   c             c   s>   x8t | ƒD ],}t| |ƒ}t|tƒr
t|tƒr
||fV  q
W d S )N)Údirr«   Ú
isinstanceÚtypeÚ
issubclassÚBaseException)ÚmodrŸ   Úattrr   r   r   Úget_exceptionst  s    
r´   c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚCompatPickleTestsc          	   C   st   t t ¡ ƒ}|t tƒO }|dd„ tD ƒO }|dd„ t ¡ D ƒO }x.|D ]&}yt|ƒ W qF tk
rj   Y qFX qFW d S )Nc             S   s   h | ]\}}|’qS r   r   )rŠ   rž   rŸ   r   r   r   ú	<setcomp>~  s    z0CompatPickleTests.test_import.<locals>.<setcomp>c             S   s   h | ]\}}|’qS r   r   )rŠ   rž   rŸ   r   r   r   r¶     s    )Úsetr   Úvaluesr   r   r   r¨   r1   )r$   r¢   rž   r   r   r   Útest_import{  s    
zCompatPickleTests.test_importc          
   C   s‚   x|t  ¡ D ]p\}}|  ||f¡T yt|ƒ W n tk
rB   Y nX |d d… dkrp|  |t¡ |  t| |¡ W d Q R X q
W d S )NrF   Ú_)r   ÚitemsÚsubTestr¨   r1   ZassertInr   rK   )r$   Úmodule3Úmodule2r   r   r   Útest_import_mapping†  s    z%CompatPickleTests.test_import_mappingc          
   C   sü   xöt  ¡ D ]ê\\}}\}}|  ||f||ff¡¾ ||fdkrZt||ƒ}|  t|tƒ¡ n||fdkr‚t||ƒ}|  t|tƒ¡ nht||ƒ\}}|d d… dkr´|  	||f||f¡ yt||ƒ}W n tk
rÖ   Y nX |  	t||ƒ|¡ W d Q R X q
W d S )N)r™   ÚOSError)r™   r1   rF   rº   )
r   r»   r¼   r¬   Z
assertTruer°   rÀ   r1   r    rK   )r$   r½   Úname3r¾   Úname2r³   rž   rŸ   r   r   r   Útest_name_mapping‘  s     

z#CompatPickleTests.test_name_mappingc       	      C   sô   xît  ¡ D ]â\}}|  ||f¡Æ yt|ƒ W n0 tk
r^ } ztjrNt|ƒ W d d }~X Y nX ||ftkr¾t	 
|d ¡|kr¾x@t ¡ D ]"\\}}\}}||f||fkr†P q†W |  d||f ¡ t	 
||¡}t  
||¡}|  ||¡ W d Q R X q
W d S )Nz No reverse mapping from %r to %r)r   r»   r¼   r¨   r1   r   r¥   r¦   ÚALT_IMPORT_MAPPINGr   Úgetr   ZfailrK   )	r$   r¾   r½   r§   Zm3Zn3Zm2Zn2rž   r   r   r   Útest_reverse_import_mapping¥  s"    z-CompatPickleTests.test_reverse_import_mappingc          
   C   s¼   x¶t  ¡ D ]ª\\}}\}}|  ||f||ff¡~ yt||ƒ}W n tk
rT   Y nX t||ƒ\}}||||ftkrˆ|  ||f||f¡ t||ƒ\}}|  ||f||f¡ W d Q R X q
W d S )N)	r   r»   r¼   r¬   r1   r¡   ÚALT_NAME_MAPPINGrK   r    )r$   r¾   rÂ   r½   rÁ   r³   rž   rŸ   r   r   r   Útest_reverse_name_mapping¹  s    z+CompatPickleTests.test_reverse_name_mappingc          
   C   s*  |   tddƒd¡ |   tddƒd¡ |   tddƒd¡ |   tddƒd¡ |   tddƒd	¡ xÊttƒD ]¾\}}|  |¡¦ |tttt	fkrŠwd|t
k	r°t|t
ƒr°|   td|ƒd	¡ nh|tk	rìt|tƒrì|   td|ƒd
¡ |   td|ƒd|f¡ n,|   td|ƒd|f¡ |   td|ƒd|f¡ W d Q R X qdW d S )Nr™   rš   )r—   r›   r›   r—   )r™   r›   rÀ   )r—   rÀ   )r™   rÀ   )r™   r1   )rK   r    r¡   r´   r—   r¼   ÚBlockingIOErrorÚResourceWarningÚStopAsyncIterationÚRecursionErrorrÀ   r°   r1   )r$   rŸ   r§   r   r   r   Útest_exceptionsÆ  s:    
z!CompatPickleTests.test_exceptionsc          
   C   sf   t  d¡}xVt|ƒD ]J\}}|  |¡2 |  td|ƒd|f¡ |  td|ƒd|f¡ W d Q R X qW d S )Nzmultiprocessing.contextZmultiprocessing)r   Úimport_moduler´   r¼   rK   r¡   r    )r$   rž   rŸ   r§   r   r   r   Útest_multiprocessing_exceptionsç  s    

z1CompatPickleTests.test_multiprocessing_exceptionsN)
r   r   r   r¹   r¿   rÃ   rÆ   rÈ   rÍ   rÏ   r   r   r   r   rµ   z  s   !rµ   c              C   sT   t tttttttg} tr<|  	t
ttttttttttttg¡ tj| Ž  t t¡ d S )N)r   r    r3   rD   rE   rZ   r^   rµ   Úhas_c_implementationÚextendra   rc   rd   re   rf   rg   rh   rW   ri   rn   ro   r;   rp   r   Zrun_unittestZrun_doctestr   )Ztestsr   r   r   Ú	test_mainñ  s    


rÒ   Ú__main__)=Z_compat_pickler   r   r   r   r—   r   r!   r_   r/   rx   rL   ZunittestZtestr   Ztest.pickletesterr   r   r	   r
   r   r   r   r   rb   rÐ   r1   r   r    r3   r;   rl   r<   rD   rE   rW   rZ   r^   ra   rc   rd   re   rf   rg   rh   ri   rn   ro   rV   ZTestCaserp   rÄ   rÇ   r    r¡   r¨   r¬   r´   rµ   rÒ   r   r   r   r   r   Ú<module>   s‚   
	B
Bw
