JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrJFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrB  f؟@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZddl mZddl mZddl mZdd l mZdd l mZdd l mZdd l mZdd lmZdZe jdkredddZGdddejZGdddejZGdddej ej!Z"Gdddej#Z$GdddZ%Gddde%Z&Gdd d e&Z'Gd!d"d"e&Z(Gd#d$d$ej)Z*eZ+e*Z,dS)%z2Selector event loop for Unix with signal handling.N) base_events)base_subprocess) constants) coroutines)events)futures)selector_events)tasks) transports)logger)SelectorEventLoopAbstractChildWatcherSafeChildWatcherFastChildWatcherDefaultEventLoopPolicyZwin32z+Signals are not really supported on WindowscCsdS)zDummy signal handler.N)signumframerr8/opt/alt/python37/lib64/python3.7/asyncio/unix_events.py_sighandler_noop'srcseZdZdZd)fdd ZfddZddZd d Zd d Zd dZ ddZ d*ddZ d+ddZ d,ddZ ddZd-dddddddZd.dddddddd Zd!d"Zd#d$Zd%d&Zd'd(ZZS)/_UnixSelectorEventLoopzdUnix event loop. Adds signal handling and UNIX Domain Socket support to SelectorEventLoop. Ncst|i|_dS)N)super__init___signal_handlers)selfselector) __class__rrr2s z_UnixSelectorEventLoop.__init__cs^tts2xFt|jD]}||qWn(|jrZtjd|dt |d|j dS)NzClosing the loop z@ on interpreter shutdown stage, skipping signal handlers removal)source) rclosesys is_finalizinglistrremove_signal_handlerwarningswarnResourceWarningclear)rsig)rrrr6s z_UnixSelectorEventLoop.closecCs"x|D]}|sq||qWdS)N)_handle_signal)rdatarrrr_process_self_dataDs z)_UnixSelectorEventLoop._process_self_datac GsLt|st|rtd|||yt|j Wn2t t fk rt}zt t |Wdd}~XYnXt|||d}||j|<yt|tt|dWnt k rF}zz|j|=|jsytdWn4t t fk r}ztd|Wdd}~XYnX|jtjkr4t d|dnWdd}~XYnXdS)zAdd a handler for a signal. UNIX only. Raise ValueError if the signal number is invalid or uncatchable. Raise RuntimeError if there is a problem setting up the handler. z3coroutines cannot be used with add_signal_handler()NFzset_wakeup_fd(-1) failed: %szsig z cannot be caught)rZ iscoroutineZiscoroutinefunction TypeError _check_signalZ _check_closedsignal set_wakeup_fdZ_csockfileno ValueErrorOSError RuntimeErrorstrrZHandlerr siginterruptr infoerrnoEINVAL)rr(callbackargsexchandleZnexcrrradd_signal_handlerKs0     z)_UnixSelectorEventLoop.add_signal_handlercCs8|j|}|dkrdS|jr*||n ||dS)z2Internal helper that is the actual signal handler.N)rgetZ _cancelledr#Z_add_callback_signalsafe)rr(r=rrrr)xs   z%_UnixSelectorEventLoop._handle_signalc Cs||y |j|=Wntk r*dSX|tjkr>tj}ntj}yt||WnBtk r}z$|jtj krt d|dnWdd}~XYnX|jsyt dWn2t tfk r}zt d|Wdd}~XYnXdS)zwRemove a handler for a signal. UNIX only. Return True if a signal handler was removed, False if not. Fzsig z cannot be caughtNr,zset_wakeup_fd(-1) failed: %sT)r.rKeyErrorr/SIGINTdefault_int_handlerSIG_DFLr3r8r9r4r0r2r r7)rr(Zhandlerr<rrrr#s(    z,_UnixSelectorEventLoop.remove_signal_handlercCsLt|tstd|d|kr.tjksHntd|dtjddS)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 rzsig z out of range(1, )N) isinstanceintr-r/NSIGr2)rr(rrrr.s z$_UnixSelectorEventLoop._check_signalcCst|||||S)N)_UnixReadPipeTransport)rpipeprotocolwaiterextrarrr_make_read_pipe_transportsz0_UnixSelectorEventLoop._make_read_pipe_transportcCst|||||S)N)_UnixWritePipeTransport)rrIrJrKrLrrr_make_write_pipe_transportsz1_UnixSelectorEventLoop._make_write_pipe_transportc st} |} t||||||||f| |d| } | | |j| y| IdHWn,tk r| | IdHYnXWdQRX| S)N)rKrL) rget_child_watcher create_future_UnixSubprocessTransportadd_child_handlerZget_pid_child_watcher_callback ExceptionrZ_wait) rrJr;shellstdinstdoutstderrbufsizerLkwargswatcherrKtransprrr_make_subprocess_transports     z1_UnixSelectorEventLoop._make_subprocess_transportcCs||j|dS)N)Zcall_soon_threadsafeZ_process_exited)rpid returncoder]rrrrTsz._UnixSelectorEventLoop._child_watcher_callback)sslsockserver_hostnamessl_handshake_timeoutc s |r|dkr6tdn |dk r&td|dk r6td|dk r|dk rNtdt|}ttjtjd}y |d|||IdHWq|YqXn@|dkrtd|j tjks|j tjkrtd||d|j |||||d IdH\}}||fS) Nz/you have to pass server_hostname when using sslz+server_hostname is only meaningful with sslz1ssl_handshake_timeout is only meaningful with sslz3path and sock can not be specified at the same timerFzno path and sock were specifiedz.A UNIX Domain Stream Socket was expected, got )rd) r2osfspathsocketAF_UNIX SOCK_STREAM setblockingZ sock_connectrfamilytypeZ_create_connection_transport) rprotocol_factorypathrarbrcrd transportrJrrrcreate_unix_connections@       z-_UnixSelectorEventLoop.create_unix_connectiondT)rbbacklogrard start_servingc st|trtd|dk r&|s&td|dk rH|dk r@tdt|}ttjtj}|ddkry t t |j rt |WnBt k rYn0tk r}ztd||Wdd}~XYnXy||Wnltk r0} z8|| jtjkrd|d} ttj| dnWdd} ~ XYn|YnXn<|dkrZtd |jtjksv|jtjkrtd ||d t||g||||} |r| tjd|d IdH| S) Nz*ssl argument must be an SSLContext or Nonez1ssl_handshake_timeout is only meaningful with sslz3path and sock can not be specified at the same timer)rz2Unable to check or remove stale UNIX socket %r: %rzAddress z is already in usez-path was not specified, and no sock specifiedz.A UNIX Domain Stream Socket was expected, got F)loop)rEboolr-r2rerfrgrhristatS_ISSOCKst_moderemoveFileNotFoundErrorr3r errorZbindrr8Z EADDRINUSErkrlrjrZServerZ_start_servingr Zsleep) rrmrnrbrrrardrserrr<msgZserverrrrcreate_unix_serversZ            z)_UnixSelectorEventLoop.create_unix_serverc sy tjWn,tk r6}ztdWdd}~XYnXy |}Wn2ttjfk rv}ztdWdd}~XYnXyt|j }Wn,t k r}ztdWdd}~XYnX|r|n|} | sdS| } | | d||||| d| IdHS)Nzos.sendfile() is not availableznot a regular filer) resendfileAttributeErrorrSendfileNotAvailableErrorr1ioUnsupportedOperationfstatst_sizer3rQ_sock_sendfile_native_impl) rrbfileoffsetcountr<r1r}Zfsize blocksizefutrrr_sock_sendfile_native>s(     z,_UnixSelectorEventLoop._sock_sendfile_nativec Cs|} |dk r|||r4||||dS|rd||}|dkrd||||||dSyt| |||} Wn*ttfk r|dkr| ||| | |j || |||||| YnHt k rj} z|dk r| j t jkrt| tk rtdt j} | | _| } |dkrBtd} |||||| n|||||| Wdd} ~ XYntk r} z|||||| Wdd} ~ XYnjX| dkr||||||nD|| 7}|| 7}|dkr| ||| | |j || |||||| dS)Nrzsocket is not connectedzos.sendfile call failed)r1 remove_writer cancelled_sock_sendfile_update_fileposZ set_resultrerBlockingIOErrorInterruptedError_sock_add_cancellation_callbackZ add_writerrr3r8ZENOTCONNrlConnectionError __cause__rrZ set_exceptionrU)rrZ registered_fdrbr1rrr total_sentfdZsentr<new_excr}rrrrUs`             z1_UnixSelectorEventLoop._sock_sendfile_native_implcCs|dkrt||tjdS)Nr)relseekSEEK_SET)rr1rrrrrrsz4_UnixSelectorEventLoop._sock_sendfile_update_fileposcsfdd}||dS)Ncs&|r"}|dkr"|dS)Nr,)rr1r)rr)rrbrrcbszB_UnixSelectorEventLoop._sock_add_cancellation_callback..cb)Zadd_done_callback)rrrbrr)rrbrrsz6_UnixSelectorEventLoop._sock_add_cancellation_callback)N)NN)NN)N)N)N)__name__ __module__ __qualname____doc__rrr+r>r)r#r.rMrOr^rTrprrrrr __classcell__rr)rrr,s4 -      *?DrcseZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ dddZddZddZZS) rHiNcst|||jd<||_||_||_||_d|_d|_ t |jj }t |st |st |sd|_d|_d|_tdt |jd|j|jj||j|jj|j|j|dk r|jtj|ddS)NrIFz)Pipe transport is for pipes/sockets only.)rr_extra_loop_piper1_fileno _protocol_closing_pausedrerryrwS_ISFIFOrxS_ISCHRr2 set_blocking call_soonconnection_made _add_reader _read_readyr_set_result_unless_cancelled)rrurIrJrKrLmode)rrrrs.         z_UnixReadPipeTransport.__init__cCs|jjg}|jdkr |dn|jr0|d|d|jt|jdd}|jdk r|dk rt ||jt j }|r|dq|dn |jdk r|dn |dd d |S) Nclosedclosingzfd= _selectorpollingidleopenz<{}> )rrrappendrrgetattrrr _test_selector_event selectorsZ EVENT_READformatjoin)rr7rrrrr__repr__s"         z_UnixReadPipeTransport.__repr__c Csyt|j|j}WnDttfk r,Yntk rX}z||dWdd}~XYn^X|rl|j |nJ|j rt d|d|_|j |j|j |jj|j |jddS)Nz"Fatal read error on pipe transportz%r was closed by peerT)rereadrmax_sizerrr3 _fatal_errorrZ data_receivedr get_debugr r7r_remove_readerrZ eof_received_call_connection_lost)rr*r<rrrrs  z"_UnixReadPipeTransport._read_readycCs>|js |jrdSd|_|j|j|jr:td|dS)NTz%r pauses reading)rrrrrrr debug)rrrr pause_readings   z$_UnixReadPipeTransport.pause_readingcCsB|js |jsdSd|_|j|j|j|jr>td|dS)NFz%r resumes reading) rrrrrrrr r)rrrrresume_readings   z%_UnixReadPipeTransport.resume_readingcCs ||_dS)N)r)rrJrrr set_protocolsz#_UnixReadPipeTransport.set_protocolcCs|jS)N)r)rrrr get_protocolsz#_UnixReadPipeTransport.get_protocolcCs|jS)N)r)rrrr is_closingsz!_UnixReadPipeTransport.is_closingcCs|js|ddS)N)r_close)rrrrrsz_UnixReadPipeTransport.closecCs.|jdk r*tjd|t|d|jdS)Nzunclosed transport )r)rr$r%r&r)rrrr__del__ s z_UnixReadPipeTransport.__del__Fatal error on pipe transportcCsZt|tr4|jtjkr4|jrLtjd||ddn|j||||j d| |dS)Nz%r: %sT)exc_info)message exceptionrorJ) rEr3r8ZEIOrrr rcall_exception_handlerrr)rr<rrrrrs  z#_UnixReadPipeTransport._fatal_errorcCs(d|_|j|j|j|j|dS)NT)rrrrrr)rr<rrrr sz_UnixReadPipeTransport._closecCs4z|j|Wd|jd|_d|_d|_XdS)N)rconnection_lostrrr)rr<rrrr%s  z,_UnixReadPipeTransport._call_connection_lost)NN)r)rrrrrrrrrrrrrrrrrrrr)rrrHs rHcseZdZd%fdd ZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZd&dd Zd'd!d"Zd#d$ZZS)(rNNc st||||jd<||_||_||_t|_d|_ d|_ t |jj }t|}t|}t|} |s|s| sd|_d|_d|_tdt |jd|j|jj|| s|rtjds|j|jj|j|j|dk r|jtj|ddS)NrIrFz?Pipe transport is only for pipes, sockets and character devicesZaix)rrrrr1rr bytearray_buffer _conn_lostrrerryrwrrrxr2rrrrr platform startswithrrrr) rrurIrJrKrLrZis_charZis_fifoZ is_socket)rrrr2s2         z _UnixWritePipeTransport.__init__cCs|jjg}|jdkr |dn|jr0|d|d|jt|jdd}|jdk r|dk rt ||jt j }|r|dn |d| }|d|n |jdk r|dn |dd d |S) Nrrzfd=rrrzbufsize=rz<{}>r)rrrrrrrrr rrZ EVENT_WRITEget_write_buffer_sizerr)rr7rrrZrrrrWs&         z _UnixWritePipeTransport.__repr__cCs t|jS)N)lenr)rrrrrosz-_UnixWritePipeTransport.get_write_buffer_sizecCs6|jrtd||jr*|tn|dS)Nz%r was closed by peer)rrr r7rrBrokenPipeError)rrrrrrs   z#_UnixWritePipeTransport._read_readyc Cst|trt|}|sdS|js&|jrN|jtjkr _sig_chldr)rrurrrrgs zBaseChildWatcher.attach_loopc CsFy |Wn4tk r@}z|jd|dWdd}~XYnXdS)Nz$Unknown exception in SIGCHLD handler)rr)rrUrr)rr<rrrr{s  zBaseChildWatcher._sig_chldcCs2t|rt| St|r*t|S|SdS)N)re WIFSIGNALEDWTERMSIG WIFEXITED WEXITSTATUS)rstatusrrr_compute_returncodes     z$BaseChildWatcher._compute_returncodeN) rrrrrrrrrrrrrrrXs rcsPeZdZdZfddZddZddZdd Zd d Zd d Z ddZ Z 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|jtdS)N)rr'rr)r)rrrrs zSafeChildWatcher.closecCs|S)Nr)rrrrrszSafeChildWatcher.__enter__cCsdS)Nr)rrrrrrrrszSafeChildWatcher.__exit__cGs.|jdkrtd||f|j|<||dS)NzICannot add child handler, the child watcher does not have a loop attached)rr4rr)rr_r:r;rrrrSs  z"SafeChildWatcher.add_child_handlercCs&y |j|=dStk r dSXdS)NTF)rr@)rr_rrrrs z%SafeChildWatcher.remove_child_handlercCs"xt|jD]}||q WdS)N)r"rr)rr_rrrrsz SafeChildWatcher._do_waitpid_allcCsyt|tj\}}Wn(tk r>|}d}td|Yn0X|dkrLdS||}|jrnt d||y|j |\}}Wn.t k r|jrtjd|ddYnX|||f|dS)Nz8Unknown child process pid %d, will report returncode 255rz$process %s exited with returncode %sz'Child watcher got an unexpected pid: %rT)r) rewaitpidWNOHANGChildProcessErrorr rrrrrrpopr@)rrr_rr`r:r;rrrrs*    zSafeChildWatcher._do_waitpid) rrrrrrrrSrrrrrr)rrrs   rcsTeZdZdZfddZfddZddZdd Zd d Zd d Z ddZ Z 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). cs$tt|_i|_d|_dS)Nr)rr threadingZLock_lock_zombies_forks)r)rrrrs  zFastChildWatcher.__init__cs"|j|jtdS)N)rr'r rr)r)rrrrs  zFastChildWatcher.closec Cs$|j|jd7_|SQRXdS)Nr)r r )rrrrrszFastChildWatcher.__enter__c CsT|j8|jd8_|js"|js&dSt|j}|jWdQRXtd|dS)Nrz5Caught subprocesses termination from unknown pids: %s)r r r r5r'r r)rrrrZcollateral_victimsrrrrs  zFastChildWatcher.__exit__c Gsl|jdkrtd|j:y|j|}Wn"tk rL||f|j|<dSXWdQRX|||f|dS)NzICannot add child handler, the child watcher does not have a loop attached)rr4r r rr@r)rr_r:r;r`rrrrS s z"FastChildWatcher.add_child_handlercCs&y |j|=dStk r dSXdS)NTF)rr@)rr_rrrr s z%FastChildWatcher.remove_child_handlerc Csxytdtj\}}Wntk r,dSX|dkr:dS||}|jvy|j|\}}WnBtk r|j r||j |<|j rt d||wd}YnX|j rt d||WdQRX|dkrt d||q|||f|qWdS)Nr,rz,unknown process %s exited with returncode %sz$process %s exited with returncode %sz8Caught subprocess termination from unknown pid: %d -> %d)rerrrrr rrr@r r rrr rr)rr_rr`r:r;rrrr's6      z FastChildWatcher._do_waitpid_all) rrrrrrrrrSrrrrr)rrrs   rcsHeZdZdZeZfddZddZfddZdd Z d d Z Z S) _UnixDefaultEventLoopPolicyz:UNIX event loop policy with a watcher for child processes.cstd|_dS)N)rr_watcher)r)rrrrVs z$_UnixDefaultEventLoopPolicy.__init__c CsHtj8|jdkr:t|_tttjr:|j|j j WdQRXdS)N) rr r rrErcurrent_thread _MainThreadr_localr)rrrr _init_watcherZs  z)_UnixDefaultEventLoopPolicy._init_watchercs6t||jdk r2tttjr2|j|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_loopr rErrrr)rru)rrrrbs  z*_UnixDefaultEventLoopPolicy.set_event_loopcCs|jdkr||jS)zzGet the watcher for child processes. If not yet set, a SafeChildWatcher object is automatically created. N)r r)rrrrrPps z-_UnixDefaultEventLoopPolicy.get_child_watchercCs|jdk r|j||_dS)z$Set the watcher for child processes.N)r r)rr\rrrset_child_watcherzs  z-_UnixDefaultEventLoopPolicy.set_child_watcher) rrrrrZ _loop_factoryrrrrPrrrr)rrr Rs   r )-rr8rrerr/rgrwrr rr$rrrrrrr r r logr __all__r ImportErrorrZBaseSelectorEventLooprZ ReadTransportrHZ_FlowControlMixinZWriteTransportrNZBaseSubprocessTransportrRrrrrZBaseDefaultEventLoopPolicyr r rrrrrsR           | JF=On3