Your IP : 18.119.118.151


Current Path : /opt/alt/python36/lib64/python3.6/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/asyncio/__pycache__/test_utils.cpython-36.opt-2.pyc

3

��2a�:�
@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZddlmZmZyddlZWnek
r�dZYnXddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lm Z ddl!m"Z"ej#dk�rDddl$m%Z%nddlm%Z%dd�Z&e&d�Z'e&d�Z(dd�Z)dd�Z*dQdd�Z+dd�Z,Gdd�de�Z-Gd d!�d!e�Z.Gd"d#�d#�Z/Gd$d%�d%e/e.�Z0d&d'�d(d)�Z1e2ed*��rVGd+d,�d,ej3e�Z4Gd-d.�d.e4e�Z5Gd/d0�d0e5�Z6Gd1d2�d2e/e6�Z7d3d4�Z8ej9d5d6��Z:ej9d&d'�d7d8��Z;ej9d9dd&d:�d;d<��Z<d=d>�Z=Gd?d@�d@ej>�Z?GdAdB�dBej@�ZAdCdD�ZBGdEdF�dFeC�ZDdGdH�ZEGdIdJ�dJejF�ZFej9dKdL��ZGejHejIejJfdMdN�ZKdOdP�ZLdS)R�N)�mock)�
HTTPServer)�WSGIRequestHandler�
WSGIServer�)�base_events)�compat)�events)�futures)�	selectors)�tasks)�	coroutine)�logger)�support�win32)�
socketpaircCs`ttd�r*tjjtj|�}tjj|�r*|Stjjtjjtj�d|�}tjj|�rT|St	|��dS)N�
TEST_HOME_DIR�test)
�hasattrr�os�path�joinr�isfile�dirname�__file__�FileNotFoundError)�filename�fullname�r�//opt/alt/python36/lib64/python3.6/test_utils.py�	data_file-s
r zssl_cert.pemzssl_key.pemcCstdkrdStjtj�SdS)N)�ssl�
SSLContextZPROTOCOL_SSLv23rrrr�dummy_ssl_context<sr#c
Cs@tdd��}|�}|j|�}d|_z|j|�Wd|j�XdS)NcSsdS)Nrrrrr�onceDszrun_briefly.<locals>.onceF)r
Zcreate_taskZ_log_destroy_pending�run_until_complete�close)�loopr$�gen�trrr�run_brieflyCs
r*�cCsTtj�|}xB|�sN|dk	r8|tj�}|dkr8tj��|jtjd|d��qWdS)Nrg����MbP?)r')�timer
�TimeoutErrorr%rZsleep)r'Zpred�timeoutZdeadlinerrr�	run_untilRsr/cCs|j|j�|j�dS)N)Z	call_soon�stopZrun_forever)r'rrr�run_once\sr1c@seZdZdd�Zdd�ZdS)�SilentWSGIRequestHandlercCstj�S)N)�io�StringIO)�selfrrr�
get_stderrisz#SilentWSGIRequestHandler.get_stderrcGsdS)Nr)r5�format�argsrrr�log_messagelsz$SilentWSGIRequestHandler.log_messageN)�__name__�
__module__�__qualname__r6r9rrrrr2gsr2cs(eZdZdZ�fdd�Zdd�Z�ZS)�SilentWSGIServer�cs"t�j�\}}|j|j�||fS)N)�super�get_request�
settimeout�request_timeout)r5�request�client_addr)�	__class__rrr@tszSilentWSGIServer.get_requestcCsdS)Nr)r5rC�client_addressrrr�handle_erroryszSilentWSGIServer.handle_error)r:r;r<rBr@rG�
__classcell__rr)rErr=psr=c@seZdZdd�ZdS)�SSLWSGIServerMixincCs^t}t}tj�}|j||�|j|dd�}y|j|||�|j�Wntk
rXYnXdS)NT)Zserver_side)	�ONLYKEY�ONLYCERTr!r"Zload_cert_chainZwrap_socketZRequestHandlerClassr&�OSError)r5rCrFZkeyfileZcertfile�contextZssockrrr�finish_requestsz!SSLWSGIServerMixin.finish_requestN)r:r;r<rNrrrrrI}srIc@seZdZdS)�
SSLWSGIServerN)r:r;r<rrrrrO�srOF)�use_sslc
#svdd�}|r|n|}||t���j|��j�_tj�fdd�d�}|j�z
�VWd�j��j�|j	�XdS)NcSsd}dg}|||�dgS)Nz200 OK�Content-type�
text/plainsTest message)rQrRr)�environZstart_response�statusZheadersrrr�app�s
z_run_test_server.<locals>.appcs�jdd�S)Ng�������?)Z
poll_interval)Z
serve_foreverr)�httpdrr�<lambda>�sz"_run_test_server.<locals>.<lambda>)�target)
r2Zset_appZserver_address�address�	threadingZThread�start�shutdownZserver_closer)rYrP�
server_cls�server_ssl_clsrUZserver_classZ
server_threadr)rVr�_run_test_server�s


r_ZAF_UNIXc@seZdZdd�ZdS)�UnixHTTPServercCstjj|�d|_d|_dS)Nz	127.0.0.1�P)�socketserver�UnixStreamServer�server_bindZserver_nameZserver_port)r5rrrrd�szUnixHTTPServer.server_bindN)r:r;r<rdrrrrr`�sr`cs(eZdZdZdd�Z�fdd�Z�ZS)�UnixWSGIServerr>cCstj|�|j�dS)N)r`rdZ
setup_environ)r5rrrrd�s
zUnixWSGIServer.server_bindcs"t�j�\}}|j|j�|dfS)N�	127.0.0.1�)rfrg)r?r@rArB)r5rCrD)rErrr@�szUnixWSGIServer.get_request)r:r;r<rBrdr@rHrr)rErre�srec@seZdZdd�ZdS)�SilentUnixWSGIServercCsdS)Nr)r5rCrFrrrrG�sz!SilentUnixWSGIServer.handle_errorN)r:r;r<rGrrrrrh�srhc@seZdZdS)�UnixSSLWSGIServerN)r:r;r<rrrrri�sric	Cstj��}|jSQRXdS)N)�tempfileZNamedTemporaryFile�name)�filerrr�gen_unix_socket_path�s
rmccs<t�}z
|VWdytj|�Wntk
r4YnXXdS)N)rmr�unlinkrL)rrrr�unix_socket_path�s
roc
cs,t��}t||ttd�EdHWdQRXdS)N)rYrPr]r^)ror_rhri)rPrrrr�run_test_unix_server�srpz	127.0.0.1)�host�portrPccst||f|ttd�EdHdS)N)rYrPr]r^)r_r=rO)rqrrrPrrr�run_test_server�s
rscCsPi}x4t|�D](}|jd�r(|jd�r(qtdd�||<qWtd|f|j|��S)N�__)�return_valueZTestProtocol)�dir�
startswith�endswith�MockCallback�type�	__bases__)�baseZdctrkrrr�make_test_protocol�sr}c@s6eZdZdd�Zddd�Zdd�Zdd	�Zd
d�ZdS)
�TestSelectorcCs
i|_dS)N)�keys)r5rrr�__init__szTestSelector.__init__NcCstj|d||�}||j|<|S)Nr)rZSelectorKeyr)r5�fileobjr	�data�keyrrr�registers
zTestSelector.registercCs|jj|�S)N)r�pop)r5r�rrr�
unregisterszTestSelector.unregistercCsgS)Nr)r5r.rrr�selectszTestSelector.selectcCs|jS)N)r)r5rrr�get_mapszTestSelector.get_map)N)r:r;r<r�r�r�r�r�rrrrr~s

r~cs�eZdZd,�fdd�	Zdd�Zdd�Z�fdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Z�fd$d%�Z�fd&d'�Zd(d)�Zd*d+�Z�ZS)-�TestLoopNcsvt�j�|dkr"dd�}d|_nd|_|�|_t|j�d|_d|_g|_t�|_	i|_
i|_|j�t
j�|_dS)Ncss
dVdS)Nrrrrrr(,szTestLoop.__init__.<locals>.genFTrg��&�.>)r?r��_check_on_close�_gen�next�_timeZ_clock_resolution�_timersr~Z	_selector�readers�writers�reset_counters�weakref�WeakValueDictionary�_transports)r5r()rErrr�(s

zTestLoop.__init__cCs|jS)N)r�)r5rrrr,?sz
TestLoop.timecCs|r|j|7_dS)N)r�)r5�advancerrr�advance_timeBszTestLoop.advance_timecsBt�j�|jr>y|jjd�Wntk
r4Yn
Xtd��dS)NrzTime generator is not finished)r?r&r�r��send�
StopIteration�AssertionError)r5)rErrr&Gs
zTestLoop.closecGstj|||�|j|<dS)N)r	�Handler�)r5�fd�callbackr8rrr�_add_readerQszTestLoop._add_readercCs0|j|d7<||jkr(|j|=dSdSdS)NrTF)�remove_reader_countr�)r5r�rrr�_remove_readerTs

zTestLoop._remove_readercGsh||jkrtd|�d���|j|}|j|krDtd|j�d|����|j|krdtd|j�d|����dS)Nzfd z is not registeredzunexpected callback: z != zunexpected callback args: )r�r�Z	_callbackZ_args)r5r�r�r8�handlerrr�
assert_reader\s



zTestLoop.assert_readercCs||jkrtd|�d���dS)Nzfd z is registered)r�r�)r5r�rrr�assert_no_readergs
zTestLoop.assert_no_readercGstj|||�|j|<dS)N)r	r�r�)r5r�r�r8rrr�_add_writerkszTestLoop._add_writercCs0|j|d7<||jkr(|j|=dSdSdS)NrTF)�remove_writer_countr�)r5r�rrr�_remove_writerns

zTestLoop._remove_writercGs|j|}dS)N)r�)r5r�r�r8r�rrr�
assert_writervs
zTestLoop.assert_writercCs8y|j|}Wntk
r"YnXtdj||���dS)Nz.File descriptor {!r} is used by transport {!r})r��KeyError�RuntimeErrorr7)r5r�Z	transportrrr�_ensure_fd_no_transport~sz TestLoop._ensure_fd_no_transportcGs|j|�|j||f|��S)N)r�r�)r5r�r�r8rrr�
add_reader�s
zTestLoop.add_readercCs|j|�|j|�S)N)r�r�)r5r�rrr�
remove_reader�s
zTestLoop.remove_readercGs|j|�|j||f|��S)N)r�r�)r5r�r�r8rrr�
add_writer�s
zTestLoop.add_writercCs|j|�|j|�S)N)r�r�)r5r�rrr�
remove_writer�s
zTestLoop.remove_writercCstjt�|_tjt�|_dS)N)�collections�defaultdict�intr�r�)r5rrrr��szTestLoop.reset_counterscs:t�j�x$|jD]}|jj|�}|j|�qWg|_dS)N)r?�	_run_oncer�r�r�r�)r5�whenr�)rErrr��s

zTestLoop._run_oncecs |jj|�t�j||f|��S)N)r��appendr?�call_at)r5r�r�r8)rErrr��szTestLoop.call_atcCsdS)Nr)r5Z
event_listrrr�_process_events�szTestLoop._process_eventscCsdS)Nr)r5rrr�_write_to_self�szTestLoop._write_to_self)N)r:r;r<r�r,r�r&r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rHrr)rErr�s*

r�cKstjfddgi|��S)N�spec�__call__)rZMock)�kwargsrrrry�sryc@seZdZdd�ZdS)�MockPatterncCsttjt|�|tj��S)N)�bool�re�search�str�S)r5�otherrrr�__eq__�szMockPattern.__eq__N)r:r;r<r�rrrrr��s	r�cCs$tj|�}|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@sVeZdZedd��Zdd�dd�Zddd	�Zd
d�Zdd
�Zdd�Z	e
jsRdd�ZdS)�TestCasecCs&|j}|dk	r|jdd�|j�dS)NT)�wait)Z_default_executorr\r&)r'�executorrrr�
close_loop�szTestCase.close_loopT)�cleanupcCs tjd�|r|j|j|�dS)N)r	�set_event_loopZ
addCleanupr�)r5r'r�rrrr��s
zTestCase.set_event_loopNcCst|�}|j|�|S)N)r�r�)r5r(r'rrr�
new_test_loop�s
zTestCase.new_test_loopcCs|jt_dS)N)�_get_running_loopr	)r5rrr�unpatch_get_running_loop�sz!TestCase.unpatch_get_running_loopcCs tj|_dd�t_tj�|_dS)NcSsdS)NrrrrrrW�sz TestCase.setUp.<locals>.<lambda>)r	r�rZthreading_setup�_thread_cleanup)r5rrr�setUp�s
zTestCase.setUpcCsB|j�tjd�|jtj�d�|j�tj|j	�tj
�dS)N)NNN)r�r	r�ZassertEqual�sys�exc_infoZ
doCleanupsrZthreading_cleanupr�Z
reap_children)r5rrr�tearDown�s
zTestCase.tearDowncOsGdd�d�}|�S)Nc@seZdZdd�Zdd�ZdS)z!TestCase.subTest.<locals>.EmptyCMcSsdS)Nr)r5rrr�	__enter__�sz+TestCase.subTest.<locals>.EmptyCM.__enter__cWsdS)Nr)r5�excrrr�__exit__�sz*TestCase.subTest.<locals>.EmptyCM.__exit__N)r:r;r<r�r�rrrr�EmptyCM�sr�r)r5r8r�r�rrr�subTest�szTestCase.subTest)N)
r:r;r<�staticmethodr�r�r�r�r�r�rZPY34r�rrrrr��s

r�ccs2tj}ztjtjd�dVWdtj|�XdS)Nr)r�levelZsetLevel�loggingZCRITICAL)Z	old_levelrrr�disable_logger�s

r�cCs*tjtj�}||_||_||_d|j_|S)Ng)rZ	MagicMock�socket�protorz�familyZ
gettimeoutru)r�rzr�Zsockrrr�mock_nonblocking_socketsr�cCstjddd�S)Nz'asyncio.sslproto._is_sslproto_availableF)ru)rZpatchrrrr�force_legacy_ssl_supportsr�)r+)Mr��
contextlibr3r�rr�r�rbr�rjrZr,Zunittestr�rZhttp.serverrZwsgiref.simple_serverrrr!�ImportErrorrgrrr	r
rrZ
coroutinesr
�logrrr�platformZ
windows_utilsrr rKrJr#r*r/r1r2r=rIrOr_rrcr`rerhrirm�contextmanagerrorprsr}ZBaseSelectorr~Z
BaseEventLoopr�ryr�r�r�r�r�ZIPPROTO_TCPZSOCK_STREAMZAF_INETr�r�rrrr�<module>s�


	


4

?>