a  zeQ@sdZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z z ddl Z Wne yndZ Yn0ddlZddlZddlZddlZddlZddlZddlmZddlZejdkrddlZddlZddlmZddlmZddlmZddlmZdd lmZdd lm Z dd l!m"Z"dd l!m#Z#m$Z$m%Z%d dZ&ddZ'ddZ(GdddZ)Gdddej*Z+Gddde+Z,Gdddej-Z.Gdddej*Z/Gdddej0Z1Gdd d ej2Z3Gd!d"d"Z4Gd#d$d$Z5ejdkrGd%d&d&e4ej6Z7Gd'd(d(e4e5ej6Z8nddl9Z9Gd)d*d*e4Z:e;e9d+rTGd,d-d-e:e5ej6ZGd4d&d&e:e5ej6Z7d5d6Z?Gd7d8d8ej6Z@Gd9d:d:ej6ZAGd;d<dd>ej6ZCGd?d@d@ZDGdAdBdBeDej6ZEz ddlFZFWne y@Yn0GdCdDdDeDej6ZGGdEdFdFej6ZHGdGdHdHej6ZIeJdIkreKdS)JzTests for events.py.N)mockwin32) coroutines)events)proactor_events)selector_events)utils)support) socket_helper) ALWAYS_EQLARGESTSMALLESTcCstddSN)asyncioset_event_loop_policyrrQ/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_asyncio/test_events.pytearDownModule'srcCsFtjdrdStjdkrdStd}ttt|d}|dkS)z4Return True if the platform is Mac OS 10.4 or older.ZaixTdarwinFr.) )sysplatform startswithZmac_vertuplemapintsplit)versionrrrbroken_unix_getsockname+s   r cCs&dd}t}t|||S)NcsdSNhellorrrrrdoit7sz8_test_get_event_loop_new_process__sub_proc..doit)rnew_event_loopset_event_looprun_until_complete)r#looprrr*_test_get_event_loop_new_process__sub_proc6s r(c@s,eZdZddZddZddZddZd S) CoroLikecCsdSrr)selfvrrrsend@sz CoroLike.sendcGsdSrrr*excrrrthrowCszCoroLike.throwcCsdSrrr*rrrcloseFszCoroLike.closecCsdSrrr0rrr __await__IszCoroLike.__await__N)__name__ __module__ __qualname__r,r/r1r2rrrrr)?sr)c@s>eZdZdZdZd ddZddZddZdd Zd d Z dS) MyBaseProtoNcCs2d|_d|_d|_|dur.||_||_dSNINITIALr) transportstatenbytes create_future connecteddoner*r'rrr__init__Qs  zMyBaseProto.__init__cCs6||_|jdksJ|jd|_|jr2|jddSNr8 CONNECTEDr9r:r= set_resultr*r9rrrconnection_madeYs zMyBaseProto.connection_madecCs*|jdksJ|j|jt|7_dSNrBr:r;lenr*datarrr data_received`szMyBaseProto.data_receivedcCs|jdksJ|jd|_dS)NrBEOFr:r0rrr eof_receiveddszMyBaseProto.eof_receivedcCs0|jdvsJ|jd|_|jr,|jddS)N)rBrMCLOSEDr:r>rDr-rrrconnection_losthszMyBaseProto.connection_lost)N) r3r4r5r=r>r@rFrLrOrRrrrrr6Ms r6cseZdZfddZZS)MyProtocst||ddS)Ns%GET / HTTP/1.0 Host: example.com )superrFwriterE __class__rrrFps zMyProto.connection_mader3r4r5rF __classcell__rrrVrrSosrSc@s:eZdZdZd ddZddZddZdd Zd d ZdS) MyDatagramProtoNcCs"d|_d|_|dur||_dSr7)r:r;r<r>r?rrrr@xszMyDatagramProto.__init__cCs$||_|jdksJ|jd|_dS)Nr8 INITIALIZEDr9r:rErrrrF~szMyDatagramProto.connection_madecCs*|jdksJ|j|jt|7_dSNr[rHr*rKaddrrrrdatagram_receivedsz!MyDatagramProto.datagram_receivedcCs|jdksJ|jdSr]rNr-rrrerror_receivedszMyDatagramProto.error_receivedcCs0|jdksJ|jd|_|jr,|jddS)Nr[rPrQr-rrrrRszMyDatagramProto.connection_lost)N) r3r4r5r>r@rFr`rarRrrrrrZus  rZc@s:eZdZdZd ddZddZddZdd Zd d ZdS) MyReadPipeProtoNcCs*dg|_d|_d|_|dur&||_dSr7)r:r;r9r<r>r?rrrr@s zMyReadPipeProto.__init__cCs,||_|jdgksJ|j|jddSrA)r9r:appendrErrrrFszMyReadPipeProto.connection_madecCs.|jddgksJ|j|jt|7_dSrArHrJrrrrLszMyReadPipeProto.data_receivedcCs(|jddgksJ|j|jddS)Nr8rBrM)r:rcr0rrrrOszMyReadPipeProto.eof_receivedcCsPd|jvr|jd|jgdks.J|j|jd|jrL|jddS)NrM)r8rBrMrP)r:rcr>rDr-rrrrRs    zMyReadPipeProto.connection_lost)N) r3r4r5r>r@rFrLrOrRrrrrrbs  rbc@s*eZdZdZdddZddZddZdS) MyWritePipeProtoNcCs"d|_d|_|dur||_dS)Nr8)r:r9r<r>r?rrrr@szMyWritePipeProto.__init__cCs$||_|jdksJ|jd|_dSrAr\rErrrrFsz MyWritePipeProto.connection_madecCs0|jdksJ|jd|_|jr,|jddSNrBrPrQr-rrrrRsz MyWritePipeProto.connection_lost)N)r3r4r5r>r@rFrRrrrrrds rdc@s<eZdZddZddZddZddZd d Zd d Zd S)MySubprocessProtocolcsbd|_d|_|_|_fddtdD|_ddd|_d|_t t d|_ dS)Nr8csi|]}|qSr)r<).0fdr'rr z1MySubprocessProtocol.__init__..rk) r:r9r<r= completedrange disconnectsrK returncoderEventgot_datar?rrirr@s   zMySubprocessProtocol.__init__cCs0||_|jdksJ|jd|_|jddSrArCrErrrrFsz$MySubprocessProtocol.connection_madecCs*|jdksJ|jd|_|jddSre)r:rprDr-rrrrRsz$MySubprocessProtocol.connection_lostcCs8|jdksJ|j|j||7<|j|dSrG)r:rKruset)r*rhrKrrrpipe_data_receivedsz'MySubprocessProtocol.pipe_data_receivedcCs>|jdksJ|j|r*|j||n|j||dSrG)r:rr set_exceptionrD)r*rhr.rrrpipe_connection_lostsz)MySubprocessProtocol.pipe_connection_lostcCs$|jdksJ|j|j|_dSrG)r:r9Zget_returncodersr0rrrprocess_exitedsz#MySubprocessProtocol.process_exitedN) r3r4r5r@rFrRrwryrzrrrrrfs  rfcs0eZdZfddZfddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZeeeddddZeeedd d!d"Zeeedd d#d$Zdd&d'Zd(d)Zejd*d+Zd%d,ifd-d.Zdd/d0Zdd1d2Zee d,ud3d4d5Z!ejee d,ud3d6d7Z"d8d9Z#d:d;Z$ddd?Z&d@dAZ'e()dBdCdDZ*dEdFZ+dGdHZ,dIdJZ-eee.dKdLdMdNZ/dOdPZ0ejdQdRZ1eee.dSdTdUdVZ2ddWdXZ3ddYdZZ4dd[d\Z5ee d,ud3d]d^Z6ejee d,ud3d_d`Z7ee d,ud3dadbZ8ejee d,ud3dcddZ9ee d,ud3dedfZ:ejee d,ud3dgdhZ;ee d,ud3didjZeej?dodpdqZ@drdsZAdtduZBdvdwZCeej?dodxdyZDdzd{ZEd|d}ZFeeGjHd~kdddZIeeGjHd~kdddZJeeGjHd~kdddZKeeGjHd~kdddZLeeGjHd~kdddZMeeGjHd~kdeNOddddZPeeGjHd~kdeNOddddZQddZRddZSddZTddZUddZVddZWZXS)EventLoopTestsMixincs$t||_||jdSr)rTsetUpcreate_event_loopr'r%r0rVrrr|s  zEventLoopTestsMixin.setUpcs4|jst|j|ttdSr) r' is_closed test_utils run_brieflyZ doCleanupsr gc_collectrTtearDownr0rVrrrs   zEventLoopTestsMixin.tearDowncsZddfdd}td$tjj|Wdn1sL0YdS)NcstdIdHdSNr)rsleeprrrrcoro1szBEventLoopTestsMixin.test_run_until_complete_nesting..coro1cs"jjdSr) assertTruer' is_runningr&rrr*rrcoro2szBEventLoopTestsMixin.test_run_until_complete_nesting..coro2zcoroutine \S+ was never awaited)ZassertWarnsRegexRuntimeWarning assertRaises RuntimeErrorr'r&)r*rrrrtest_run_until_complete_nestings z3EventLoopTestsMixin.test_run_until_complete_nestingcCsR|j}|jtd|j}|d||ko@dkn||dS)N皙?g{Gz?g?)r'timer&rrr)r*t0t1rrrtest_run_until_completes  z+EventLoopTestsMixin.test_run_until_completecs(fdd}|}tjj|dS)NcsjtdIdHdS)Nr)r'stoprrrr0rrcbs z?EventLoopTestsMixin.test_run_until_complete_stopped..cb)rrr'r&)r*rZtaskrr0rtest_run_until_complete_stoppeds  z3EventLoopTestsMixin.test_run_until_complete_stoppedcs>gfdd}jd|djdgdS)Ncs|jdSrrcr'rargresultsr*rrcallback#s z5EventLoopTestsMixin.test_call_later..callbackrz hello world)r' call_later run_forever assertEqualr*rrrrtest_call_later s  z#EventLoopTestsMixin.test_call_latercs>gfdd}j|ddjdgdS)Ncs||fjdSrr)Zarg1Zarg2rrrr.sz4EventLoopTestsMixin.test_call_soon..callbackr"world)r"r)r' call_soonrrrrrrtest_call_soon+s  z"EventLoopTestsMixin.test_call_sooncsgtfddfdd}tj|d}|(jdjWdn1sx0Y| ddgdS)Ncs$|tdkr jdSNrorcrIr'rrrrrr:s  z?EventLoopTestsMixin.test_call_soon_threadsafe..callbackcsjddSr!)r'call_soon_threadsafereleaser)rlockr*rr run_in_thread?szDEventLoopTestsMixin.test_call_soon_threadsafe..run_in_threadtargetrr") threadingLockacquireThreadstartr'rrjoinr)r*rtr)rrrr*rtest_call_soon_threadsafe6s (z-EventLoopTestsMixin.test_call_soon_threadsafecsLgfdd}j|dj|djddgdS)Ncs$|tdkr jdSrrrrrrrPs  zKEventLoopTestsMixin.test_call_soon_threadsafe_same_thread..callbackr"r)r'rrrrrrrr%test_call_soon_threadsafe_same_threadMs  z9EventLoopTestsMixin.test_call_soon_threadsafe_same_threadcCsHdd}|jd|d}|j|\}}||d||tdS)NcSs |tfSr)r get_identrrrrrun[sz5EventLoopTestsMixin.test_run_in_executor..runZyo)r'run_in_executorr&rZassertNotEqualrr)r*rf2resZ thread_idrrrtest_run_in_executorZs  z(EventLoopTestsMixin.test_run_in_executorcsrdfdd}dd}|jd|}||j|j|j||j_||j_t d| dS)NFcsddSNTrargsZcalledrrpatched_call_sooneszJEventLoopTestsMixin.test_run_in_executor_cancel..patched_call_sooncSstddS)Ng?)rrrrrrrisz.rung?) r'rcancelr&Zshutdown_default_executorr1rrrr assertFalse)r*rrrrrrtest_run_in_executor_cancelbs   z/EventLoopTestsMixin.test_run_in_executor_cancelcst\}dtfdd}j|j|jdt jfddj|jdt jfddj|j jjj j d dS) NFcsVzd}Wnty"YdS0|r4|njdSN)recvBlockingIOErrorextendrr' remove_readerfilenor1rK bytes_readrr*rrreader{s  z8EventLoopTestsMixin.test_reader_callback..readersabccs tdkS)NrlrIrrrrrkz:EventLoopTestsMixin.test_reader_callback..sdefcs tdkS)Nrrrrrrrksabcdef)socket socketpair setblocking bytearrayr' add_readerrrr,r run_untilr1rrr)r*wrrrrtest_reader_callbackvs    z(EventLoopTestsMixin.test_reader_callbackcst\}dfdd}d}j||jj j | t |d}|  ||dS)NFcs|jdSr)r,r'rrr*rrrwriters z8EventLoopTestsMixin.test_writer_callback..writersxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxro)rrrr' add_writerrrr remove_writerrr1rrIr)r*rrrKreadrrrtest_writer_callbacks   z(EventLoopTestsMixin.test_writer_callbackSIGKILLz No SIGKILLcsXdfdd}|t|jjd||t|jjd|t|jjtjd||t|jjtjd|t|jjd||t|jjd|t|jjd||t|jjd|t|jjtj || |jtj |jtj |t t tj t|jfdd||jtj |ttj tj| |jtj dS) Nrcs d7dSNrnrrcaughtrr my_handlersz?EventLoopTestsMixin.test_add_signal_handler..my_handlerZboomrncsSrrrrrrrrkz=EventLoopTestsMixin.test_add_signal_handler..)r TypeErrorr'add_signal_handlerremove_signal_handler ValueErrorsignalNSIGrrrSIGINToskillgetpidrrrr getsignaldefault_int_handlerr*rrrrtest_add_signal_handlersP        z+EventLoopTestsMixin.test_add_signal_handlerSIGALRMz No SIGALRMcs^dfdd}jtj|ttjddjdjjj ddS)Nrcsd7jdSr)r'rrrr*rrrszLEventLoopTestsMixin.test_signal_handling_while_selecting..my_handler{Gz?<rn r'rrr setitimer ITIMER_REALrrrrrrrr$test_signal_handling_while_selectings z8EventLoopTestsMixin.test_signal_handling_while_selectingcslddfdd}jjtj|gRttjddjdjjj ddS)N)*rcs"d7|jdSr)rr'rrrr*Z some_argsrrrs zAEventLoopTestsMixin.test_signal_handling_args..my_handlerrrrnrrrrrtest_signal_handling_argss z-EventLoopTestsMixin.test_signal_handling_argsTcCsv|j|\}}||tj||tj||j||rN|| d|j|j | |j d| dS)Nsocknamer)r'r&assertIsInstancer TransportProtocolassertIsr9assertIsNotNoneget_extra_infor> assertGreaterr;r1)r*connection_futcheck_socknametrprrrr_basetest_create_connectionsz/EventLoopTestsMixin._basetest_create_connectioncsTt8}jjfddg|jR}|Wdn1sF0YdS)Ncs tjdSNrirSr'rr0rrrrkz.)rrun_test_serverr'create_connectionaddressr )r*httpdconn_futrr0rtest_create_connections  z*EventLoopTestsMixin.test_create_connectioncsXt }t4}jfdd|j}||Wdn1sJ0YdS)Ncs tjdSr rrr0rrrrkzAEventLoopTestsMixin.test_create_unix_connection..)r rrun_test_unix_serverr'create_unix_connectionrr )r*r rrrr0rtest_create_unix_connections  z/EventLoopTestsMixin.test_create_unix_connectionNcCs|r||d|r,|||dn||d|||d|d}||t|t|d|||dt||dt||dt|d }|||||d || |d|| |d|||d dS) NrpeernamepeercertcipherrlrrnroZ ssl_object compression) rrrrrrIstrrrrZ getpeercert)r*clientr rrrZsslobjrrrcheck_ssl_extra_infos<        z(EventLoopTestsMixin.check_ssl_extra_infocCsx|j|\}}||tj||tj|d|jj v| ||||j|j | |j d|dS)Nsslr)r'r&rrrrrrWr3lowerrr>rr;r1)r*rr rr r rrr_basetest_create_ssl_connection1sz3EventLoopTestsMixin._basetest_create_ssl_connectionc s|td}|||ttdrtjjfddddfdd }tjd|d6}|dd}||| |j d Wdn1s0Y tj P}|dd}t |||Wdn1s0YWdn1s0Y |jjd dS) NrPurpose)cafilecapathcadatacs|tjjtS)z A ssl.create_default_context() replacement that doesn't enable cert validation. )rrr# SERVER_AUTHrdummy_ssl_context)Zpurposer$r%r&r0rr_dummy_ssl_create_contextEszREventLoopTestsMixin._test_create_ssl_connection.._dummy_ssl_create_contextzssl.create_default_context) side_effectTrnZCERTIFICATE_VERIFY_FAILED)rr(r!hasattrrr#r'rpatchrZ call_countrSSLErrordisable_logger exceptionreason) r*rrr rrr)mcmrr0r_test_create_ssl_connection=s2   ,  @z/EventLoopTestsMixin._test_create_ssl_connectionz No ssl modulecsdtjddD}tjjjfddg|jR}j|||jdWdn1sV0YdS)NTZuse_sslcs tjdSr rrr0rrrgrkz@EventLoopTestsMixin.test_create_ssl_connection..r)rr functoolspartialr'rrr3)r*rrrr0rtest_create_ssl_connectionbs z.EventLoopTestsMixin.test_create_ssl_connectioncslt }tjddD}tjjjfdd|jdd}j||||jdWdn1s^0YdS)NTr4cs tjdSr rrr0rrrvrkzEEventLoopTestsMixin.test_create_ssl_unix_connection.. 127.0.0.1)server_hostnamer5) r rrr6r7r'rrr3)r*r rrrr0rtest_create_ssl_unix_connectionlsz3EventLoopTestsMixin.test_create_ssl_unix_connectioncstz}t}jjfddg|jRd|jd|fi}j|\}}|j dd} ||| Wdn1s0YdS)Ncs tjdSr rrr0rrrrkzGEventLoopTestsMixin.test_create_connection_local_addr.. local_addrrrrn) rrr find_unused_portr'rrr&r9rrr1)r*rportfr r Zexpectedrr0r!test_create_connection_local_addr}s    z5EventLoopTestsMixin.test_create_connection_local_addrc st}jjfddg|jRd|ji}t}j|Wdn1s\0Y|j j t j  t |j|j jWdn1s0YdS)Ncs tjdSr rrr0rrrrkzNEventLoopTestsMixin.test_create_connection_local_addr_in_use..r<)rrr'rrrOSErrorr&rr/errno EADDRINUSEassertInrstrerror)r*rr?r2rr0r(test_create_connection_local_addr_in_uses   *z.MyProtocst|jdSr)rTrRrrr-)rWr'rrrRs zQEventLoopTestsMixin.test_connect_accepted_socket..MyProto.connection_lostcst||jdSr)rTrLr9rUrJ)rWexpected_responserrrLs zOEventLoopTestsMixin.test_connect_accepted_socket..MyProto.data_received)r3r4r5rRrLrYr)rGr'rVrrSsrSr9rrn)backlogs test datasrogerc sxzDt}dur|}|||d|Wn.tyr}ztd|WYd}~n d}~00dS)Ncz8Failure in client thread in test_connect_accepted_socket)rZ wrap_socketconnectsendallrr1 Exceptionprint)Zcsockr.)r_ client_sslmessageresponserrrs     z@EventLoopTestsMixin.test_connect_accepted_socket..clientT)rdaemonricsSrrrprotorrrrkzBEventLoopTestsMixin.test_connect_accepted_socket..r"rP)r'r6r create_server getsocknamerrracceptr&connect_accepted_socketrr9r1r join_threadris_aliverr:r;rI) r*Z server_sslrOrSZlsockrthreadconn_r)r_rOrGr'rPrTrQrtest_connect_accepted_sockets4     z0EventLoopTestsMixin.test_connect_accepted_socketcCsLtjdkr,tjdkr,t|jtjr,tdt }t }| ||dS)Nr)rlrz=SSL not supported with proactor event loops before Python 3.5) rr version_info isinstancer'rZBaseProactorEventLoopunittestSkipTestrZsimple_server_sslcontextZsimple_client_sslcontextr^)r*Zserver_contextZclient_contextrrr test_ssl_connect_accepted_sockets  z4EventLoopTestsMixin.test_ssl_connect_accepted_socketcCsdt}||j|jjt|tjd}|t d|j |Wdn1sV0YdS)N)Zssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl) r addCleanupr1r'rXrSr ZLOOPBACK_TIMEOUTassertRaisesRegexrr&)r*sockcororrr9test_connect_accepted_socket_ssl_timeout_for_plain_sockets zMEventLoopTestsMixin.test_connect_accepted_socket_ssl_timeout_for_plain_socketzasyncio.base_events.socketc sfddfdd}t|}tjkrDdd|D|j_ndd|D|j_|j_tj_ tj_ j fdd |d }j |} |jd d |jD}||dS) Ncs>tjkr tjdd||ffgStjdd||ddffgSdS)Nrr)rAF_INET SOCK_STREAM)hostr>rkw)familyrr getaddrinfos zEEventLoopTestsMixin.create_server_multiple_hosts..getaddrinfocsj|i|Sr)r' create_task)rkwds)ror*rrgetaddrinfo_taskszJEventLoopTestsMixin.create_server_multiple_hosts..getaddrinfo_taskcSsg|] }|dfqS)Prrgrlrrr szDEventLoopTestsMixin.create_server_multiple_hosts..cSsg|]}|dddfqS)rsrrrtrrrruscs tjSrrrr0rrrrkzBEventLoopTestsMixin.create_server_multiple_hosts..rscSsh|]}|dqS)r) getsockbyname)rgrfrrr rkzCEventLoopTestsMixin.create_server_multiple_hosts..)rvrrjrvr*r'rorMockZ_start_serving _stop_servingrUr&rdr1socketsr) r*rnZhostsZ mock_sockrrZ unique_hostsr?serverZ server_hostsr)rnror*rcreate_server_multiple_hostss$      z0EventLoopTestsMixin.create_server_multiple_hostscCs|tjgddS)N)1.2.3.4z5.6.7.8r})r|rrjr0rrr&test_create_server_multiple_hosts_ipv4sz:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv4cCs|tjgddS)N)::1z::2r)r|rAF_INET6r0rrr&test_create_server_multiple_hosts_ipv6sz:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv6cs&t|j|jfdddd}|j|}|t|jd|jd}|\}}||dt}| d|f| d|jj |dj t |jfd d|d j|jd |djd dj|jj|d j ||dS)NcsSrrrrSrrrrkz8EventLoopTestsMixin.test_create_server..0.0.0.0rrnr9xxxrBcs jdkSrr;rrSrrrrkrlrrrP)rSr'rUr&rrIrzrVrrKrLr=r:rrr;rr9rr1r>r*r?r{rfrlr>rrrSrtest_create_servers.       z&EventLoopTestsMixin.test_create_server SO_REUSEPORTzNo SO_REUSEPORTcst|j|jfdddd}|j|}|t|jd|jd}||t j t j | t |jt|j|jjfdddddd}|j|}|t|jd|jd}||t j t j | dS) NcsSrrrrSrrr-rkzCEventLoopTestsMixin.test_create_server_reuse_port..rrrncsSrrrrSrrr:rkT) reuse_port)rSr'rUr&rrIrzr getsockoptr SOL_SOCKETrr1rrr)r*r?r{rfrrSrtest_create_server_reuse_port)s6       z1EventLoopTestsMixin.test_create_server_reuse_portc sDt|fdd|jj|fi|}|j|}|fS)NcstjotSr)rpathexistsunlinkrrrrrErkz7EventLoopTestsMixin._make_unix_server..)rZgen_unix_socket_pathrdr'create_unix_serverr&)r*factorykwargsr?r{rrr_make_unix_serverCs  z%EventLoopTestsMixin._make_unix_servercst|jd|fdd\}}|t|jdttj}||| d|j j |dj t |jfdd|djj|j j|d j ||dS) NricsSrrrrSrrrOrkz=EventLoopTestsMixin.test_create_unix_server..rnrrBcs jdkSrrrrSrrrXrkrlrP)rSr'rrrIrzrAF_UNIXrKrLr&r=r:rrr;r9r1r>)r*r{rrrrSrtest_create_unix_serverLs     z+EventLoopTestsMixin.test_create_unix_serverrzNo UNIX Socketsc st|jdt}|b|jjfddd|d}|td|j|Wdn1sb0YWdn1s0YdS)NricsSrrrrSrrrmrkzOEventLoopTestsMixin.test_create_unix_server_path_socket_error..z/testrfz3path and sock can not be specified at the same time)rSr'rrrerr&)r*rfr?rrSr)test_create_unix_server_path_socket_errorhs z=EventLoopTestsMixin.test_create_unix_server_path_socket_errorcCs,ttj}|jtjO_||||Sr)r SSLContextZPROTOCOL_TLS_SERVERoptions OP_NO_SSLv2Zload_cert_chain)r*certfilekeyfile sslcontextrrr_create_ssl_contextss  z'EventLoopTestsMixin._create_ssl_contextc CsX|||}|jj|dd|d}|j|}|jd}|\}} ||d||| fS)Nr9rr")rr'rUr&rzrVr) r*rrrrr?r{rfrlr>rrr_make_ssl_serverys     z$EventLoopTestsMixin._make_ssl_servercCs|||}|j||dS)Nr")rr)r*rrrrrrr_make_ssl_unix_servers z)EventLoopTestsMixin._make_ssl_unix_servercst|jd|fddtjtj\}}}|jjt||td}|j |\}}| d|j j | dj t|jfdd| dj|j|||fd j|j j| d j ||dS) NricsSrrrrSrrrrkz.r"rrBcs jdkSrrrrSrrrrkrlr5rP)rSr'rrONLYCERTONLYKEYrr6r(r&rUr=rr:rr;rr9r1r>)r*r{rlr>f_crr rrSrtest_create_server_ssls&     z*EventLoopTestsMixin.test_create_server_sslcst|jd|fddtjtj\}}|jjt|tdd}|j |\}}| d|j j | dj t|jfdd| d jj|j j| d j ||dS) NricsSrrrrSrrrrkzAEventLoopTestsMixin.test_create_unix_server_ssl..rirr:rrBcs jdkSrrrrSrrrrkrlrP)rSr'rrrrrr6r(r&rUr=rr:rr;r9r1r>)r*r{rrrr rrSrtest_create_unix_server_ssls&    z/EventLoopTestsMixin.test_create_unix_server_sslc s(t|jd|fddtj\}}}ttj}|jtj O_tj |_ t |dr\d|_ |jjt|||d}tj|jd~tJ|tjd|j|Wdn1s0YWdn1s0Yt|jWdn1s0Y|j|dS) NricsSrrrrSrrrrkzJEventLoopTestsMixin.test_create_server_ssl_verify_failed..check_hostnameTr"call_exception_handler(?i)certificate.verify.failed)rSr'rrSIGNED_CERTFILErrPROTOCOL_TLS_CLIENTrr CERT_REQUIRED verify_moder+rrrr,objectr.rer-r&r assertIsNoner9r1r*r{rlr>sslcontext_clientrrrSr$test_create_server_ssl_verify_faileds*      H, z8EventLoopTestsMixin.test_create_server_ssl_verify_failedc s&t|jd|fddtj\}}ttj}|jtj O_tj |_ t |drZd|_ |jjt||dd}tj|jd~tJ|tjd |j|Wdn1s0YWdn1s0Yt|jWdn1s0Y|j|dS) NricsSrrrrSrrrrkzOEventLoopTestsMixin.test_create_unix_server_ssl_verify_failed..rTinvalidrrr)rSr'rrrrrrrrrrr+rrrr,rr.rer-r&rrr9r1)r*r{rrrrrSr)test_create_unix_server_ssl_verify_faileds,     H, z=EventLoopTestsMixin.test_create_unix_server_ssl_verify_failedc s*t|jd|fddtj\}}}ttj}|jtj O_tj |_ |j tj dt|drjd|_|jjt|||d}tj|jdrtJ|tjd |j|Wdn1s0YWdn1s0YWdn1s0Y|j|dS) NricsSrrrrSrrrrkzIEventLoopTestsMixin.test_create_server_ssl_match_failed..r$rTr"rz=IP address mismatch, certificate is not valid for '127.0.0.1')rSr'rrrrrrrrrrload_verify_locations SIGNING_CAr+rrrr,rr.reZCertificateErrorr&rr9r1rrrSr#test_create_server_ssl_match_faileds0      h z7EventLoopTestsMixin.test_create_server_ssl_match_failedcst|jd|fddtj\}}ttj}|jtj O_tj |_ |j tj dt|drhd|_|jjt||dd}|j|\}}|jjj|||jjdS) NricsSrrrrSrrr%rkzJEventLoopTestsMixin.test_create_unix_server_ssl_verified..rrT localhostr)rSr'rrrrrrrrrrrrr+rrr&r=r9r1r>)r*r{rrrrr rrSr$test_create_unix_server_ssl_verified s(     z8EventLoopTestsMixin.test_create_unix_server_ssl_verifiedcst|jd|fddtj\}}}ttj}|jtj O_tj |_ |j tj dt|drjd|_|jjt|||dd}|j|\}}|jj|j|||ftjd j|||jjdS) NricsSrrrrSrrr?rkzEEventLoopTestsMixin.test_create_server_ssl_verified..rrTrr)rr)rSr'rrrrrrrrrrrrr+rrr&r=rZPEERCERTr9r1r>)r*r{rlr>rrrr rrSrtest_create_server_ssl_verified;s.       z3EventLoopTestsMixin.test_create_server_ssl_verifiedc s|jGfdddt}td}|jj||d}|j|}|jd}|||| \}}||dt}| d|f| d| | dS) NcseZdZfddZZS)z@EventLoopTestsMixin.test_create_server_sock..TestMyProtocst||dSrrTrFrDrE)rWrTrrrF]s zPEventLoopTestsMixin.test_create_server_sock..TestMyProto.connection_maderXrrSrVr TestMyProto\srrrrrrr9r) r'r<rSrrUr&rzrrrVrKr,r1) r*rsock_obr?r{rfrlr>rrrSrtest_create_server_sockYs       z+EventLoopTestsMixin.test_create_server_sockcCstd}|jjt|d}|j|}|jd}|\}}|jjt||d}|t}|j|Wdn1sz0Y| |j j t j | dS)Nrrrrlr>)rrUr'rSr&rzrVrrArr/rBrCr1)r*rr?r{rfrlr>r2rrrtest_create_server_addr_in_useps     *z2EventLoopTestsMixin.test_create_server_addr_in_usezIPv6 not supported or enabledc s<|jGfdddt}d}z*t}|jj|d|d}|j|}Wqty}z<|jtj kr|d7}| d|WYd}~q"nWYd}~q"d}~00qq"t }| d|f| d|j}|j||jt t j}| d |f| d|j}|j||dS) NcseZdZfddZZS)zFEventLoopTestsMixin.test_create_server_dual_stack..TestMyProtocst||dSrrrE)rWf_protorrrFs zVEventLoopTestsMixin.test_create_server_dual_stack..TestMyProto.connection_maderXrrrVrrsrrrrnrr9rr)r'r<rSr r=rUr&rArBrCZassertGreaterEqualrrKr,r9r1r) r*rZ try_countr>r?r{exrrTrrrtest_create_server_dual_stacks8           z1EventLoopTestsMixin.test_create_server_dual_stackcCs|jtdd}|j|}|jd}|\}}t}|d|f|d| | t}| t |jd|f| dS)Nrrr9r) r'rUrSr&rzrVrrKr,r1rConnectionRefusedErrorrrrrtest_server_closes     z%EventLoopTestsMixin.test_server_closec sGfdddt}jj|||d}j|\}|d}t|tjtjB\}} |t j  | dj j|jjfdd||fd}j|\}  | t j  t dj j| | d tjfd d d jtjfd d d j| d| jj dj jdS)Ncs*eZdZfddZfddZZS)zOEventLoopTestsMixin._test_create_datagram_endpoint..TestMyDatagramProtocstjjddSr )rTr@r')Z inner_self)rWr*rrr@szXEventLoopTestsMixin._test_create_datagram_endpoint..TestMyDatagramProto.__init__cs$t|||jd||dS)Nsresp:)rTr`r9sendtor^rVrrr`szaEventLoopTestsMixin._test_create_datagram_endpoint..TestMyDatagramProto.datagram_received)r3r4r5r@r`rYrr0rVrTestMyDatagramProtosr)r<rnrr[cs tjdSr rZr'rr0rrrrkzDEventLoopTestsMixin._test_create_datagram_endpoint..)Z remote_addrrcsjSrrr)r{rrrrkrlcsjSrrr)rrrrrkrP)rZr'create_datagram_endpointr&rr getnameinfoNI_NUMERICHOSTNI_NUMERICSERVrrrrr:rr9rrrr;rr1r>) r*r<rnrrgZ s_transportrrlr>r9r)rr*r{r_test_create_datagram_endpoints@      z2EventLoopTestsMixin._test_create_datagram_endpointcCs|dtjdS)NrH)rrrjr0rrrtest_create_datagram_endpointsz1EventLoopTestsMixin.test_create_datagram_endpointcCs|dtjdS)N)rr)rrrr0rrr"test_create_datagram_endpoint_ipv6sz6EventLoopTestsMixin.test_create_datagram_endpoint_ipv6c sd}d}jjj|dtji}|D]H\}}}}}z(tj|||d}|d||Wn Yq(0q~q(ds~Jdjjfdd|d} j| \} } | t j | t | j| j dS) NrHtype)rnrrTFzCan not create socket.cs tjdSr rrr0rrrrkzHEventLoopTestsMixin.test_create_datagram_endpoint_sock..r)r'r&ror SOCK_DGRAMrbindrrrrrZr1r>) r*rfZ local_addressZinfosrnrrTZcnamerr?r r rr0r"test_create_datagram_endpoint_socks4    z6EventLoopTestsMixin.test_create_datagram_endpoint_sockcCsf|}t|tjs&||d|d|j||d|j||j ||j dS)Nz#loop is not a BaseSelectorEventLooprnr) r}r`rZBaseSelectorEventLoopr1ZskipTestrZ _internal_fdsrZ_csockZ_ssockr?rrrtest_internal_fds s   z%EventLoopTestsMixin.test_internal_fdsrzDon't support pipes for Windowscstjdt\}}t|ddfdd}j|t|dt jfdd d j t|d t jfd d d d gj  dj t |jj gdj jddS)Nrirbrcs^jfddIdH\}}||jddgjdjdS)NcsSrrrrSrrr!rkzEEventLoopTestsMixin.test_read_pipe..connect..r8rBrr'connect_read_piperr9rr:r;rppipeobjrTr*rrrKs  z3EventLoopTestsMixin.test_read_pipe..connect1cs jdkSrrrrSrrr*rkz4EventLoopTestsMixin.test_read_pipe..rn2345cs jdkSNrrrrSrrr.rkr8rBrr8rBrMrPpipe)rbr'rrioopenr&rUrrrr;r:r1r>rr9r)r*rpipewpiperKrrrtest_read_pipes$      z"EventLoopTestsMixin.test_read_pipecs|tdtdt\}}t|ddt|ddfdd}|\}}| dt || dt |d|_ d|_ dS)NrirrrcsDfddIdH\}}fddIdH\}}||fS)NcsSrrr read_protorrrGrkzSEventLoopTestsMixin.test_unclosed_pipe_transport..connect..csSrrr write_protorrrIrk)rconnect_write_pipe)read_transportr]write_transportr'rZrpipeobjZwpipeobjrrrrKEs  zAEventLoopTestsMixin.test_unclosed_pipe_transport..connectr) r}rbrdrrrrr&r1rDreprZ_pipe)r*rrrKrrrrrtest_unclosed_pipe_transport9s   z0EventLoopTestsMixin.test_unclosed_pipe_transportcstjdt\}}t|ddfdd}j|t|dt jfdd d j t|d t jfd d d d gj  dj t |j jj gdj jddS)Nrirrcs^jfddIdH\}}||jddgjdjdS)NcsSrrrrSrrrdrkzKEventLoopTestsMixin.test_read_pty_output..connect..r8rBrrrZmaster_read_objrTr*rrrKcs z9EventLoopTestsMixin.test_read_pty_output..connectrcsjSrrrrSrrrnrkz:EventLoopTestsMixin.test_read_pty_output..rnrcs jdkSrrrrSrrrrrkr8rBrrr)rbr'ropenptyrrr&rUrrrr;r:r1r9r>rr)r*masterslaverKrrrtest_read_pty_output[s&       z(EventLoopTestsMixin.test_read_pty_outputcs6t\}t|dd}t|jd|jfdd|}|j|\}}||||j | dj | dt fdd t|jfd d| d| d t|jfd d| d | dj t|j dj |jj| dj dS)NwbrricsSrrrrSrrrrkz5EventLoopTestsMixin.test_write_pipe..rBrcstd}||7}t|SrrrrIrKchunk)rrrrs z3EventLoopTestsMixin.test_write_pipe..readercs dkSrrrrKrrrrrkrcs dkSrrrrrrrrk12345rrP)rrrrrdr'rr&rr9rr:rUrrrr1rrr>)r*rrrKr9rr)rKrTrrrtest_write_pipe~s,          z#EventLoopTestsMixin.test_write_pipecst\}}|dt|dd}t|jd|jfdd|}|j |\}}| || |j | dj |d|j |j|d}| d|||j j| d j dS) NFrrricsSrrrrSrrrrkzIEventLoopTestsMixin.test_write_pipe_disconnect_on_close..rBrrP)rrrrrdetachrdr'rr&rr9rr:rU sock_recvr1r>)r*ZrsockZwsockrrKr9rrKrrSr#test_write_pipe_disconnect_on_closes      z7EventLoopTestsMixin.test_write_pipe_disconnect_on_closerrcsBt\}t|dd}t|jd|jfdd|}|j|\}}||||j | dj | dt fdd tj|jfd dtjd | d| d tj|jfd dtjd | d| dj t|j dj |jj| dj dS)NrrricsSrrrrSrrrrkz4EventLoopTestsMixin.test_write_pty..rBrcstd}||7}t|Srrrrrrrs z2EventLoopTestsMixin.test_write_pty..readercs dkSrrrrrrrrktimeoutrcs dkSrrrrrrrrkrrrP)rrrrrdr'rr&rr9rr:rUrrrr SHORT_TIMEOUTr1rrr>)r*rslave_write_objrKr9rr)rKrrTrrtest_write_ptys4          z"EventLoopTestsMixin.test_write_ptyc st\}t|}t|t|dd}t|jd|j fdd|}|j |\}}| || |j | ddgj| djt|dd}t|jd|jfd d|}|j |\} }| || | j | djtfd d | d tj|jfd dtjd| d | ddgj| djtdtj|jfddtjd| ddgj| dj| dj| dtj|jfddtjd| d| ddgj| djtdtj|jfddtjd| ddgj| dj| djt||j j| gdj| |j j| djdS)NrrricsSrrrrrrrrkz.r8rBrcsSrrrrrrrrkcstd}||7}t|Srrrrrrrs z:EventLoopTestsMixin.test_bidirectional_pty..readerrcs dkSrrrrrrr rkracs jdkSrrrrrrrrkrnrcs dkSrrrrrrrrkrsbcdecs jdkSrrrrrrr"rkrrrP)rrdupttyZsetrawrrrbr'rr&rr9rr:r;rdrrrUrrr rr1r>) r*Z read_slaveZ write_slaveZslave_read_objZ read_connectrrrZ write_connectrr)rKrrrrrtest_bidirectional_ptysz                z*EventLoopTestsMixin.test_bidirectional_ptycst\}}|djj|dtdd}|durL|jfdd}t }j|}j t |} |d |dtjj|durƈ|jj|||dS)NFrnovcsZzHzjjIdHWntjy6d}Yn0d}Wjn j0|S)N cancelled)r'rrrCancelledErrorr)rr?r*rrmain;s z:EventLoopTestsMixin.test_prompt_cancellation..mainrr)rrrr'rprgetattrrpendingr monotonicrZ assertLessrresultrrrrryr1)r*rrr rrrelapsedrrrtest_prompt_cancellation3s&          z,EventLoopTestsMixin.test_prompt_cancellationcshfdd}jjdj_|j_fdd}j|jjdjjjjjjddS)Ncsjjd7_dSr)r'_run_once_counterrZ orig_run_oncer*rr _run_onceWsz._run_oncercsZj}tdIdHtdIdHtdIdHtdIdHtdIdHdS)Nrg-C6?gư>g:0yE>g|=)r'rrrir0rrwait_s z7EventLoopTestsMixin.test_timeout_rounding..wait)Zclock_resolutionselector) r'rrr&ZassertLessEqualZ_clock_resolution _selectorrWr3)r*rrrrrtest_timeout_roundingVs   z)EventLoopTestsMixin.test_timeout_roundingcCsx|}dd}t\}}||j||j|||||||||||| |dS)NcSsdSrrrrrrrrrkzCEventLoopTestsMixin.test_remove_fds_after_closing..) r}rrrdr1rrrrrr*r'rrrrrrtest_remove_fds_after_closingps     z1EventLoopTestsMixin.test_remove_fds_after_closingcCs|}dd}t\}}||j||j||t|||Wdn1sh0Y|t|||Wdn1s0YdS)NcSsdSrrrrrrr~rkz@EventLoopTestsMixin.test_add_fds_after_closing..) r}rrrdr1rrrrr rrrtest_add_fds_after_closing|s    * z.EventLoopTestsMixin.test_add_fds_after_closingcsPfdd}|j}tj|Wdn1sB0YdS)NcsjdSr)r'r1rir0rr close_loopszEEventLoopTestsMixin.test_close_running_event_loop..close_loop)r'rrr&)r*r#rgrr0rtest_close_running_event_loops   z1EventLoopTestsMixin.test_close_running_event_loopcCsJ|jdd}dd}|}||j|t|jWdn1sV0Y|t&|j}|j|Wdn1s0Y|t|j|Wdn1s0Y|t|j |Wdn1s0Y|t|j d|Wdn1s>0Y|t(|j |j d|Wdn1s0Y|t|j |Wdn1s0Y|t |jtj|Wdn1s0Y|t*|jd|}t|Wdn1s<0YdS)NcsdSrrrrrrtestsz,EventLoopTestsMixin.test_close..testcSsdSNFrrrrrrrkz0EventLoopTestsMixin.test_close..g?g)r'r1rdrrrr<r&rrrcall_atrrprrSIGTERMrr2next)r*r%funcrgZfutitrrr test_closes2   (  * * , . 8 , 0 zEventLoopTestsMixin.test_close)T)TN)TN)NN)N)N)N)Yr3r4r5r|rrrrrrrrrrrrra skipUnlessr+rrrrr rr Zskip_unless_bind_unix_socketrrr!r3skipIfrr8r;r@rFr^rcrhrr,r|r~rrrrrrrrrrrrrrrrrrrZ IPV6_ENABLEDrrrrrrrrrrrrrrr requires_mac_verrr rrr!r"r$r,rYrrrVrr{s       +     ! %    6   $              (0      !  %     '   F#  r{c@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ e ejdkdddZddZddZddZddZdd Zd!d"Zd#S)$SubprocessTestsMixincCs,tjdkr||tn|tj |dSNr)rrrrrrr(r*rsrrrcheck_terminateds z%SubprocessTestsMixin.check_terminatedcCs,tjdkr||tn|tj |dSr1)rrrrrrrr2rrr check_killeds z!SubprocessTestsMixin.check_killedcCstjtjtd}|jtt |jt j |}|j |\}}| |t |j |j|d|j|d}|d|j |jdt|Wdn1s0Y|j |j||j|d|jddS)Necho.pyrBrPython The Winnerrn)rrrdirname__file__r'subprocess_execr6r7rfr executabler&rr=rr:get_pipe_transportrUrurrr.r1rpr4rsrKr*progrKtransprTstdinrrrtest_subprocess_execs"     & z)SubprocessTestsMixin.test_subprocess_execcCs6tjtjtd}|jtt |jt j |}|j |\}}| |t |j |j|d|j|d}|d|j |jd|jd|d|jd|d|j |jd|d|jdt|Wdn1s0Y|j |j||jdS)Nr5rBrsPython rns The Winnerr6)rrrr7r8r'r9r6r7rfrr:r&rr=rr:r;rUrurclearrKrr.r1rpr4rsr<rrrtest_subprocess_interactives*      (z0SubprocessTestsMixin.test_subprocess_interactivecCs|jtt|jd}|j|\}}||t|j|j|d |j|j | d|j | tdd|jD| |jddd| |jdd | dS) Nz echo Pythonrcss|]}|VqdSr)r>)rgr?rrr rkz=SubprocessTestsMixin.test_subprocess_shell..rns sPythonrork)r'subprocess_shellr6r7rfr&rr=r;r1rprrsrallrrvaluesrKrstripr*rKr>rTrrrtest_subprocess_shells  z*SubprocessTestsMixin.test_subprocess_shellcCsd|jjtt|jddddd}|j|\}}||t|j|j|d|j | dS)Nexit 7r?stdoutstderr r'rDr6r7rfr&rrprrsr1rHrrrtest_subprocess_exitcodes  z-SubprocessTestsMixin.test_subprocess_exitcodecCs|jjtt|jddddd}|j|\}}||t||d||d||d|j|j | d|j || dS)NrJrKrrnrorN) r'rDr6r7rfr&rrr;rprrsr1rHrrr"test_subprocess_close_after_finishs  z7SubprocessTestsMixin.test_subprocess_close_after_finishcCstjtjtd}|jtt |jt j |}|j |\}}| |t |j |j||j |j||j|dSNr5)rrrr7r8r'r9r6r7rfrr:r&rr=rrpr4rsr1r*r=rKr>rTrrrtest_subprocess_kills   z)SubprocessTestsMixin.test_subprocess_killcCstjtjtd}|jtt |jt j |}|j |\}}| |t |j |j||j |j||j|dSrR)rrrr7r8r'r9r6r7rfrr:r&rr= terminaterpr3rsr1rSrrrtest_subprocess_terminate,s   z.SubprocessTestsMixin.test_subprocess_terminaterzDon't have SIGHUPc Csttjtj}ztjtjtd}|j t t |jt j|}|j|\}}||t |j|j|tj|j|j|tj |j|Wttj|nttj|0dSrR)rSIGHUPSIG_DFLrrrr7r8r'r9r6r7rfrr:r&rr= send_signalrprrsr1)r*Z old_handlerr=rKr>rTrrrtest_subprocess_send_signal<s    z0SubprocessTestsMixin.test_subprocess_send_signalcCstjtjtd}|jtt |jt j |}|j |\}}| |t |j |j|d}|d|j |j||d|jd||jdd|jd|d|jdS)Necho2.pyrtestOUT:testrnrosERR:test)rrrr7r8r'r9r6r7rfrr:r&rr=r;rUrpr1rrKrrrsr<rrrtest_subprocess_stderrTs    z+SubprocessTestsMixin.test_subprocess_stderrcCstjtjtd}|jjtt |jt j |t j d}|j|\}}||t |j|j|d}||d||d|d|j|j||jdd|jd|d|jd||d|jdS) Nr[)rMrrnror\sOUT:testERR:testrk)rrrr7r8r'r9r6r7rfrr: subprocessSTDOUTr&rr=r;rrrUrprrKrrr1rsr<rrr)test_subprocess_stderr_redirect_to_stdoutis&     z>SubprocessTestsMixin.test_subprocess_stderr_redirect_to_stdoutcCs\tjtjtd}|jtt |jt j |}|j |\}}| |t |j |j|d}|d}|d|j |jd|d|jd||j |jd|d|j |jdt jdkr|d |jdn|d |jdt|Wdn1s40Y|j |j||jdS) Nzecho3.pyrrnr\r]rrorsERR:BrokenPipeErrors ERR:OSError)rrrr7r8r'r9r6r7rfrr:r&rr=r;rUrurrrKr1rrrrr.rpr4rs)r*r=rKr>rTr?rLrrr#test_subprocess_close_client_streams0        (z8SubprocessTestsMixin.test_subprocess_close_client_streamcCsf|jjtt|jdddddd}|j|\}}||t|j|j|d|j | dS)NrJT)r?rLrMstart_new_sessionrNrOrHrrr"test_subprocess_wait_no_same_groups  z7SubprocessTestsMixin.test_subprocess_wait_no_same_groupcsfdd}t"j|ddWdn1s>0Yt"j|ddWdn1sz0Yt"j|ddWdn1s0YdS)Ncs"jjtjdfi|IdHdSNpwd)r'r9rSubprocessProtocol)rqr0rrrKs zGSubprocessTestsMixin.test_subprocess_exec_invalid_args..connectTuniversal_newlinesbufsizeshellrrr'r&r*rKrr0r!test_subprocess_exec_invalid_argss  0 0 z6SubprocessTestsMixin.test_subprocess_exec_invalid_argscsd fdd }t$j|ddgWdn1sB0Yt"j|ddWdn1s~0Yt"j|ddWdn1s0Yt"j|d d Wdn1s0YdS) Ncs*|sd}jjtj|fi|IdHdSre)r'rDrrg)cmdrqr0rrrKszHSubprocessTestsMixin.test_subprocess_shell_invalid_args..connectZlsz-lTrhrjrkFrm)Nrorprr0r"test_subprocess_shell_invalid_argss 2 0 0 z7SubprocessTestsMixin.test_subprocess_shell_invalid_argsN)r3r4r5r3r4r@rBrIrPrQrTrVrar.rrrZr^rarbrdrqrsrrrrr0s"   !  r0c@seZdZddZdS)SelectEventLoopTestscCstSr)rSelectorEventLoopr0rrrr}s&SelectEventLoopTests.create_event_loopNr3r4r5r}rrrrrtsrtc@s<eZdZddZddZddZddZd d Zd d Zd S)ProactorEventLoopTestscCstSr)rZProactorEventLoopr0rrrr}sz(ProactorEventLoopTests.create_event_loopcCstddSNz(IocpEventLoop does not have add_reader()rarbr0rrrrsz+ProactorEventLoopTests.test_reader_callbackcCstddSryrzr0rrrtest_reader_callback_cancelsz2ProactorEventLoopTests.test_reader_callback_cancelcCstddSNz(IocpEventLoop does not have add_writer()rzr0rrrrsz+ProactorEventLoopTests.test_writer_callbackcCstddSr|rzr0rrrtest_writer_callback_cancelsz2ProactorEventLoopTests.test_writer_callback_cancelcCstddSryrzr0rrrr!sz4ProactorEventLoopTests.test_remove_fds_after_closingN) r3r4r5r}rr{rr}r!rrrrrxs rxcs(eZdZfddZfddZZS)UnixEventLoopTestsMixincs,tt}||jt|dSr)rTr|rSafeChildWatcher attach_loopr'set_child_watcherr*ZwatcherrVrrr|s  zUnixEventLoopTestsMixin.setUpcstdtdSr)rrrTrr0rVrrrs z UnixEventLoopTestsMixin.tearDown)r3r4r5r|rrYrrrVrr~s r~KqueueSelectorcs\eZdZddZeddeej ddfddZ eddfd d Z Z S) KqueueEventLoopTestscCsttSr)rru selectorsrr0rrrr}sz&KqueueEventLoopTests.create_event_loopr Zopenbsdztest hangs on OpenBSDcstdSr)rTrr0rVrrrsz)KqueueEventLoopTests.test_read_pty_outputcstdSr)rTrr0rVrrrsz#KqueueEventLoopTests.test_write_pty)r3r4r5r}r r/rar.rrrrrrYrrrVrrs  r EpollSelectorc@seZdZddZdS)EPollEventLoopTestscCsttSr)rrurrr0rrrr}sz%EPollEventLoopTests.create_event_loopNrwrrrrrsr PollSelectorc@seZdZddZdS)PollEventLoopTestscCsttSr)rrurrr0rrrr} sz$PollEventLoopTests.create_event_loopNrwrrrrrsrc@seZdZddZdS)rtcCsttSr)rrurSelectSelectorr0rrrr}(srvNrwrrrrrt$scOsdSrr)rrrrrnoop,srcsheZdZfddZddZddZddZd d Zd d Zd dZ e e e jddddZZS) HandleTestscs"tt|_d|jj_dSr)rTr|rrxr' get_debug return_valuer0rVrrr|2s  zHandleTests.setUpcCs`dd}d}t|||j}||j|||j||||| |dS)NcWs|Srrrrrrr8sz)HandleTests.test_handle..callbackr) rHandler'r _callback_argsrrrr)r*rrhrrr test_handle7szHandleTests.test_handlecCs\dd}t|_t|j_t|d|j}||jjt dtj ||j ddS)NcSs tdSr)rrrrrrEsz:HandleTests.test_callback_with_exception..callbackrzException in callback.*)rPr/handleZsource_traceback) rrxr'rrrZ_runassert_called_withrZ MockPatternANY_source_traceback)r*rrrrrtest_callback_with_exceptionDs  z(HandleTests.test_callback_with_exceptioncCs(t}tddd|j}||d<dS)NcSsdSrrrrrrrWrkz1HandleTests.test_handle_weakref..rr)weakrefWeakValueDictionaryrrr')r*Zwdrrrrtest_handle_weakrefUszHandleTests.test_handle_weakrefcCsd|jj_ttd|j}tt\}}|t |d||f| |t |d| t t t}Wdn1s0Yt|d|j}|t |d||fttdd}t|d |j}d t||f}|t ||tjtdd }t|d |j}d t||f}|t ||tjdkrtj}t|}t|\}}t|d|j}d}d|}d|t||f}|t ||dS)NFrmzzrzrnro)rlz%^$)x)rorlz'^$)rlz*z%functools.partialmethod\(%s, , \)\(\)z^$)r'rrrrrrget_function_sourcerrrZ assertWarnsDeprecationWarning coroutiner6r7reescapeZ assertRegexrr_rtest_handle_repr partialmethod)r*rfilenamelinenorZregexmethodZcb_regexrrrrZsV    (     zHandleTests.test_handle_reprcCsd|jj_t}tjd}tt d|j}t t \}}| t |d||||f|| t |d||||f|| t |d||||fdS)NTrnrmz-z7)r'rrr8r _getframef_linenorrrrrrrrr*Zcreate_filenameZ create_linenorrrrrrtest_handle_repr_debugs0     z"HandleTests.test_handle_repr_debugcs|t}|d|fdd}|t}|||t}|||dt}|||dt}||dS)NTcsBtdjd}|jt|jdddt|dfdS)Nrnrrltest_handle_source_traceback)rrrrrlistrr8)rrr0rrcheck_source_tracebackszHHandleTests.test_handle_source_traceback..check_source_tracebackr) rget_event_loop_policyr$ set_debugr%rrrr)r*r'rrrr0rrs       z(HandleTests.test_handle_source_traceback CoroutinezNo collections.abc.CoroutinecCst}d|_|t||t|dd|_|t|dd|_ |t|dd|_|_|t|dt}d|_|t|d t}d|_d|_ |t|ddS) NZAAAzAAA()ZBBBzBBB()Tz BBB() runningz%() runningr)z CoroLike()) r)r3rrZ iscoroutinerrZ_format_coroutiner5 cr_runningcr_code)r*rgrrr+test_coroutine_like_object_debug_formattings&  z7HandleTests.test_coroutine_like_object_debug_formatting)r3r4r5r|rrrrrrrar-r+ collectionsabcrrYrrrVrr0s  2rcsLeZdZfddZddZddZddZd d Zd d Zd dZ Z S) TimerTestscstt|_dSr)rTr|rrxr'r0rVrrr|s zTimerTests.setUpcCs8t}t|dddt}|t|t|dS)NcSsdSr&rrrrrrrkz&TimerTests.test_hash..r)rrr TimerHandlerrxrhashr*whenrrrr test_hashs zTimerTests.test_hashcCs4t}t|dddt}|||dS)NcSsdSr&rrrrrrrkz&TimerTests.test_when..r)rrrrrrxrrrrrr test_whens zTimerTests.test_whencCsdd}d}t}t|||t}||j|||j|| | | | | | |j| |j|ttjd|||jdS)NcWs|Srrrrrrrsz'TimerTests.test_timer..callback)rnrorl)rrrrrrxrrrrrrrrrAssertionErrorr')r*rrrrrrr test_timers   zTimerTests.test_timercCsVd|jj_tdtd|j}tt}|t |d|| |t |ddS)NF{rz&z ) r'rrrrrrrrrr)r*rsrcrrrtest_timer_repr s    zTimerTests.test_timer_reprcCsd|jj_t}tjd}tdt d|j}t t \}}| t |d||||f|| t |d||||fdS)NTrnrrz7zA)r'rrr8rrrrrrrrrrrrrrrtest_timer_repr_debug s      z TimerTests.test_timer_repr_debugcCs:dd}t}t||d|j}t||d|j}|||k|||k|||k|||k|||k|||k|||k|||k|||k|||k||||kt||d|j}t|d|d|j}|||k|||k|||k|||k|||k|||k|||k|||k|||k|||kt|d|j}| t | || t | || t|dkWdn1s0Y| t|dkWdn1s0Y| t|dkWdn1sP0Y| t|dkWdn1s0Y||dk||dk||tk||tk||tk||tk||tk||tk||tk||tk||tk||tkdS)NcWs|Srrrrrrr1 sz2TimerTests.test_timer_comparison..callbackrg$@)rrrrr'rrrrrNotImplemented__eq____ne__rrr r r )r*rrZh1Zh2Zh3rrrtest_timer_comparison0 sf ( ( ( (z TimerTests.test_timer_comparison) r3r4r5r|rrrrrrrYrrrVrrs rc@seZdZddZddZdS)AbstractEventLoopTestscCst}t}|t|j|t|jd|t|j|t|j |t|j |t|j |t|j d|t|j dd|t|j|||t|jd|t|j|t|jd|t|j||t|jd||t|jd|t|jd||t|jd|t|jd||t|jd|t|jd|t|j||t|j||t|j||t|j|t|j|dSr)rrxrAbstractEventLooprNotImplementedErrorrr&rrr~r1rprr'rrrZset_default_executorrrrrrrZset_exception_handlerZdefault_exception_handlerrrr)r*r?r'rrrtest_not_implementedq s     z+AbstractEventLoopTests.test_not_implementedcs,fdd}t}|||dS)Ncs(t}t}t"|||IdHWdn1sB0Yt"|ddIdHWdn1s~0Yt |dIdHWdn1s0Yt | |IdHWdn1s0Yt | |IdHWdn1s.0Yt | |IdHWdn1sj0Yt"| |dIdHWdn1s0Yt"| |dIdHWdn1s0Yt"||dIdHWdn1s$0Yt"|||IdHWdn1sb0Yt ||IdHWdn1s0Yt"|||IdHWdn1s0Yt"|||IdHWdn1s0Yt&||tjjIdHWdn1s\0Yt&||tjjIdHWdn1s0Yt$||tjIdHWdn1s0Yt ||IdHWdn1s0YdS)Nr)rrr)rrxrrrrrrorrrUrrZsock_recv_intoZ sock_sendallZ sock_connectZ sock_acceptZ sock_sendfilesendfilersentinelrrrDr9)r?r'r0rrinner sH 0 0 . . 0 0 2 2 2 2 0 2 2 6 6 4 z@AbstractEventLoopTests.test_not_implemented_async..inner)rr$r&r1)r*rr'rr0rtest_not_implemented_async s ' z1AbstractEventLoopTests.test_not_implemented_asyncN)r3r4r5rrrrrrro s6rc@s^eZdZddZddZddZddZed d d Z d d Z ddZ ddZ ddZ dS) PolicyTestscCsZt}|t|j|t|jt|t|j|t|j|t|j tdSr) rAbstractEventLoopPolicyrrget_event_loopr%rr$Zget_child_watcherrr*policyrrrtest_event_loop_policy s z"PolicyTests.test_event_loop_policycCsXt}||jj|}||tj||jj||||| dSr) rDefaultEventLoopPolicyr_localZ_looprrrrr1r*rr'rrrtest_get_event_loop szPolicyTests.test_get_event_loopcCsZt}tjj|d|jd"}|}||Wdn1sD0Y|dS)Nr%)wraps) rrrr,rr%rrr1)r*rZm_set_event_loopr'rrr(test_get_event_loop_calls_set_event_loop s(z4PolicyTests.test_get_event_loop_calls_set_event_loopcCs$t}|d|t|jdSr)rrr%rrrrrrr"test_get_event_loop_after_set_none s z.PolicyTests.test_get_event_loop_after_set_nonez'asyncio.events.threading.current_threadcs,fdd}tj|d}||dS)Ncst}t|jdSr)rrrrr)rr0rrr? sz1PolicyTests.test_get_event_loop_thread..fr)rrrr)r*Zm_current_threadr?thrr0rtest_get_event_loop_thread s  z&PolicyTests.test_get_event_loop_threadcCs*t}|}||tj|dSr)rrr$rrr1rrrrtest_new_event_loop szPolicyTests.test_new_event_loopcCsht}|}|t|jt|}|||||| ||| | dSr) rrrrrr%rr$r assertIsNotr1)r*rZold_loopr'rrrtest_set_event_loop s zPolicyTests.test_set_event_loopcCs*t}||tj||tdSr)rrrrrrrrrtest_get_event_loop_policy sz&PolicyTests.test_get_event_loop_policycCsL|ttjtt}t}t|||t|||dSr) rrrrrrrrr)r* old_policyrrrrtest_set_event_loop_policy$ s  z&PolicyTests.test_set_event_loop_policyN)r3r4r5rrrrrr,rrrrrrrrrr s    rcsReZdZdZdZdZdZfddZfddZe j dkrBddZ d d Z Z S) GetEventLoopTestsMixinNcstj|_tj|_tj|_tj|_t |j t_t |j t_t |j t_t |j t_t |j t_t |j t_t |j t_t |j t_tt|_t|jtjdkrt}||jt|dSr1)r_get_running_loop_get_running_loop_saved_set_running_loop_set_running_loop_savedget_running_loopget_running_loop_savedrget_event_loop_savedr_get_running_loop_impl_set_running_loop_implget_running_loop_implget_event_loop_implrrTr|r$r'r%rrrrrrrVrrr|7 s&             zGetEventLoopTestsMixin.setUpc szvtjdkrtdtW|jtd|j t _ |j t _ |jt _|jt _|j t_ |j t_ |jt_|jt_nV|jtd|j t _ |j t _ |jt _|jt _|j t_ |j t_ |jt_|jt_0dSr1)rrrrrTrr'r1r%rrrrrrrrrr0rVrrrQ s0       zGetEventLoopTestsMixin.tearDownrcs.tfdd}j|ddS)Ncs*tj}j|tIdH}||Sr) concurrentfuturesProcessPoolExecutorr'rr(shutdown)poolrr0rrrm s   zDGetEventLoopTestsMixin.test_get_event_loop_new_process..mainr")r Z*skip_if_broken_multiprocessing_synchronizerr'r&)r*rrr0rtest_get_event_loop_new_processg s   z6GetEventLoopTestsMixin.test_get_event_loop_new_processc s&GdddtGfdddtj}t}zt|ttWdn1sn0YtdtWdn1s0Y t d  t dWdn1s0Y t dfdd}|ttWdn1sN0YtdtWdn1s0YWt|durԈnt|dur҈0 t d  t dWdn1s0Y t ddS)Nc@s eZdZdS)zRGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop..TestErrorN)r3r4r5rrrr TestErrory srcseZdZfddZdS)zOGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop..PolicycsdSrrr0rrrr} sz^GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop..Policy.get_event_loopN)r3r4r5rrrrrPolicy| srz no runningcs4tttdSr)rrrrrr)r'r*rrr* szMGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop..func)rMrrrrr$rrr%rerrrrr&r1)r*rrr*r)rr'r*r(test_get_event_loop_returns_running_loopx s>  &  &.   (  *     0z?GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop)r3r4r5rrrrr|rrrrrrYrrrVrr0 s   rc@s$eZdZejZejZejZ ej Z dS)TestPyGetEventLoopN) r3r4r5rZ_py__get_running_looprZ_py__set_running_looprZ_py_get_running_looprZ_py_get_event_looprrrrrr src@s$eZdZejZejZejZ ej Z dS)TestCGetEventLoopN) r3r4r5rZ_c__get_running_looprZ_c__set_running_looprZ_c_get_running_looprZ_c_get_event_looprrrrrr src@seZdZddZdS) TestServercsbt}||jt|||fdddd}|||||| dS)NcsSrrrrSrrr rkz*TestServer.test_get_loop..rr) rr$rdr1rSr&rUrget_loop wait_closed)r*r'r{rrSr test_get_loop s zTestServer.test_get_loopN)r3r4r5rrrrrr src@s$eZdZddZddZddZdS)TestAbstractServercCs:|ttWdn1s,0YdSr)rrrAbstractServerr1r0rrrr, s zTestAbstractServer.test_closecCsTt}||j|t"|t Wdn1sF0YdSr) rr$rdr1rrr&rrrr?rrrtest_wait_closed s  z#TestAbstractServer.test_wait_closedcCs:|ttWdn1s,0YdSr)rrrrrr0rrrr s z TestAbstractServer.test_get_loopN)r3r4r5r,rrrrrrr sr__main__)L__doc__collections.abcrconcurrent.futuresrr6rrrrrrr ImportErrorr_rrrrBrarrr rrrrrZtest.test_asynciorrr%r Z test.supportr r r r rr r(r)rr6rSZDatagramProtocolrZrbZ BaseProtocolrdrgrfr{r0ZTestCasertrxrr~r+rrrrrrrrrrZ_asynciorrrr3rrrrrs              " )Q          6 f[y