PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  oY @sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddl m Z ddl mZddl mZdd l mZdd l mZdd l mZdd l mZdd l mZddlmZddlmZdddddgZejdkrbedddZy ejZWnek rddZYnXGdddejZ e!edrddZ"nddl#Z#d dZ"Gd!d"d"ej$Z%Gd#d$d$ej&ej'Z(e!ed%r>ej)Z*nddl#Z#d&d'Z*Gd(d)d)e j+Z,Gd*ddZ-Gd+d,d,e-Z.Gd-dde.Z/Gd.dde.Z0Gd/d0d0ej1Z2e Z3e2Z4dS)1z2Selector event loop for Unix with signal handling.N) base_events)base_subprocess)compat) constants) coroutines)events)futures)selector_events) selectors) transports) coroutine)loggerSelectorEventLoopAbstractChildWatcherSafeChildWatcherFastChildWatcherDefaultEventLoopPolicywin32z+Signals are not really supported on WindowscCsdS)zDummy signal handler.N)signumframerr*/opt/python35/lib/python3.5/unix_events.py_sighandler_noop%srcCs|S)Nr)pathrrr.src seZdZdZdfddZddZfddZd d Zd d Zd dZ ddZ ddZ ddddZ ddddZ edddZddZeddddddddZedddd d!ddd"d#ZS)$_UnixSelectorEventLoopzdUnix event loop. Adds signal handling and UNIX Domain Socket support to SelectorEventLoop. Ncstj|i|_dS)N)super__init___signal_handlers)selfselector) __class__rrr7sz_UnixSelectorEventLoop.__init__cCs tjS)N)socket socketpair)r rrr _socketpair;sz"_UnixSelectorEventLoop._socketpaircs8tjx$t|jD]}|j|qWdS)N)rcloselistrremove_signal_handler)r sig)r"rrr&>s z_UnixSelectorEventLoop.closecCs+x$|D]}|sq|j|qWdS)N)_handle_signal)r datarrrr_process_self_dataCs z)_UnixSelectorEventLoop._process_self_datac+Gstj|stj|r*td|j||jytj|jj Wn=t t fk r}zt t |WYdd}~XnXtj|||}||j|tjkns^tdj|tjdS)zInternal helper to validate a signal. Raise ValueError if the signal number is invalid or uncatchable. Raise RuntimeError if there is a problem setting up the handler. zsig must be an int, not {!r}rzsig {} out of range(1, {})N) isinstanceintr.r<r1NSIGr4)r r)rrrr/s z$_UnixSelectorEventLoop._check_signalcCst|||||S)N)_UnixReadPipeTransport)r pipeprotocolwaiterextrarrr_make_read_pipe_transportsz0_UnixSelectorEventLoop._make_read_pipe_transportcCst|||||S)N)_UnixWritePipeTransport)r rLrMrNrOrrr_make_write_pipe_transportsz1_UnixSelectorEventLoop._make_write_pipe_transportc kstj} |j} t||||||||d| d|| } | j| j|j| y | EdHWn+tk r} z | }WYdd} ~ XnXd}|dk r| j| j EdH|WdQRX| S)NrNrO) rget_child_watcherZ create_future_UnixSubprocessTransportadd_child_handlerZget_pid_child_watcher_callback Exceptionr&_wait)r rMr>shellstdinstdoutstderrbufsizerOkwargswatcherrNtranspr?errrrr_make_subprocess_transports$        z1_UnixSelectorEventLoop._make_subprocess_transportcCs|j|j|dS)N)Zcall_soon_threadsafeZ_process_exited)r pid returncoder`rrrrVsz._UnixSelectorEventLoop._child_watcher_callbacksslsockserver_hostnamec csc|dks!t|ts!t|rB|dkrZtdn|dk rZtd|dk r|dk r~tdtjtjtjd}y&|jd|j||EdHWq6|j Yq6Xn\|dkrtd|j tjkst j | r)tdj ||jd|j||||EdH\}}||fS)Nz/you have to pass server_hostname when using sslz+server_hostname is only meaningful with sslz3path and sock can not be specified at the same timerFzno path and sock were specifiedz2A UNIX Domain Stream Socket was expected, got {!r})rHr7AssertionErrorr4r#AF_UNIX SOCK_STREAM setblockingZ sock_connectr&familyr_is_stream_socketr<Z_create_connection_transport)r protocol_factoryrrerfrg transportrMrrrcreate_unix_connections:!              z-_UnixSelectorEventLoop.create_unix_connectionbacklogdc !Cst|trtd|dk r|dk r?tdt|}tjtjtj}|dd kry,tj t j|j rt j |WnIt k rYn8tk r}ztjd||WYdd}~XnXy|j|Wqtk ri}zK|j|jtjkrTdj|}ttj|dnWYdd}~Xq|jYqXnO|dkrtd|jtjkstj| rtdj|tj||g} |j||jd |j|||| | S) Nz*ssl argument must be an SSLContext or Nonez3path and sock can not be specified at the same timerz2Unable to check or remove stale UNIX socket %r: %rzAddress {!r} is already in usez-path was not specified, and no sock specifiedz2A UNIX Domain Stream Socket was expected, got {!r}F)rrs)rHboolr.r4_fspathr#rirjstatS_ISSOCKosst_moderemoveFileNotFoundErrorr5rerrorbindr&r:Z EADDRINUSEr<rlrrmZServerlistenrkZ_start_serving) r rnrrfrqrerar?msgZserverrrrcreate_unix_serversP      &        z)_UnixSelectorEventLoop.create_unix_server)__name__ __module__ __qualname____doc__rr%r&r,rAr*r(r/rPrRr rbrVrprrr)r"rr1s,    -   %r set_blockingcCstj|ddS)NF)rxr)fdrrr_set_nonblocking9srcCs<tj|tj}|tjB}tj|tj|dS)N)fcntlZF_GETFLrx O_NONBLOCKZF_SETFL)rflagsrrrr>s cseZdZdZddfddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ e jrddZdddZddZddZS) rKiNcs*tj|||jd<||_||_|j|_||_d|_t j |jj }t j |pt j|pt j|sd|_d|_d|_tdt|j|jj|jj||jj|jj|j|j|dk r&|jjtj|ddS)NrLFz)Pipe transport is for pipes/sockets only.)rr_extra_loop_piper3_fileno _protocol_closingrxfstatryrvS_ISFIFOrwS_ISCHRr4r call_soonconnection_made _add_reader _read_readyr _set_result_unless_cancelled)r looprLrMrNrOmode)r"rrrHs,           z_UnixReadPipeTransport.__init__cCs|jjg}|jdkr.|jdn|jrD|jd|jd|jt|jdd}|jdk r|dk rtj ||jt j }|r|jdq|jdn,|jdk r|jdn |jddd j |S) Nclosedclosingzfd=%s _selectorpollingidleopenz<%s> ) r"rrappendrrgetattrrr _test_selector_eventr EVENT_READjoin)r r9r!rrrr__repr__es$   z_UnixReadPipeTransport.__repr__cCsytj|j|j}WnLttfk r6Yntk rj}z|j|dWYdd}~XnX|r|jj |ng|j j rt j d|d|_|j j|j|j j|jj|j j|jddS)Nz"Fatal read error on pipe transportz%r was closed by peerT)rxreadrmax_sizeBlockingIOErrorInterruptedErrorr5 _fatal_errorrZ data_receivedr get_debugrr9r_remove_readerrZ eof_received_call_connection_lost)r r+r?rrrr{s# z"_UnixReadPipeTransport._read_readycCs|jj|jdS)N)rrr)r rrr pause_readingsz$_UnixReadPipeTransport.pause_readingcCs|jj|j|jdS)N)rrrr)r rrrresume_readingsz%_UnixReadPipeTransport.resume_readingcCs ||_dS)N)r)r rMrrr set_protocolsz#_UnixReadPipeTransport.set_protocolcCs|jS)N)r)r rrr get_protocolsz#_UnixReadPipeTransport.get_protocolcCs|jS)N)r)r rrr is_closingsz!_UnixReadPipeTransport.is_closingcCs|js|jddS)N)r_close)r rrrr&s z_UnixReadPipeTransport.closecCs4|jdk r0tjd|t|jjdS)Nzunclosed transport %r)rwarningswarnResourceWarningr&)r rrr__del__sz_UnixReadPipeTransport.__del__zFatal error on pipe transportc Cst|trL|jtjkrL|jjrwtjd||ddn+|jjd|d|d|d|j i|j |dS)Nz%r: %sexc_infoTmessage exceptionrorM) rHr5r:ZEIOrrrdebugcall_exception_handlerrr)r r?rrrrrs! z#_UnixReadPipeTransport._fatal_errorcCs6d|_|jj|j|jj|j|dS)NT)rrrrrr)r r?rrrrs z_UnixReadPipeTransport._closec CsDz|jj|Wd|jjd|_d|_d|_XdS)N)rconnection_lostrr&r)r r?rrrrs    z,_UnixReadPipeTransport._call_connection_losti)rrrrrrrrrrrrr&rPY34rrrrrr)r"rrKDs            rKcseZdZddfddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZejrddZddZddd Zdd!d"Zd#d$ZS)%rQNc sjtj||||jd<||_|j|_||_t|_d|_ d|_ t j |jj }tj|}tj|}tj|} |p|p| sd|_d|_d|_tdt|j|jj|jj|| s|rAtjjd rA|jj|jj|j|j|dk rf|jjtj|ddS)NrLrFz?Pipe transport is only for pipes, sockets and character devicesaix)rrrrr3rr bytearray_buffer _conn_lostrrxrryrvrrrwr4rrrrsysplatform startswithrrr r) r rrLrMrNrOrZis_charZis_fifoZ is_socket)r"rrrs2            z _UnixWritePipeTransport.__init__cCs#|jjg}|jdkr.|jdn|jrD|jd|jd|jt|jdd}|jdk r|dk rtj ||jt j }|r|jdn |jd|j }|jd|n,|jdk r|jdn |jdd d j |S) Nrrzfd=%srrrz bufsize=%srz<%s>r)r"rrrrrrrr rr EVENT_WRITEget_write_buffer_sizer)r r9r!rr]rrrrs(     z _UnixWritePipeTransport.__repr__cCs t|jS)N)lenr)r rrrrsz-_UnixWritePipeTransport.get_write_buffer_sizecCsI|jjrtjd||jr;|jtn |jdS)Nz%r was closed by peer)rrrr9rrBrokenPipeError)r rrrr s  z#_UnixWritePipeTransport._read_readycCst|tttfs*tt|t|trEt|}|sOdS|jsa|jr|jtj krt j d|jd7_dS|j snyt j|j|}Wnettfk rd}YnHtk r}z(|jd7_|j|ddSWYdd}~XnX|t|kr3dS|dkrUt||d}|jj|j|j|j |7_ |jdS)Nz=pipe closed by peer or os.write(pipe, data) raised exception.rrz#Fatal write error on pipe transport)rHbytesr memoryviewrhreprrrrZ!LOG_THRESHOLD_FOR_CONNLOST_WRITESrwarningrrxwriterrrrWrrrZ _add_writer _write_readyZ_maybe_pause_protocol)r r+nr?rrrrs4*     z_UnixWritePipeTransport.writecCs;|jstdytj|j|j}Wn{ttfk rKYntk r}zD|jj|j d7_ |j j |j|j |dWYdd}~XnX|t |jkr|jj|j j |j|j|jr|j j|j|jddS|dkr7|jd|=dS)NzData should not be emptyrz#Fatal write error on pipe transportr)rrhrxrrrrrWclearrr_remove_writerrrZ_maybe_resume_protocolrrr)r rr?rrrr4s( #     z$_UnixWritePipeTransport._write_readycCsdS)NTr)r rrr can_write_eofNsz%_UnixWritePipeTransport.can_write_eofcCs[|jr dS|jstd|_|jsW|jj|j|jj|jddS)NT) rrrhrrrrrr)r rrr write_eofQs   z!_UnixWritePipeTransport.write_eofcCs ||_dS)N)r)r rMrrrrZsz$_UnixWritePipeTransport.set_protocolcCs|jS)N)r)r rrrr]sz$_UnixWritePipeTransport.get_protocolcCs|jS)N)r)r rrrr`sz"_UnixWritePipeTransport.is_closingcCs'|jdk r#|j r#|jdS)N)rrr)r rrrr&csz_UnixWritePipeTransport.closecCs4|jdk r0tjd|t|jjdS)Nzunclosed transport %r)rrrrr&)r rrrrlsz_UnixWritePipeTransport.__del__cCs|jddS)N)r)r rrrabortqsz_UnixWritePipeTransport.abortzFatal error on pipe transportc Csyt|tjr=|jjrhtjd||ddn+|jjd|d|d|d|ji|j |dS)Nz%r: %srTrrrorM) rHrZ_FATAL_ERROR_IGNORErrrrrrr)r r?rrrrrts z$_UnixWritePipeTransport._fatal_errorcCs_d|_|jr%|jj|j|jj|jj|j|jj|j|dS)NT) rrrrrrrrr)r r?rrrrs    z_UnixWritePipeTransport._closec CsDz|jj|Wd|jjd|_d|_d|_XdS)N)rrrr&r)r r?rrrrs    z-_UnixWritePipeTransport._call_connection_lost)rrrrrrrrrrrrrrr&rrrrrrrrr)r"rrQs$ %   !         rQset_inheritablecCsittdd}tj|tj}|sJtj|tj||Bntj|tj||@dS)NZ FD_CLOEXECr)rrZF_GETFDZF_SETFD)r inheritableZ cloexec_flagoldrrr_set_inheritables rc@seZdZddZdS)rTc Ksd}|tjkr=|jj\}}t|jdtj|d|d|d|d|ddd|||_|dk r|jt |j dd ||j_ dS) NFrYrZr[r\universal_newlinesr]wb buffering) subprocessPIPErr%rr3Popen_procr&rdetachrZ) r r>rYrZr[r\r]r^Zstdin_wrrr_starts  z_UnixSubprocessTransport._startN)rrrrrrrrrTs rTc@s^eZdZdZddZddZddZdd Zd d Zd d Z dS)raHAbstract base class for monitoring child processes. Objects derived from this class monitor a collection of subprocesses and report their termination or interruption by a signal. New callbacks are registered with .add_child_handler(). Starting a new process must be done within a 'with' block to allow the watcher to suspend its activity until the new process if fully registered (this is needed to prevent a race condition in some implementations). Example: with watcher: proc = subprocess.Popen("sleep 1") watcher.add_child_handler(proc.pid, callback) Notes: Implementations of this class must be thread-safe. Since child watcher objects may catch the SIGCHLD signal and call waitpid(-1), there should be only one active object per process. cGs tdS)aRegister a new child handler. Arrange for callback(pid, returncode, *args) to be called when process 'pid' terminates. Specifying another callback for the same process replaces the previous handler. Note: callback() must be thread-safe. N)NotImplementedError)r rcr=r>rrrrUs z&AbstractChildWatcher.add_child_handlercCs tdS)zRemoves the handler for process 'pid'. The function returns True if the handler was successfully removed, False if there was nothing to remove.N)r)r rcrrrremove_child_handlersz)AbstractChildWatcher.remove_child_handlercCs tdS)zAttach the watcher to an event loop. If the watcher was previously attached to an event loop, then it is first detached before attaching to the new loop. Note: loop may be None. N)r)r rrrr attach_loopsz AbstractChildWatcher.attach_loopcCs tdS)zlClose the watcher. This must be called to make sure that any underlying resource is freed. N)r)r rrrr&szAbstractChildWatcher.closecCs tdS)zdEnter the watcher's context and allow starting new processes This function must return selfN)r)r rrr __enter__szAbstractChildWatcher.__enter__cCs tdS)zExit the watcher's contextN)r)r abcrrr__exit__szAbstractChildWatcher.__exit__N) rrrrrUrrr&rrrrrrrs    c@sdeZdZddZddZddZddZd d Zd d Zd dZ dS)BaseChildWatchercCsd|_i|_dS)N)r _callbacks)r rrrrs zBaseChildWatcher.__init__cCs|jddS)N)r)r rrrr& szBaseChildWatcher.closecCs tdS)N)r)r expected_pidrrr _do_waitpid szBaseChildWatcher._do_waitpidcCs tdS)N)r)r rrr_do_waitpid_allsz BaseChildWatcher._do_waitpid_allcCs|dks$t|tjs$t|jdk rX|dkrX|jrXtjdt|jdk rz|jj t j ||_|dk r|j t j |j |jdS)NzCA loop is being detached from a child watcher with pending handlers)rHrZAbstractEventLooprhrrrrRuntimeWarningr(r1SIGCHLDrA _sig_chldr)r rrrrrs$$  zBaseChildWatcher.attach_loopcCsVy|jWnAtk rQ}z!|jjddd|iWYdd}~XnXdS)Nrz$Unknown exception in SIGCHLD handlerr)rrWrr)r r?rrrr&s  zBaseChildWatcher._sig_chldcCsAtj|rtj| Stj|r9tj|S|SdS)N)rx WIFSIGNALEDWTERMSIG WIFEXITED WEXITSTATUS)r statusrrr_compute_returncode2s  z$BaseChildWatcher._compute_returncodeN) rrrrr&rrrrrrrrrrs       rcspeZdZdZfddZddZddZdd Zd d Zd d Z ddZ S)rad'Safe' child watcher implementation. This implementation avoids disrupting other code spawning processes by polling explicitly each process in the SIGCHLD handler instead of calling os.waitpid(-1). This is a safe solution but it has a significant overhead when handling a big number of children (O(n) each time SIGCHLD is raised) cs|jjtjdS)N)rrrr&)r )r"rrr&Ks zSafeChildWatcher.closecCs|S)Nr)r rrrrOszSafeChildWatcher.__enter__cCsdS)Nr)r rrrrrrrRszSafeChildWatcher.__exit__cGs?|jdkrtd||f|j|<|j|dS)NzICannot add child handler, the child watcher does not have a loop attached)rr6rr)r rcr=r>rrrrUUs  z"SafeChildWatcher.add_child_handlerc Cs/y|j|=dSWntk r*dSYnXdS)NTF)rrC)r rcrrrr`s   z%SafeChildWatcher.remove_child_handlercCs+x$t|jD]}|j|qWdS)N)r'rr)r rcrrrrgsz SafeChildWatcher._do_waitpid_allcCs |dkstytj|tj\}}Wn.tk ra|}d}tjd|YnBX|dkrrdS|j|}|jj rtj d||y|j j |\}}Wn7t k r|jj rtjd|ddYnX||||dS)Nrz8Unknown child process pid %d, will report returncode 255z$process %s exited with returncode %sz'Child watcher got an unexpected pid: %rrT)rhrxwaitpidWNOHANGChildProcessErrorrrrrrrrpoprC)r rrcrrdr=r>rrrrls,       zSafeChildWatcher._do_waitpid) rrrrr&rrrUrrrrr)r"rr@s     csveZdZdZfddZfddZddZdd Zd d Zd d Z ddZ S)raW'Fast' child watcher implementation. This implementation reaps every terminated processes by calling os.waitpid(-1) directly, possibly breaking other code spawning processes and waiting for their termination. There is no noticeable overhead when handling a big number of children (O(1) each time a child terminates). cs2tjtj|_i|_d|_dS)Nr)rr threadingLock_lock_zombies_forks)r )r"rrrs  zFastChildWatcher.__init__cs+|jj|jjtjdS)N)rrrrr&)r )r"rrr&s  zFastChildWatcher.closec Cs(|j|jd7_|SWdQRXdS)Nr)rr)r rrrrs zFastChildWatcher.__enter__c Csg|jG|jd8_|js,|j r0dSt|j}|jjWdQRXtjd|dS)Nrz5Caught subprocesses termination from unknown pids: %s)rrrr7rrr)r rrrZcollateral_victimsrrrrs zFastChildWatcher.__exit__cGs|jstd|jdkr0td|jGy|jj|}Wn)tk r{||f|j|rdrrrrUs   z"FastChildWatcher.add_child_handlerc Cs/y|j|=dSWntk r*dSYnXdS)NTF)rrC)r rcrrrrs   z%FastChildWatcher.remove_child_handlercCs9x2ytjdtj\}}Wntk r:dSYn X|dkrKdS|j|}|jy|jj|\}}WnStk r|j r||j |<|j j rt jd||wd}Yn#X|j j rt jd||WdQRX|dkr!t jd||q||||qWdS)Nrrz,unknown process %s exited with returncode %sz$process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %dr-)rxrrrrrrrrCrrrrrrr)r rcrrdr=r>rrrrs6             z FastChildWatcher._do_waitpid_all) rrrrrr&rrrUrrrr)r"rrs     csdeZdZdZeZfddZddZfddZdd Z d d Z S) _UnixDefaultEventLoopPolicyz:UNIX event loop policy with a watcher for child processes.cstjd|_dS)N)rr_watcher)r )r"rrrs z$_UnixDefaultEventLoopPolicy.__init__c Cs^tjN|jdkrSt|_ttjtjrS|jj|j j WdQRXdS)N) rrrrrHrcurrent_thread _MainThreadr_localr)r rrr _init_watchers     z)_UnixDefaultEventLoopPolicy._init_watchercsKtj||jdk rGttjtjrG|jj|dS)zSet the event loop. As a side effect, if a child watcher was set before, then calling .set_event_loop() from the main thread will call .attach_loop(loop) on the child watcher. N)rset_event_looprrHrrr r)r r)r"rrr  sz*_UnixDefaultEventLoopPolicy.set_event_loopcCs |jdkr|j|jS)zzGet the watcher for child processes. If not yet set, a SafeChildWatcher object is automatically created. N)rr )r rrrrSs z-_UnixDefaultEventLoopPolicy.get_child_watchercCsJ|dks!t|ts!t|jdk r=|jj||_dS)z$Set the watcher for child processes.N)rHrrhrr&)r r_rrrset_child_watcher%s! z-_UnixDefaultEventLoopPolicy.set_child_watcher) rrrrrZ _loop_factoryrr r rSr rr)r"rrs   r)5rr:rxr1r#rvrrrrrrrrrrr r r r r logr__all__r ImportErrorrZfspathruAttributeErrorZBaseSelectorEventLooprhasattrrrZ ReadTransportrKZ_FlowControlMixinZWriteTransportrQrrZBaseSubprocessTransportrTrrrrZBaseDefaultEventLoopPolicyrrrrrrrsh                    F=On2