AlkantarClanX12

Your IP : 3.135.220.219


Current Path : /opt/alt/python35/lib64/python3.5/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/asyncio/__pycache__/test_utils.cpython-35.opt-2.pyc



���]�8�@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZddlmZmZyddlZWnek
rdZYnXddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lm Z ddl!m"Z"ej#dkr�ddl$m%Z%nddlm%Z%dd�Z&dd�Z'ddd�Z(dd�Z)Gdd�de�Z*Gdd�de�Z+Gdd�d�Z,Gd d!�d!e,e+�Z-d"d#d$d%�Z.e/ed&�rGd'd(�d(ej0e�Z1Gd)d*�d*e1e�Z2Gd+d,�d,e2�Z3Gd-d.�d.e,e3�Z4d/d0�Z5ej6d1d2��Z7ej6d"d#d3d4��Z8ej6d5d6d7dd"d#d8d9��Z9d:d;�Z:Gd<d=�d=ej;�Z<Gd>d?�d?ej=�Z>d@dA�Z?GdBdC�dCe@�ZAdDdE�ZBGdFdG�dGejC�ZCej6dHdI��ZDejEejFejGdJdK�ZHdLdM�ZIdS)N�N)�mock)�
HTTPServer)�WSGIRequestHandler�
WSGIServer�)�base_events)�compat)�events)�futures)�	selectors)�tasks)�	coroutine)�logger)�support�win32)�
socketpaircCs$tdkrdStjtj�SdS)N)�sslZ
SSLContextZPROTOCOL_SSLv23�rr�//opt/alt/python35/lib64/python3.5/test_utils.py�dummy_ssl_context-src
CsVtdd��}|�}|j|�}d|_z|j|�Wd|j�XdS)NcSsdS)Nrrrrr�once5szrun_briefly.<locals>.onceF)r
Zcreate_taskZ_log_destroy_pending�run_until_complete�close)�loopr�gen�trrr�run_briefly4s		r�cCsttj�|}x]|�so|dk	rP|tj�}|dkrPtj��|jtjdd|��qWdS)Nrg����MbP?r)�timer
�TimeoutErrorrr�sleep)rZpred�timeout�deadlinerrr�	run_untilCsr#cCs|j|j�|j�dS)N)Z	call_soon�stopZrun_forever)rrrr�run_onceMsr%c@s(eZdZdd�Zdd�ZdS)�SilentWSGIRequestHandlercCs
tj�S)N)�io�StringIO)�selfrrr�
get_stderrZsz#SilentWSGIRequestHandler.get_stderrcGsdS)Nr)r)�format�argsrrr�log_message]sz$SilentWSGIRequestHandler.log_messageN)�__name__�
__module__�__qualname__r*r-rrrrr&Xsr&cs4eZdZdZ�fdd�Zdd�Z�S)�SilentWSGIServer�cs/t�j�\}}|j|j�||fS)N)�super�get_request�
settimeout�request_timeout)r)�request�client_addr)�	__class__rrr4eszSilentWSGIServer.get_requestcCsdS)Nr)r)r7�client_addressrrr�handle_errorjszSilentWSGIServer.handle_error)r.r/r0r6r4r;rr)r9rr1asr1c@seZdZdd�ZdS)�SSLWSGIServerMixincCs�tjjtjjt�dd�}tjj|�s]tjjtjjtj�dd�}tjj|d�}tjj|d�}tj|d|d|d	d
�}y!|j|||�|j	�Wnt
k
r�YnXdS)Nz..Ztests�testZtest_asynciozssl_key.pemzssl_cert.pem�keyfile�certfileZserver_sideT)�os�path�join�dirname�__file__�isdirrZwrap_socketZRequestHandlerClassr�OSError)r)r7r:�herer>r?Zssockrrr�finish_requestps$	
z!SSLWSGIServerMixin.finish_requestN)r.r/r0rHrrrrr<nsr<c@seZdZdS)�
SSLWSGIServerN)r.r/r0rrrrrI�srI�use_sslFc
#s�dd�}|r|n|}||t���j|��j�_tjd�fdd��}|j�z	�VWd�j��j�|j	�XdS)NcSs#d}dg}|||�dgS)Nz200 OK�Content-type�
text/plainsTest message)rKrLr)�environZstart_response�statusZheadersrrr�app�s	
z_run_test_server.<locals>.app�targetcs�jdd�S)NZ
poll_intervalg�������?)Z
serve_foreverr)�httpdrr�<lambda>�sz"_run_test_server.<locals>.<lambda>)
r&Zset_appZserver_address�address�	threading�Thread�start�shutdownZserver_closerB)rSrJ�
server_cls�server_ssl_clsrOZserver_classZ
server_threadr)rQr�_run_test_server�s
	
	

rZ�AF_UNIXc@seZdZdd�ZdS)�UnixHTTPServercCs&tjj|�d|_d|_dS)Nz	127.0.0.1�P)�socketserver�UnixStreamServer�server_bindZserver_nameZserver_port)r)rrrr`�s	zUnixHTTPServer.server_bindN)r.r/r0r`rrrrr\�sr\cs4eZdZdZdd�Z�fdd�Z�S)�UnixWSGIServerr2cCstj|�|j�dS)N)r\r`Z
setup_environ)r)rrrr`�s
zUnixWSGIServer.server_bindcs/t�j�\}}|j|j�|dfS)N�	127.0.0.1�)rbrc)r3r4r5r6)r)r7r8)r9rrr4�szUnixWSGIServer.get_request)r.r/r0r6r`r4rr)r9rra�srac@seZdZdd�ZdS)�SilentUnixWSGIServercCsdS)Nr)r)r7r:rrrr;�sz!SilentUnixWSGIServer.handle_errorN)r.r/r0r;rrrrrd�srdc@seZdZdS)�UnixSSLWSGIServerN)r.r/r0rrrrre�srec	Cs!tj��}|jSWdQRXdS)N)�tempfile�NamedTemporaryFile�name)�filerrr�gen_unix_socket_path�srjccs@t�}z	|VWdytj|�Wntk
r:YnXXdS)N)rjr@�unlinkrF)rArrr�unix_socket_path�s		
rlccs;t��+}td|d|dtdt�EdHWdQRXdS)NrSrJrXrY)rlrZrdre)rJrArrr�run_test_unix_server�srm�hostz	127.0.0.1�portc	cs.td||fd|dtdt�EdHdS)NrSrJrXrY)rZr1rI)rnrorJrrr�run_test_server�srpcCsni}xHt|�D]:}|jd�r:|jd�r:qtdd�||<qWtd|f|j|��S)N�__�return_valueZTestProtocol)�dir�
startswith�endswith�MockCallback�type�	__bases__)�base�dctrhrrr�make_test_protocol�sr{c@sOeZdZdd�Zddd�Zdd�Zdd	�Zd
d�ZdS)�TestSelectorcCs
i|_dS)N)�keys)r)rrr�__init__�szTestSelector.__init__NcCs)tj|d||�}||j|<|S)Nr)r�SelectorKeyr})r)�fileobjr	�data�keyrrr�register�s
zTestSelector.registercCs|jj|�S)N)r}�pop)r)r�rrr�
unregisterszTestSelector.unregistercCsgS)Nr)r)r!rrr�selectszTestSelector.selectcCs|jS)N)r})r)rrr�get_mapszTestSelector.get_map)r.r/r0r~r�r�r�r�rrrrr|�s
r|cseZdZd�fdd�Zdd�Zdd�Z�fdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Z�fd"d#�Z�fd$d%�Zd&d'�Zd(d)�Z�S)*�TestLoopNcs�t�j�|dkr1dd�}d|_n	d|_|�|_t|j�d|_d|_g|_t�|_	i|_
i|_|j�t
j�|_dS)Ncss	dVdS)Nrrrrrr!szTestLoop.__init__.<locals>.genFTrg��&�.>)r3r~�_check_on_close�_gen�next�_timeZ_clock_resolution�_timersr|�	_selector�readers�writers�reset_counters�weakref�WeakValueDictionary�_transports)r)r)r9rrr~s
	
					
zTestLoop.__init__cCs|jS)N)r�)r)rrrr4sz
TestLoop.timecCs|r|j|7_dS)N)r�)r)�advancerrr�advance_time7szTestLoop.advance_timecsOt�j�|jrKy|jjd�Wntk
r>Yn
Xtd��dS)NrzTime generator is not finished)r3rr�r��send�
StopIteration�AssertionError)r))r9rrr<s
	
zTestLoop.closecGs tj|||�|j|<dS)N)r	�Handler�)r)�fd�callbackr,rrr�_add_readerFszTestLoop._add_readercCs6|j|d7<||jkr.|j|=dSdSdS)NrTF)�remove_reader_countr�)r)r�rrr�_remove_readerIs

zTestLoop._remove_readercGs|j|}dS)N)r�)r)r�r�r,�handlerrr�
assert_readerQs
zTestLoop.assert_readercGs tj|||�|j|<dS)N)r	r�r�)r)r�r�r,rrr�_add_writerYszTestLoop._add_writercCs6|j|d7<||jkr.|j|=dSdSdS)NrTF)�remove_writer_countr�)r)r�rrr�_remove_writer\s

zTestLoop._remove_writercGs|j|}dS)N)r�)r)r�r�r,r�rrr�
assert_writerds
zTestLoop.assert_writercCsBy|j|}Wntk
r%YnXtdj||���dS)Nz.File descriptor {!r} is used by transport {!r})r��KeyError�RuntimeErrorr+)r)r�Z	transportrrr�_ensure_fd_no_transportls
z TestLoop._ensure_fd_no_transportcGs |j|�|j|||�S)N)r�r�)r)r�r�r,rrr�
add_readervs
zTestLoop.add_readercCs|j|�|j|�S)N)r�r�)r)r�rrr�
remove_reader{s
zTestLoop.remove_readercGs |j|�|j|||�S)N)r�r�)r)r�r�r,rrr�
add_writer�s
zTestLoop.add_writercCs|j|�|j|�S)N)r�r�)r)r�rrr�
remove_writer�s
zTestLoop.remove_writercCs(tjt�|_tjt�|_dS)N)�collections�defaultdict�intr�r�)r)rrrr��szTestLoop.reset_counterscsMt�j�x0|jD]%}|jj|�}|j|�qWg|_dS)N)r3�	_run_oncer�r�r�r�)r)�whenr�)r9rrr��s

zTestLoop._run_oncecs&|jj|�t�j|||�S)N)r��appendr3�call_at)r)r�r�r,)r9rrr��szTestLoop.call_atcCsdS)Nr)r)Z
event_listrrr�_process_events�szTestLoop._process_eventscCsdS)Nr)r)rrr�_write_to_self�szTestLoop._write_to_self)r.r/r0r~rr�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr)r9rr�
s(

r�cKstjddg|�S)N�spec�__call__)rZMock)�kwargsrrrrv�srvc@seZdZdd�ZdS)�MockPatterncCs"ttjt|�|tj��S)N)�bool�re�search�str�S)r)�otherrrr�__eq__�szMockPattern.__eq__N)r.r/r0r�rrrrr��s	r�cCs2tj|�}|dkr.td|f��|S)Nzunable to get the source of %r)r	Z_get_function_source�
ValueError)�func�sourcerrr�get_function_source�sr�c@sjeZdZdddd�Zddd�Zdd	�Zd
d�Zdd
�Zej	sfdd�Z
dS)�TestCase�cleanupTcCs'tjd�|r#|j|j�dS)N)r	�set_event_loopZ
addCleanupr)r)rr�rrrr��s
zTestCase.set_event_loopNcCst|�}|j|�|S)N)r�r�)r)rrrrr�
new_test_loop�s
zTestCase.new_test_loopcCs|jt_dS)N)�_get_running_loopr	)r)rrr�unpatch_get_running_loop�sz!TestCase.unpatch_get_running_loopcCs.tj|_dd�t_tj�|_dS)NcSsdS)NrrrrrrR�sz TestCase.setUp.<locals>.<lambda>)r	r�rZthreading_setup�_thread_cleanup)r)rrr�setUp�szTestCase.setUpcCsU|j�tjd�|jtj�d�|j�tj|j	�tj
�dS)N)NNN)r�r	r�ZassertEqual�sys�exc_infoZ
doCleanupsrZthreading_cleanupr�Z
reap_children)r)rrr�tearDown�s


zTestCase.tearDowncOsGdd�d�}|�S)Nc@s(eZdZdd�Zdd�ZdS)z!TestCase.subTest.<locals>.EmptyCMcSsdS)Nr)r)rrr�	__enter__�sz+TestCase.subTest.<locals>.EmptyCM.__enter__cWsdS)Nr)r)�excrrr�__exit__�sz*TestCase.subTest.<locals>.EmptyCM.__exit__N)r.r/r0r�r�rrrr�EmptyCM�sr�r)r)r,r�r�rrr�subTest�szTestCase.subTest)r.r/r0r�r�r�r�r�rZPY34r�rrrrr��s
	r�ccs;tj}ztjtjd�dVWdtj|�XdS)Nr)r�level�setLevel�logging�CRITICAL)Z	old_levelrrr�disable_logger�s
		r�cCs=tjtj�}||_||_||_d|j_|S)Ng)rZ	MagicMock�socket�protorw�family�
gettimeoutrr)r�rwr��sockrrr�mock_nonblocking_socket�s			r�cCstjddd�S)Nz'asyncio.sslproto._is_sslproto_availablerrF)rZpatchrrrr�force_legacy_ssl_support�sr�)Jr��
contextlibr'r�r@r�r�r^r�rfrTrZunittestr�rZhttp.serverrZwsgiref.simple_serverrrr�ImportErrorrcrrr	r
rrZ
coroutinesr
�logrr=r�platformZ
windows_utilsrrrr#r%r&r1r<rIrZ�hasattrr_r\rardrerj�contextmanagerrlrmrpr{�BaseSelectorr|Z
BaseEventLoopr�rvr�r�r�r�r��IPPROTO_TCP�SOCK_STREAM�AF_INETr�r�rrrr�<module>s~

	
		
�
-