Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/test_asyncio/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/test_asyncio/__pycache__/utils.cpython-39.pyc

a

��g	D�@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZddlmZddlmZmZzddlZWney�dZYn0ddlmZddlmZddlmZdd	lmZdd
lmZddlmZddl m!Z!d
d�Z"e"d�Z#e"d�Z$e"d�Z%e"d�Z&ddddddddddd�
Z'dd�Z(d d!�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�Z0Gd0d1�d1�Z1Gd2d3�d3e1e0�Z2d4d5�d6d7�Z3e4e	d8��rnGd9d:�d:e
j5e�Z6Gd;d<�d<e6e�Z7Gd=d>�d>e7�Z8Gd?d@�d@e1e8�Z9dAdB�Z:ej;dCdD��Z<ej;d4d5�dEdF��Z=ej;dGdd4dH�dIdJ��Z>dKdL�Z?GdMdN�dNej@�ZAGdOdP�dPejB�ZCdQdR�ZDGdSdT�dTeE�ZFGdUdV�dV�ZGdWdX�ZHGdYdZ�dZejI�ZIej;d[d\��ZJe	jKe	jLe	jMfd]d^�ZNdS)_zUtilities shared by tests.�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�3/usr/local/lib/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�timeout�deadlinerrr�	run_untilnsr<cCs|�|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�r2rrr�run_oncexsr?c@seZdZdd�Zdd�ZdS)�SilentWSGIRequestHandlercCst��Sr-)�io�StringIO��selfrrr�
get_stderr�sz#SilentWSGIRequestHandler.get_stderrcGsdSr-r)rD�format�argsrrr�log_message�sz$SilentWSGIRequestHandler.log_messageN)�__name__�
__module__�__qualname__rErHrrrrr@�sr@cs*eZdZejZ�fdd�Zdd�Z�ZS)�SilentWSGIServercs"t���\}}|�|j�||fSr-��super�get_request�
settimeout�request_timeout�rD�requestZclient_addr��	__class__rrrO�szSilentWSGIServer.get_requestcCsdSr-r�rDrS�client_addressrrr�handle_error�szSilentWSGIServer.handle_error)	rIrJrKr�LOOPBACK_TIMEOUTrQrOrX�
__classcell__rrrTrrL�srLc@seZdZdd�ZdS)�SSLWSGIServerMixincCsTt��}|�tt�|j|dd�}z|�|||�|��WntyNYn0dS)NT)Zserver_side)	r"r#r$r%r&Zwrap_socketZRequestHandlerClassr1�OSError)rDrSrW�context�ssockrrr�finish_request�sz!SSLWSGIServerMixin.finish_requestN)rIrJrKr_rrrrr[�sr[c@seZdZdS)�
SSLWSGIServerN�rIrJrKrrrrr`�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)rgZstart_response�statusZheadersr>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�	threading�Thread�start�shutdownZserver_closer)rprb�
server_cls�server_ssl_clsrkZserver_classZ
server_threadr)rlr2r�_run_test_server�s$


�
�rw�AF_UNIXc@seZdZdd�ZdS)�UnixHTTPServercCstj�|�d|_d|_dS)N�	127.0.0.1�P)�socketserver�UnixStreamServer�server_bindZserver_nameZserver_portrCrrrr~�szUnixHTTPServer.server_bindN)rIrJrKr~rrrrry�srycs*eZdZejZdd�Z�fdd�Z�ZS)�UnixWSGIServercCst�|�|��dSr-)ryr~Z
setup_environrCrrrr~�s
zUnixWSGIServer.server_bindcs"t���\}}|�|j�|dfS)N)rz�rMrRrTrrrO�szUnixWSGIServer.get_request)	rIrJrKrrYrQr~rOrZrrrTrr�src@seZdZdd�ZdS)�SilentUnixWSGIServercCsdSr-rrVrrrrX�sz!SilentUnixWSGIServer.handle_errorN)rIrJrKrXrrrrr��sr�c@seZdZdS)�UnixSSLWSGIServerNrarrrrr��sr�cCs2t���}|jWd�S1s$0YdSr-)�tempfile�NamedTemporaryFile�name)�filerrr�gen_unix_socket_path�s
r�ccs\t�}z,|VWzt�|�WqXty0YqX0n$zt�|�WntyTYn00dSr-)r�r�unlinkr\)rrrr�unix_socket_paths�r�ccs@t��&}t||ttd�EdHWd�n1s20YdS�N)rprbrurv)r�rwr�r�)rbrrrr�run_test_unix_servers
�r�rz��host�portrbccst||f|ttd�EdHdSr�)rwrLr`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-��keysrCrrr�__init__'szTestSelector.__init__NcCst�|d||�}||j|<|S)Nr)�	selectors�SelectorKeyr�)rD�fileobjrri�keyrrr�register*s
zTestSelector.registercCs|j�|�Sr-)r��pop)rDr�rrr�
unregister/szTestSelector.unregistercCsgSr-r)rDr:rrr�select2szTestSelector.selectcCs|jSr-r�rCrrr�get_map5szTestSelector.get_map)N)rIrJrKr�r�r�r�r�rrrrr�%s

r�cs�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"�Zd#d$�Z�fd%d&�Zdd'��fd(d)�
Zd*d+�Zd,d-�Z�ZS)/�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.
    Ncsvt���|dur"dd�}d|_nd|_|�|_t|j�d|_d|_g|_t�|_	i|_
i|_|��t
��|_dS)Ncss
dVdSr-rrrrrr3PszTestLoop.__init__.<locals>.genFTrg��&�.>)rNr��_check_on_close�_gen�next�_timeZ_clock_resolution�_timersr��	_selector�readers�writers�reset_counters�weakref�WeakValueDictionary�_transports)rDr3rTrrr�Ls

zTestLoop.__init__cCs|jSr-�r�rCrrrr6csz
TestLoop.timecCs|r|j|7_dS)zMove test time forward.Nr�)rD�advancerrr�advance_timefszTestLoop.advance_timecs@t���|jr<z|j�d�Wnty2Yn
0td��dS)NrzTime generator is not finished)rNr1r�r��send�
StopIteration�AssertionErrorrCrTrrr1ks
zTestLoop.closecGst�|||d�|j|<dSr-)r�Handler��rD�fd�callbackrGrrr�_add_readeruszTestLoop._add_readercCs0|j|d7<||jvr(|j|=dSdSdS�N�TF)�remove_reader_countr��rDr�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��	_callback�_args�rDr�r�rG�handlerrr�
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^||jvsJd�|���|j|}|j|ks>Jd�|j|���|j|ksZJd�|j|���dS)Nzfd {} is not registeredz{!r} != {!r})r�rFr�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})
�
isinstancerc�fileno�AttributeError�	TypeError�
ValueErrorrFr��KeyError�RuntimeError)rDr�Z	transportrrr�_ensure_fd_no_transport�s$
����z TestLoop._ensure_fd_no_transportcGs|�|�|j||g|�R�S)zAdd a reader callback.)r�r�r�rrr�
add_reader�s
zTestLoop.add_readercCs|�|�|�|�S)zRemove a reader callback.)r�r�r�rrr�
remove_reader�s
zTestLoop.remove_readercGs|�|�|j||g|�R�S)zAdd a writer callback..)r�r�r�rrr�
add_writer�s
zTestLoop.add_writercCs|�|�|�|�S)zRemove a writer callback.)r�r�r�rrr�
remove_writer�s
zTestLoop.remove_writercCst�t�|_t�t�|_dSr-)�collections�defaultdictrcr�r�rCrrrr��szTestLoop.reset_counterscs6t���|jD]}|j�|�}|�|�qg|_dSr-)rN�	_run_oncer�r�r�r�)rD�whenr�rTrrr��s


zTestLoop._run_once)r]cs(|j�|�t�j||g|�Rd|i�S)Nr])r��appendrN�call_at)rDr�r�r]rGrTrrr��szTestLoop.call_atcCsdSr-r)rDZ
event_listrrr�_process_events�szTestLoop._process_eventscCsdSr-rrCrrr�_write_to_self�szTestLoop._write_to_self)N)rIrJrK�__doc__r�r6r�r1r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rZrrrTrr�9s,
r�cKstjfddgi|��S)N�spec�__call__)rZMock)�kwargsrrrr��sr�c@seZdZdZdd�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'))
    cCstt�t|�|tj��Sr-)�bool�re�search�str�S�rD�otherrrr�__eq__�szMockPattern.__eq__N)rIrJrKr�r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)�MockInstanceOfcCs
||_dSr-)�_type)rDr�rrrr��szMockInstanceOf.__init__cCst||j�Sr-)r�r�r�rrrr��szMockInstanceOf.__eq__N)rIrJrKr�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_executorrtr1rZmaybe_get_event_loop_policyZget_child_watcher�NotImplementedErrorr��asyncioZThreadedChildWatcher�listZ_threads�valuesr)r2ZpolicyZwatcher�threads�threadrrr�
close_loop�s
zTestCase.close_loopT)�cleanupcCs,|dusJ�t�d�|r(|�|j|�dSr-)r�set_event_loopZ
addCleanupr�)rDr2r�rrrr�s
zTestCase.set_event_loopNcCst|�}|�|�|Sr-)r�r�)rDr3r2rrr�
new_test_loops
zTestCase.new_test_loopcCs|jt_dSr-)�_get_running_looprrCrrr�unpatch_get_running_loopsz!TestCase.unpatch_get_running_loopcCs tj|_dd�t_t��|_dS)NcSsdSr-rrrrrrm$rnz TestCase.setUp.<locals>.<lambda>)rrrZthreading_setup�_thread_cleanuprCrrr�setUp"s
zTestCase.setUpcCsB|��t�d�|�t��d�|��tj|j	�t�
�dS)N)NNN)rrr�ZassertEqual�sys�exc_infoZ
doCleanupsrZthreading_cleanupr�
reap_childrenrCrrr�tearDown's
zTestCase.tearDown)N)
rIrJrK�staticmethodr�r�rrrrrrrrr��s

r�c	cs<tj}z$t�tjd�dVWt�|�nt�|�0dS)zrContext manager to disable asyncio logger.

    For example, it can be used to ignore warnings in debug mode.
    r�N)r�level�setLevel�logging�CRITICAL)Z	old_levelrrr�disable_logger5s
rcCs*t�tj�}||_||_||_d|j_|S)z'Create a mock of a non-blocking socket.g)rZ	MagicMock�socket�protor��family�
gettimeoutr�)rr�r�sockrrr�mock_nonblocking_socketCsr)Or�r�r��
contextlibrArrr�r�rr|rr�rqr6Zunittestr�rZhttp.serverrZwsgiref.simple_serverrrr"�ImportErrorrrrr	r
Zasyncio.logr�testrrr%r&ZSIGNED_CERTFILEZ
SIGNING_CAZPEERCERTr*r,r.r5Z
SHORT_TIMEOUTr<r?r@rLr[r`rwrr}ryrr�r�r��contextmanagerr�r�r�r��BaseSelectorr�Z
BaseEventLoopr�r�r�r�r�r�r�r�IPPROTO_TCP�SOCK_STREAM�AF_INETrrrrr�<module>s�
�
	
#

%
8

�

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists