HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3.5/asyncio/__pycache__/test_utils.cpython-35.pyc


��j`�7�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddl
mZddlmZddlmZmZyddlZWnek
rdZYnXddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddl m!Z!e	j"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&�r
Gd'd(�d(ej/e�Z0Gd)d*�d*e0e�Z1Gd+d,�d,e1�Z2Gd-d.�d.e+e2�Z3d/d0�Z4ej5d1d2��Z6ej5d"d#d3d4��Z7ej5d5d6d7dd"d#d8d9��Z8d:d;�Z9Gd<d=�d=ej:�Z;Gd>d?�d?ej<�Z=d@dA�Z>GdBdC�dCe?�Z@dDdE�ZAGdFdG�dGe
jB�ZBej5dHdI��ZCejDejEejFdJdK�ZGdLdM�ZHdS)NzUtilities shared by tests.�N)�mock)�
HTTPServer)�WSGIRequestHandler�
WSGIServer�)�base_events)�compat)�events)�futures)�	selectors)�tasks)�	coroutine)�loggerZwin32)�
socketpaircCs$tdkrdStjtj�SdS)N)�sslZ
SSLContextZPROTOCOL_SSLv23�rr�(/usr/lib/python3.5/asyncio/test_utils.py�dummy_ssl_context,src
CsVtdd��}|�}|j|�}d|_z|j|�Wd|j�XdS)NcSsdS)Nrrrrr�once4szrun_briefly.<locals>.onceF)r
Zcreate_taskZ_log_destroy_pending�run_until_complete�close)�loopr�gen�trrr�run_briefly3s		r�cCsttj�|}x]|�so|dk	rP|tj�}|dkrPtj��|jtjdd|��qWdS)Nrg����MbP?r)�timer
�TimeoutErrorrrZsleep)rZpred�timeoutZdeadlinerrr�	run_untilBsrcCs|j|j�|j�dS)z�Legacy API to run once through the event loop.

    This is the recommended pattern for test code.  It will poll the
    selector once and run all callbacks scheduled in response to I/O
    events.
    N)Z	call_soon�stopZrun_forever)rrrr�run_onceLsr!c@s(eZdZdd�Zdd�ZdS)�SilentWSGIRequestHandlercCs
tj�S)N)�io�StringIO)�selfrrr�
get_stderrYsz#SilentWSGIRequestHandler.get_stderrcGsdS)Nr)r%�format�argsrrr�log_message\sz$SilentWSGIRequestHandler.log_messageN)�__name__�
__module__�__qualname__r&r)rrrrr"Ws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__rrr0dszSilentWSGIServer.get_requestcCsdS)Nr)r%r3�client_addressrrr�handle_erroriszSilentWSGIServer.handle_error)r*r+r,r2r0r7rr)r5rr-`sr-c@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..ZtestsZtestZtest_asynciozssl_key.pemzssl_cert.pem�keyfile�certfileZserver_sideT)�os�path�join�dirname�__file__�isdirrZwrap_socketZRequestHandlerClassr�OSError)r%r3r6�herer9r:Zssockrrr�finish_requestos$	
z!SSLWSGIServerMixin.finish_requestN)r*r+r,rCrrrrr8msr8c@seZdZdS)�
SSLWSGIServerN)r*r+r,rrrrrD�srD�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)rFrGr)�environZstart_responseZstatusZheadersrrr�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�	threadingZThread�startZshutdownZserver_closer=)rMrE�
server_cls�server_ssl_clsrIZserver_classZ
server_threadr)rKr�_run_test_server�s
	
	

rRZAF_UNIXc@seZdZdd�ZdS)�UnixHTTPServercCs&tjj|�d|_d|_dS)Nz	127.0.0.1�P)�socketserver�UnixStreamServer�server_bindZserver_nameZserver_port)r%rrrrW�s	zUnixHTTPServer.server_bindN)r*r+r,rWrrrrrS�srScs4eZdZdZdd�Z�fdd�Z�S)�UnixWSGIServerr.cCstj|�|j�dS)N)rSrWZ
setup_environ)r%rrrrW�s
zUnixWSGIServer.server_bindcs/t�j�\}}|j|j�|dfS)N�	127.0.0.1�)rYrZ)r/r0r1r2)r%r3r4)r5rrr0�szUnixWSGIServer.get_request)r*r+r,r2rWr0rr)r5rrX�srXc@seZdZdd�ZdS)�SilentUnixWSGIServercCsdS)Nr)r%r3r6rrrr7�sz!SilentUnixWSGIServer.handle_errorN)r*r+r,r7rrrrr[�sr[c@seZdZdS)�UnixSSLWSGIServerN)r*r+r,rrrrr\�sr\c	Cs!tj��}|jSWdQRXdS)N)�tempfileZNamedTemporaryFile�name)�filerrr�gen_unix_socket_path�sr`ccs@t�}z	|VWdytj|�Wntk
r:YnXXdS)N)r`r;�unlinkrA)r<rrr�unix_socket_path�s		
rbccs;t��+}td|d|dtdt�EdHWdQRXdS)NrMrErPrQ)rbrRr[r\)rEr<rrr�run_test_unix_server�src�hostz	127.0.0.1�portc	cs.td||fd|dtdt�EdHdS)NrMrErPrQ)rRr-rD)rdrerErrr�run_test_server�srfcCsni}xHt|�D]:}|jd�r:|jd�r:qtdd�||<qWtd|f|j|��S)N�__�return_valueZTestProtocol)�dir�
startswith�endswith�MockCallback�type�	__bases__)�baseZdctr^rrr�make_test_protocol�srpc@sOeZdZdd�Zddd�Zdd�Zdd	�Zd
d�ZdS)�TestSelectorcCs
i|_dS)N)�keys)r%rrr�__init__�szTestSelector.__init__NcCs)tj|d||�}||j|<|S)Nr)rZSelectorKeyrr)r%�fileobjr	�data�keyrrr�register�s
zTestSelector.registercCs|jj|�S)N)rr�pop)r%rtrrr�
unregister�szTestSelector.unregistercCsgS)Nr)r%rrrr�selectszTestSelector.selectcCs|jS)N)rr)r%rrr�get_mapszTestSelector.get_map)r*r+r,rsrwryrzr{rrrrrq�s
rqcs!eZdZdZd�fdd�Zdd�Zdd�Z�fd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Z�fd#d$�Z�fd%d&�Zd'd(�Zd)d*�Z�S)+�TestLoopa�Loop for unittests.

    It manages self time directly.
    If something scheduled to be executed later then
    on next loop iteration after all ready handlers done
    generator passed to __init__ is calling.

    Generator should be like this:

        def gen():
            ...
            when = yield ...
            ... = yield time_advance

    Value returned by yield is absolute time of next scheduled handler.
    Value passed to yield is time advance to move loop's time forward.
    Ncs�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��&�.>)r/rs�_check_on_close�_gen�next�_timeZ_clock_resolution�_timersrqZ	_selector�readers�writers�reset_counters�weakref�WeakValueDictionary�_transports)r%r)r5rrrss
	
					
zTestLoop.__init__cCs|jS)N)r�)r%rrrr3sz
TestLoop.timecCs|r|j|7_dS)zMove test time forward.N)r�)r%�advancerrr�advance_time6szTestLoop.advance_timecsOt�j�|jrKy|jjd�Wntk
r>Yn
Xtd��dS)NrzTime generator is not finished)r/rr}r~�send�
StopIteration�AssertionError)r%)r5rrr;s
	
zTestLoop.closecGs tj|||�|j|<dS)N)r	�Handler�)r%�fd�callbackr(rrr�_add_readerEszTestLoop._add_readercCs6|j|d7<||jkr.|j|=dSdSdS)NrTF)�remove_reader_countr�)r%r�rrr�_remove_readerHs

zTestLoop._remove_readercGs�||jks$tdj|���|j|}|j|ks[tdj|j|���|j|ks�tdj|j|���dS)Nzfd {} is not registeredz{!r} != {!r})r�r�r'�	_callback�_args)r%r�r�r(�handlerrr�
assert_readerPs$
zTestLoop.assert_readercGs tj|||�|j|<dS)N)r	r�r�)r%r�r�r(rrr�_add_writerXszTestLoop._add_writercCs6|j|d7<||jkr.|j|=dSdSdS)NrTF)�remove_writer_countr�)r%r�rrr�_remove_writer[s

zTestLoop._remove_writercGs�||jks$tdj|���|j|}|j|ks[tdj|j|���|j|ks�tdj|j|���dS)Nzfd {} is not registeredz{!r} != {!r})r�r�r'r�r�)r%r�r�r(r�rrr�
assert_writercs$
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_transportks
z TestLoop._ensure_fd_no_transportcGs |j|�|j|||�S)zAdd a reader callback.)r�r�)r%r�r�r(rrr�
add_readerus
zTestLoop.add_readercCs|j|�|j|�S)zRemove a reader callback.)r�r�)r%r�rrr�
remove_readerzs
zTestLoop.remove_readercGs |j|�|j|||�S)zAdd a writer callback..)r�r�)r%r�r�r(rrr�
add_writers
zTestLoop.add_writercCs|j|�|j|�S)zRemove a writer callback.)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)r/�	_run_oncer�r~r�r�)r%�whenr�)r5rrr��s

zTestLoop._run_oncecs&|jj|�t�j|||�S)N)r��appendr/�call_at)r%r�r�r()r5rrr��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+r,�__doc__rsrr�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr)r5rr|	s*

r|cKstjddg|�S)N�spec�__call__)rZMock)�kwargsrrrrl�srlc@s"eZdZdZdd�ZdS)�MockPatternz�A regex based str with a fuzzy __eq__.

    Use this helper with 'mock.assert_called_with', or anywhere
    where a regex comparison between strings is needed.

    For instance:
       mock_call.assert_called_with(MockPattern('spam.*ham'))
    cCs"ttjt|�|tj��S)N)�bool�re�search�str�S)r%�otherrrr�__eq__�szMockPattern.__eq__N)r*r+r,r�r�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@s^eZdZdddd�Zddd�Zdd	�Zd
d�ZejsZdd
�Z	dS)�TestCase�cleanupTcCs9|dk	st�tjd�|r5|j|j�dS)N)r�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_loopcCstj|_dd�t_dS)NcSsdS)NrrrrrrL�sz TestCase.setUp.<locals>.<lambda>)r	�_get_running_loop)r%rrr�setUp�szTestCase.setUpcCs3|jt_tjd�|jtj�d�dS)N)NNN)r�r	r�ZassertEqual�sys�exc_info)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+r,r�r�rrrr�EmptyCM�sr�r)r%r(r�r�rrr�subTest�szTestCase.subTest)
r*r+r,r�r�r�r�rZPY34r�rrrrr��s		r�ccs;tj}ztjtjd�dVWdtj|�XdS)zrContext manager to disable asyncio logger.

    For example, it can be used to ignore warnings in debug mode.
    rN)r�levelZsetLevel�loggingZCRITICAL)Z	old_levelrrr�disable_logger�s
		r�cCs=tjtj�}||_||_||_d|j_|S)z'Create a mock of a non-blocking socket.g)rZ	MagicMock�socket�protorm�familyZ
gettimeoutrh)r�rmr�Zsockrrr�mock_nonblocking_socket�s			r�cCstjddd�S)Nz'asyncio.sslproto._is_sslproto_availablerhF)rZpatchrrrr�force_legacy_ssl_support�sr�)Ir�r��
contextlibr#r�r;r�r�rUr�r]rNrZunittestr�rZhttp.serverrZwsgiref.simple_serverrrr�ImportErrorrZrrr	r
rrZ
coroutinesr
�logr�platformZ
windows_utilsrrrrr!r"r-r8rDrR�hasattrrVrSrXr[r\r`�contextmanagerrbrcrfrpZBaseSelectorrqZ
BaseEventLoopr|rlr�r�r�r�r�ZIPPROTO_TCPZSOCK_STREAMZAF_INETr�r�rrrr�<module>s~

	
		
�
%