File "test_utils.cpython-34.pyc"

Full Path: /home/attunedd/public_html/byp/izo/con7ext_sym404/rintoar.txt/opt/alt/python34/lib64/python3.4/asyncio/__pycache__/test_utils.cpython-34.pyc
File size: 15.96 KB
MIME-type: text/x-bytecode.python
Charset: 8 bit


j f2@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddl
mZddlmZddlmZmZyddlZWnek
rdZYnXddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlm Z e	j!dkrddl"m#Z#nddlm#Z#ddZ$ddZ%dddZ&ddZ'GdddeZ(GdddeZ)GdddZ*Gd d!d!e*e)Z+d"d#d$d%Z,e-ed&rGd'd(d(ej.eZ/Gd)d*d*e/eZ0Gd+d,d,e0Z1Gd-d.d.e*e1Z2d/d0Z3ej4d1d2Z5ej4d"d#d3d4Z6nej4d5d6d7dd"d#d8d9Z7d:d;Z8Gd<d=d=ej9Z:Gd>d?d?ej;Z<d@dAZ=GdBdCdCe>Z?dDdEZ@GdFdGdGe
jAZAej4dHdIZBejCejDejEdJdKZFdLdMZGdS)NzUtilities shared by tests.N)mock)
HTTPServer)WSGIRequestHandler
WSGIServer)base_events)compat)events)futures)	selectors)tasks)	coroutine)loggerwin32)
socketpaircCs$tdkrdStjtjSdS)N)sslZ
SSLContextZPROTOCOL_SSLv23rr7/opt/alt/python34/lib64/python3.4/asyncio/test_utils.pydummy_ssl_context*src
CsVtdd}|}|j|}d|_z|j|Wd|jXdS)NcSsdS)Nrrrrronce2szrun_briefly.<locals>.onceF)r
Zcreate_taskZ_log_destroy_pendingrun_until_completeclose)looprgentrrrrun_briefly1s		rcCsztj|}xc|su|dk	rV|tj}|dkrVtjqVn|jtjdd|qWdS)NrgMbP?r)timer
TimeoutErrorrrZsleep)rZpredtimeoutZdeadlinerrr	run_until@sr cCs|j|j|jdS)zLegacy 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_soonstopZrun_forever)rrrrrun_onceJsr"c@s(eZdZddZddZdS)SilentWSGIRequestHandlercCs
tjS)N)ioStringIO)selfrrr
get_stderrWsz#SilentWSGIRequestHandler.get_stderrcGsdS)Nr)r&formatargsrrrlog_messageZsz$SilentWSGIRequestHandler.log_messageN)__name__
__module____qualname__r'r*rrrrr#Usr#cs4eZdZdZfddZddZS)SilentWSGIServercs/tj\}}|j|j||fS)N)superget_request
settimeoutrequest_timeout)r&requestclient_addr)	__class__rrr1bszSilentWSGIServer.get_requestcCsdS)Nr)r&r4client_addressrrrhandle_errorgszSilentWSGIServer.handle_error)r+r,r-r3r1r8rr)r6rr.^sr.c@seZdZddZdS)SSLWSGIServerMixincCstjjtjjtdd}tjj|s`tjjtjjtjdd}ntjj|d}tjj|d}tj|d|d|d	d
}y!|j||||j	Wnt
k
rYnXdS)Nz..ZtestsZtestZtest_asynciozssl_key.pemzssl_cert.pemkeyfilecertfileZserver_sideT)ospathjoindirname__file__isdirrZwrap_socketZRequestHandlerClassrOSError)r&r4r7herer:r;Zssockrrrfinish_requestms$	
z!SSLWSGIServerMixin.finish_requestN)r+r,r-rDrrrrr9ksr9c@seZdZdS)
SSLWSGIServerN)r+r,r-rrrrrEsrEuse_sslFc
#sdd}|r|n|}||tj|j_tjdfdd}|jz	VWdjj|j	XdS)NcSs#d}dg}|||dgS)Nz200 OKContent-type
text/plainsTest message)rGrHr)environZstart_responseZstatusZheadersrrrapps	
z_run_test_server.<locals>.apptargetcsjddS)NZ
poll_intervalg?)Z
serve_foreverr)httpdrr<lambda>sz"_run_test_server.<locals>.<lambda>)
r#Zset_appZserver_addressaddress	threadingZThreadstartZshutdownZserver_closer>)rNrF
server_clsserver_ssl_clsrJZserver_classZ
server_threadr)rLr_run_test_servers
	
	

rSZAF_UNIXc@seZdZddZdS)UnixHTTPServercCs&tjj|d|_d|_dS)Nz	127.0.0.1P)socketserverUnixStreamServerserver_bindZserver_nameZserver_port)r&rrrrXs	zUnixHTTPServer.server_bindN)r+r,r-rXrrrrrTsrTcs4eZdZdZddZfddZS)UnixWSGIServerr/cCstj||jdS)N)rTrXZ
setup_environ)r&rrrrXs
zUnixWSGIServer.server_bindcs/tj\}}|j|j|dfS)N	127.0.0.1)rZr[)r0r1r2r3)r&r4r5)r6rrr1szUnixWSGIServer.get_request)r+r,r-r3rXr1rr)r6rrYsrYc@seZdZddZdS)SilentUnixWSGIServercCsdS)Nr)r&r4r7rrrr8sz!SilentUnixWSGIServer.handle_errorN)r+r,r-r8rrrrr\sr\c@seZdZdS)UnixSSLWSGIServerN)r+r,r-rrrrr]sr]cCs tj}|jSWdQXdS)N)tempfileZNamedTemporaryFilename)filerrrgen_unix_socket_pathsraccs@t}z	|VWdytj|Wntk
r:YnXXdS)N)rar<unlinkrB)r=rrrunix_socket_paths		
rcccs:t+}td|d|dtdtDdHWdQXdS)NrNrFrQrR)rcrSr\r])rFr=rrrrun_test_unix_serversrdhostz	127.0.0.1portc	cs.td||fd|dtdtDdHdS)NrNrFrQrR)rSr.rE)rerfrFrrrrun_test_serversrgcCsqi}xKt|D]=}|jdr=|jdr=qntdd||<qWtd|f|j|S)N__return_valueZTestProtocol)dir
startswithendswithMockCallbacktype	__bases__)baseZdctr_rrrmake_test_protocolsrqc@sOeZdZddZdddZddZdd	Zd
dZdS)TestSelectorcCs
i|_dS)N)keys)r&rrr__init__szTestSelector.__init__NcCs)tj|d||}||j|<|S)Nr)rZSelectorKeyrs)r&fileobjr	datakeyrrrregisters
zTestSelector.registercCs|jj|S)N)rspop)r&rurrr
unregisterszTestSelector.unregistercCsgS)Nr)r&rrrrselectszTestSelector.selectcCs|jS)N)rs)r&rrrget_mapszTestSelector.get_map)r+r,r-rtrxrzr{r|rrrrrrs
rrcseZdZdZdfddZddZddZfd	d
ZddZd
dZ	ddZ
ddZddZddZ
ddZfddZfddZddZdd ZS)!TestLoopaLoop 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.
    Ncstj|dkr1dd}d|_n	d|_||_t|jd|_d|_g|_t|_	i|_
i|_|jdS)Ncss	dVdS)NrrrrrrszTestLoop.__init__.<locals>.genFTrg&.>)
r0rt_check_on_close_gennext_timeZ_clock_resolution_timersrrZ	_selectorreaderswritersreset_counters)r&r)r6rrrts
	
					zTestLoop.__init__cCs|jS)N)r)r&rrrr/sz
TestLoop.timecCs|r|j|7_ndS)zMove test time forward.N)r)r&advancerrradvance_time2szTestLoop.advance_timecsRtj|jrNy|jjdWntk
r>YqNXtdndS)NrzTime generator is not finished)r0rr~rsend
StopIterationAssertionError)r&)r6rrr7s
	
zTestLoop.closecGs tj||||j|<dS)N)r	Handler)r&fdcallbackr)rrr
add_readerAszTestLoop.add_readercCs6|j|d7<||jkr.|j|=dSdSdS)NrTF)remove_reader_countr)r&rrrr
remove_readerDs

zTestLoop.remove_readercGs||jks$tdj||j|}|j|ks[tdj|j||j|kstdj|j|dS)Nzfd {} is not registeredz{!r} != {!r})rrr(	_callback_args)r&rrr)handlerrr
assert_readerLs$
zTestLoop.assert_readercGs tj||||j|<dS)N)r	rr)r&rrr)rrr
add_writerTszTestLoop.add_writercCs6|j|d7<||jkr.|j|=dSdSdS)NrTF)remove_writer_countr)r&rrrr
remove_writerWs

zTestLoop.remove_writercGs||jks$tdj||j|}|j|ks[tdj|j||j|kstdj|j|dS)Nzfd {} is not registeredz{!r} != {!r})rrr(rr)r&rrr)rrrr
assert_writer_s$
zTestLoop.assert_writercCs(tjt|_tjt|_dS)N)collectionsdefaultdictintrr)r&rrrrgszTestLoop.reset_counterscsMtjx0|jD]%}|jj|}|j|qWg|_dS)N)r0	_run_oncerrrr)r&whenr)r6rrrks

zTestLoop._run_oncecs&|jj|tj|||S)N)rappendr0call_at)r&rrr))r6rrrrszTestLoop.call_atcCsdS)Nr)r&Z
event_listrrr_process_eventsvszTestLoop._process_eventscCsdS)Nr)r&rrr_write_to_selfyszTestLoop._write_to_self)r+r,r-__doc__rtrrrrrrrrrrrrrrrr)r6rr}s 
r}cKstjddg|S)Nspec__call__)rZMock)kwargsrrrrm}srmc@s"eZdZdZddZdS)MockPatternzA 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||tjS)N)boolresearchstrS)r&otherrrr__eq__szMockPattern.__eq__N)r+r,r-rrrrrrrsrcCs5tj|}|dkr1td|fn|S)Nzunable to get the source of %r)r	Z_get_function_source
ValueError)funcsourcerrrget_function_sourcesrc@sUeZdZddddZdddZdd	ZejsQd
dZndS)TestCasecleanupTcCs<|dk	sttjd|r8|j|jndS)N)rr	set_event_loopZ
addCleanupr)r&rrrrrrs
zTestCase.set_event_loopNcCst|}|j||S)N)r}r)r&rrrrr
new_test_loops
zTestCase.new_test_loopcCs'tjd|jtjddS)N)NNN)r	rZassertEqualsysexc_info)r&rrrtearDowns
zTestCase.tearDowncOsGddd}|S)Nc@s(eZdZddZddZdS)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-rrrrrrEmptyCMsrr)r&r)rrrrrsubTestszTestCase.subTest)	r+r,r-rrrrZPY34rrrrrrs
	rccs;tj}ztjtjddVWdtj|XdS)zrContext manager to disable asyncio logger.

    For example, it can be used to ignore warnings in debug mode.
    rN)rlevelZsetLevelloggingZCRITICAL)Z	old_levelrrrdisable_loggers
		rcCs=tjtj}||_||_||_d|j_|S)z'Create a mock of a non-blocking socket.g)rZ	MagicMocksocketprotornfamilyZ
gettimeoutri)rrnrZsockrrrmock_nonblocking_sockets			rcCstjdddS)Nz'asyncio.sslproto._is_sslproto_availableriF)rZpatchrrrrforce_legacy_ssl_supportsr)Hrr
contextlibr$rr<rrrVrr^rOrZunittestrZhttp.serverrZwsgiref.simple_serverrrrImportErrorr[rrr	r
rrZ
coroutinesr
logrplatformZ
windows_utilsrrrr r"r#r.r9rErShasattrrWrTrYr\r]racontextmanagerrcrdrgrqZBaseSelectorrrZ
BaseEventLoopr}rmrrrrrZIPPROTO_TCPZSOCK_STREAMZAF_INETrrrrrr<module>s|

	
		
v