Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/test_asyncio/__pycache__/utils.cpython-39.opt-2.pyc

a

XC?h	D�@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZddlmZmZzddlZWney�dZYn0ddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlm Z dd
�Z!e!d�Z"e!d�Z#e!d�Z$e!d�Z%ddddddddddd�
Z&dd�Z'dd �d!d"�Z(d#d$�Z)d%d&�Z*e j+fd'd(�Z,d)d*�Z-Gd+d,�d,e�Z.Gd-d.�d.e�Z/Gd/d0�d0�Z0Gd1d2�d2e0e/�Z1d3d4�d5d6�Z2e3ed7��rjGd8d9�d9e	j4e�Z5Gd:d;�d;e5e�Z6Gd<d=�d=e6�Z7Gd>d?�d?e0e7�Z8d@dA�Z9ej:dBdC��Z;ej:d3d4�dDdE��Z<ej:dFdd3dG�dHdI��Z=dJdK�Z>GdLdM�dMej?�Z@GdNdO�dOejA�ZBdPdQ�ZCGdRdS�dSeD�ZEGdTdU�dU�ZFdVdW�ZGGdXdY�dYejH�ZHej:dZd[��ZIejJejKejLfd\d]�ZMdS)^�N)�mock)�
HTTPServer)�WSGIRequestHandler�
WSGIServer)�base_events)�events)�format_helpers)�futures)�tasks)�logger)�supportcCs^ttd�r*tj�tj|�}tj�|�r*|Stj�tj�t�d|�}tj�|�rR|St	|��dS)N�
TEST_HOME_DIRz..)
�hasattrr�os�path�joinr
�isfile�dirname�__file__�FileNotFoundError)�filename�fullname�r�</opt/alt/python39/lib64/python3.9/test/test_asyncio/utils.py�	data_file's
rzssl_cert.pemzssl_key.pemzkeycert3.pemzpycacert.pem)z)http://testca.pythontest.net/testca/ocsp/)z0http://testca.pythontest.net/testca/pycacert.cer)z2http://testca.pythontest.net/testca/revocation.crl)�)ZcountryNameZXY))�organizationNamezPython Software Foundation CA))�
commonNamez
our-ca-serverzOct 28 14:23:16 2037 GMTzAug 29 14:23:16 2018 GMTZCB2D80995A69525C)r))ZlocalityNamezCastle Anthrax))rzPython Software Foundation))r�	localhost))ZDNSr�)
ZOCSPZ	caIssuersZcrlDistributionPointsZissuerZnotAfterZ	notBeforeZserialNumberZsubjectZsubjectAltName�versioncCs*t�tj�}|�tt�d|_tj|_|S�NF)	�ssl�
SSLContextZPROTOCOL_TLS_SERVER�load_cert_chain�ONLYCERT�ONLYKEY�check_hostname�	CERT_NONE�verify_mode)Zserver_contextrrr�simple_server_sslcontextIs
r*T)�disable_verifycCs"t�tj�}d|_|rtj|_|Sr!)r"r#ZPROTOCOL_TLS_CLIENTr'r(r))r+Zclient_contextrrr�simple_client_sslcontextQs
r,cCstdurdSt�tj�SdS�N)r"r#ZPROTOCOL_TLSrrrr�dummy_ssl_contextYsr.cCsDdd�}|�}|�|�}d|_z|�|�W|��n
|��0dS)Nc�sdSr-rrrrr�onceaszrun_briefly.<locals>.onceF)Zcreate_taskZ_log_destroy_pending�run_until_complete�close)�loopr/�gen�trrr�run_briefly`s
r5cCsLt��|}|�sH|dur6|t��}|dkr6t���|�t�d��qdS)Nrg����MbP?)�time�	monotonicr	�TimeoutErrorr0r
�sleep)r2Zpred�timeoutZdeadlinerrr�	run_untilnsr;cCs|�|j�|��dSr-)Z	call_soon�stopZrun_forever�r2rrr�run_oncexsr>c@seZdZdd�Zdd�ZdS)�SilentWSGIRequestHandlercCst��Sr-)�io�StringIO��selfrrr�
get_stderr�sz#SilentWSGIRequestHandler.get_stderrcGsdSr-r)rC�format�argsrrr�log_message�sz$SilentWSGIRequestHandler.log_messageN)�__name__�
__module__�__qualname__rDrGrrrrr?�sr?cs*eZdZejZ�fdd�Zdd�Z�ZS)�SilentWSGIServercs"t���\}}|�|j�||fSr-��super�get_requestZ
settimeout�request_timeout�rC�requestZclient_addr��	__class__rrrN�szSilentWSGIServer.get_requestcCsdSr-r�rCrQ�client_addressrrr�handle_error�szSilentWSGIServer.handle_error)	rHrIrJr�LOOPBACK_TIMEOUTrOrNrV�
__classcell__rrrRrrK�srKc@seZdZdd�ZdS)�SSLWSGIServerMixincCsTt��}|�tt�|j|dd�}z|�|||�|��WntyNYn0dS)NT)Zserver_side)	r"r#r$r%r&Zwrap_socketZRequestHandlerClassr1�OSError)rCrQrU�contextZssockrrr�finish_request�sz!SSLWSGIServerMixin.finish_requestN)rHrIrJr\rrrrrY�srYc@seZdZdS)�
SSLWSGIServerN�rHrIrJrrrrr]�sr]F)�use_sslc#s�dd���fdd�}|r|n|}||t����|��j�_tj�fdd�d�}|��z"�VW������|�	�n������|�	�0dS)Ncss<t|d�}|r8|d�t|d��}|V|t|�8}qdS)NZCONTENT_LENGTHz
wsgi.inputi)�int�read�min�len)�environ�size�datarrrr2�s
z_run_test_server.<locals>.loopcs2d}dg}|||�|ddkr(�|�SdgSdS)Nz200 OK)zContent-typez
text/plainZ	PATH_INFOz/loopsTest messager)rdZstart_responseZstatusZheadersr=rr�app�s
z_run_test_server.<locals>.appcs�jdd�S)Ng�������?)Z
poll_interval)Z
serve_foreverr)�httpdrr�<lambda>��z"_run_test_server.<locals>.<lambda>)�target)
r?Zset_appZserver_address�address�	threadingZThread�start�shutdownZserver_closer)rlr_�
server_cls�server_ssl_clsrgZserver_classZ
server_threadr)rhr2r�_run_test_server�s$


�
�rrZAF_UNIXc@seZdZdd�ZdS)�UnixHTTPServercCstj�|�d|_d|_dS)N�	127.0.0.1�P)�socketserver�UnixStreamServer�server_bindZserver_nameZserver_portrBrrrrx�szUnixHTTPServer.server_bindN)rHrIrJrxrrrrrs�srscs*eZdZejZdd�Z�fdd�Z�ZS)�UnixWSGIServercCst�|�|��dSr-)rsrxZ
setup_environrBrrrrx�s
zUnixWSGIServer.server_bindcs"t���\}}|�|j�|dfS)N)rt�rLrPrRrrrN�szUnixWSGIServer.get_request)	rHrIrJrrWrOrxrNrXrrrRrry�sryc@seZdZdd�ZdS)�SilentUnixWSGIServercCsdSr-rrTrrrrV�sz!SilentUnixWSGIServer.handle_errorN)rHrIrJrVrrrrr{�sr{c@seZdZdS)�UnixSSLWSGIServerNr^rrrrr|�sr|cCs2t���}|jWd�S1s$0YdSr-)�tempfileZNamedTemporaryFile�name)�filerrr�gen_unix_socket_path�s
r�ccs\t�}z,|VWzt�|�WqXty0YqX0n$zt�|�WntyTYn00dSr-)r�r�unlinkrZ)rrrr�unix_socket_paths�r�ccs@t��&}t||ttd�EdHWd�n1s20YdS�N)rlr_rprq)r�rrr{r|)r_rrrr�run_test_unix_servers
�r�rt�ZhostZportr_ccst||f|ttd�EdHdSr�)rrrKr]r�rrr�run_test_servers
�r�cCsLi}t|�D](}|�d�r&|�d�r&qtdd�||<qtd|f|j|��S)N�__)�return_valueZTestProtocol)�dir�
startswith�endswith�MockCallback�type�	__bases__)�baseZdctr~rrr�make_test_protocolsr�c@s6eZdZdd�Zddd�Zdd�Zdd	�Zd
d�ZdS)
�TestSelectorcCs
i|_dSr-��keysrBrrr�__init__'szTestSelector.__init__NcCst�|d||�}||j|<|S)Nr)�	selectorsZSelectorKeyr�)rC�fileobjrrf�keyrrr�register*s
zTestSelector.registercCs|j�|�Sr-)r��pop)rCr�rrr�
unregister/szTestSelector.unregistercCsgSr-r)rCr:rrr�select2szTestSelector.selectcCs|jSr-r�rBrrr�get_map5szTestSelector.get_map)N)rHrIrJr�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%�Zdd&��fd'd(�
Zd)d*�Zd+d,�Z�ZS).�TestLoopNcsvt���|dur"dd�}d|_nd|_|�|_t|j�d|_d|_g|_t�|_	i|_
i|_|��t
��|_dS)Ncss
dVdSr-rrrrrr3PszTestLoop.__init__.<locals>.genFTrg��&�.>)rMr��_check_on_close�_gen�next�_timeZ_clock_resolution�_timersr�Z	_selector�readers�writers�reset_counters�weakrefZWeakValueDictionary�_transports)rCr3rRrrr�Ls

zTestLoop.__init__cCs|jSr-�r�rBrrrr6csz
TestLoop.timecCs|r|j|7_dSr-r�)rC�advancerrr�advance_timefszTestLoop.advance_timecs@t���|jr<z|j�d�Wnty2Yn
0td��dS)NrzTime generator is not finished)rMr1r�r��send�
StopIteration�AssertionErrorrBrRrrr1ks
zTestLoop.closecGst�|||d�|j|<dSr-)r�Handler��rC�fd�callbackrFrrr�_add_readeruszTestLoop._add_readercCs0|j|d7<||jvr(|j|=dSdSdS�N�TF)�remove_reader_countr��rCr�rrr�_remove_readerxs

zTestLoop._remove_readercGsh||jvrtd|�d���|j|}|j|krDtd|j�d|����|j|krdtd|j�d|����dS)N�fd z is not registeredzunexpected callback: z != zunexpected callback args: )r�r�Z	_callbackZ_args�rCr�r�rFZhandlerrr�
assert_reader�s


�
�zTestLoop.assert_readercCs||jvrtd|�d���dS)Nr�z is registered)r�r�r�rrr�assert_no_reader�s
zTestLoop.assert_no_readercGst�|||d�|j|<dSr-)rr�r�r�rrr�_add_writer�szTestLoop._add_writercCs0|j|d7<||jvr(|j|=dSdSdSr�)�remove_writer_countr�r�rrr�_remove_writer�s

zTestLoop._remove_writercGs|j|}dSr-)r�r�rrr�
assert_writer�s
zTestLoop.assert_writerc
Cszt|t�sDzt|���}Wn(tttfyBtd�|��d�Yn0z|j|}WntydYn0t	d�||���dS)NzInvalid file object: {!r}z.File descriptor {!r} is used by transport {!r})
�
isinstancer`�fileno�AttributeError�	TypeError�
ValueErrorrEr��KeyError�RuntimeError)rCr�Z	transportrrr�_ensure_fd_no_transport�s$
����z TestLoop._ensure_fd_no_transportcGs|�|�|j||g|�R�Sr-)r�r�r�rrr�
add_reader�s
zTestLoop.add_readercCs|�|�|�|�Sr-)r�r�r�rrr�
remove_reader�s
zTestLoop.remove_readercGs|�|�|j||g|�R�Sr-)r�r�r�rrr�
add_writer�s
zTestLoop.add_writercCs|�|�|�|�Sr-)r�r�r�rrr�
remove_writer�s
zTestLoop.remove_writercCst�t�|_t�t�|_dSr-)�collections�defaultdictr`r�r�rBrrrr��szTestLoop.reset_counterscs6t���|jD]}|j�|�}|�|�qg|_dSr-)rM�	_run_oncer�r�r�r�)rC�whenr�rRrrr��s


zTestLoop._run_once)r[cs(|j�|�t�j||g|�Rd|i�S)Nr[)r��appendrM�call_at)rCr�r�r[rFrRrrr��szTestLoop.call_atcCsdSr-r)rCZ
event_listrrr�_process_events�szTestLoop._process_eventscCsdSr-rrBrrr�_write_to_self�szTestLoop._write_to_self)N)rHrIrJr�r6r�r1r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rXrrrRrr�9s*
r�cKstjfddgi|��S)N�spec�__call__)rZMock)�kwargsrrrr��sr�c@seZdZdd�ZdS)�MockPatterncCstt�t|�|tj��Sr-)�bool�re�search�str�S�rC�otherrrr�__eq__�szMockPattern.__eq__N)rHrIrJr�rrrrr��s	r�c@seZdZdd�Zdd�ZdS)�MockInstanceOfcCs
||_dSr-)�_type)rCr�rrrr��szMockInstanceOf.__init__cCst||j�Sr-)r�r�r�rrrr��szMockInstanceOf.__eq__N)rHrIrJr�r�rrrrr��sr�cCs$t�|�}|dur td|f��|S)Nzunable to get the source of %r)rZ_get_function_sourcer�)�func�sourcerrr�get_function_source�s
r�c@sHeZdZedd��Zdd�dd�Zddd	�Zd
d�Zdd
�Zdd�Z	dS)�TestCasecCs�|jdur0|��s"|�|���n|jjdd�|��t��}|dur�z|��}Wnt	yfYn.0t
|tj�r�t
|j���}|D]}|��q�dS)NT)�wait)Z_default_executorZ	is_closedr0Zshutdown_default_executorror1rZmaybe_get_event_loop_policyZget_child_watcher�NotImplementedErrorr��asyncioZThreadedChildWatcher�listZ_threads�valuesr)r2ZpolicyZwatcherZthreads�threadrrr�
close_loop�s
zTestCase.close_loopT)�cleanupcCs t�d�|r|�|j|�dSr-)r�set_event_loopZ
addCleanupr�)rCr2r�rrrr�s
zTestCase.set_event_loopNcCst|�}|�|�|Sr-)r�r�)rCr3r2rrr�
new_test_loops
zTestCase.new_test_loopcCs|jt_dSr-)�_get_running_looprrBrrr�unpatch_get_running_loopsz!TestCase.unpatch_get_running_loopcCs tj|_dd�t_t��|_dS)NcSsdSr-rrrrrri$rjz TestCase.setUp.<locals>.<lambda>)rr�rZthreading_setup�_thread_cleanuprBrrr�setUp"s
zTestCase.setUpcCsB|��t�d�|�t��d�|��tj|j	�t�
�dS)N)NNN)r�rr�ZassertEqual�sys�exc_infoZ
doCleanupsrZthreading_cleanupr�Z
reap_childrenrBrrr�tearDown's
zTestCase.tearDown)N)
rHrIrJ�staticmethodr�r�r�r�r�r�rrrrr��s

r�c	cs<tj}z$t�tjd�dVWt�|�nt�|�0dS)Nr�)r�levelZsetLevel�loggingZCRITICAL)Z	old_levelrrr�disable_logger5s
r�cCs*t�tj�}||_||_||_d|j_|S)Ng)rZ	MagicMock�socket�protor��familyZ
gettimeoutr�)r�r�r�Zsockrrr�mock_nonblocking_socketCsr�)Nr�r��
contextlibr@r�rr�r�r�rvr�r}rmr6Zunittestr�rZhttp.serverrZwsgiref.simple_serverrrr"�ImportErrorrrrr	r
Zasyncio.logr�testrrr%r&ZSIGNED_CERTFILEZ
SIGNING_CAZPEERCERTr*r,r.r5Z
SHORT_TIMEOUTr;r>r?rKrYr]rrrrwrsryr{r|r��contextmanagerr�r�r�r�ZBaseSelectorr�Z
BaseEventLoopr�r�r�r�r�r�r�r�ZIPPROTO_TCPZSOCK_STREAMZAF_INETr�rrrr�<module>s�
�
	
#

%
8

�