o b^@sddlmZddlZddlZddlZddlZddlmZmZddl m Z ddZ da ed d Z e jZeejejurCeejZnd Zd d ZeddZddZgadaeddZdS))print_functionN)closingcontextmanager)_gicCslt|dr |ddSzddl}Wn tytdw|}|||j}|||j||jBdS)zEnsures that the socket is not inherited by child processes Raises: EnvironmentError NotImplementedError: With Python <3.4 on Windows set_inheritableFrNz+Not implemented for older Python on Windows) hasattrrfcntl ImportErrorNotImplementedErrorfilenoF_GETFDF_SETFD FD_CLOEXEC)sockr fdflagsr1/usr/lib/python3/dist-packages/gi/_ossighelper.pyensure_socket_not_inheritables   rFc #strdVdSddlmt\}tt||fD] }|dt|q"z t | }Wnt yPdVYWdWddSwdafdd}zRt j dkrij }nj }|jjjjjBjjBjjB|}z dVW|n|wWt |}|| krt |dant |}|| krt |dawWdn1swYWddSWddS1swYdS) aA decorator for functions which create a glib event loop to keep Python signal handlers working while the event loop is idling. In case an OS signal is received will wake the default event loop up shortly so that any registered Python signal handlers registered through signal.signal() can run. In case the wrapped function is not called from the main thread it will be called as is and it will not wake up the default loop for signals. Nr)GLibFTc sN|j@r%ztdWSty$}z t|WYd}~dSd}~wwdS)NrF)IO_INboolrecvEnvironmentErrorprint)source conditioner read_socketrr signal_notify\s z'wakeup_on_signal..signal_notifynt)_wakeup_fd_is_active gi.repositoryrsocket socketpairr setblockingrsignal set_wakeup_fdr ValueErrorosname IOChannelwin32_new_socketunix_new io_add_watchPRIORITY_DEFAULT IOConditionINHUPNVALERR source_remove) write_socketrorig_fdr!channel source_idwrite_fdrrrwakeup_on_signal7s^            Pr=cCs ttjtjuottjtkS)z?Returns if on SIGINT the default Python handler would be called)r( getsignalSIGINTdefault_int_handler PyOS_getsigstartup_sigint_ptrrrrrsigint_handler_is_defaults rDc cstsJttj|ttj}z!dVWttj|ur0ttj|kr2ttjtjdSdSdSttj|urLttj|krMttjtjwww)zContext manager for saving/restoring the SIGINT handler default state. Will only restore the default handler again if the handler is not changed while the context is active. N)rDr(r@rBr?rA)handlersig_ptrrrr&sigint_handler_set_and_restore_defaults   rGcCstjdkS)z@Returns True in case the function is called from the main thread MainThread) threadingcurrent_threadr,rrrris_main_threadsrKc csts dVdSts3tr.t|zdVWt}tr!|dSt}tr-|wwdVdSdadd}t|z)t| dVWdn1sQwYWtrbttj ddStdStrrttj dwtw)aInstalls a SIGINT signal handler in case the default Python one is active which calls 'callback' in case the signal occurs. Only does something if called from the main thread. In case of nested context managers the signal handler will be only installed once and the callbacks will be called in the reverse order of their registration. The old signal handler will be restored in case no signal handler is registered while the context is active. NFcSstrdSdatdS)NT)_sigint_called_callback_stackpop)sig_numframerrrsigint_handlersz0register_sigint_fallback..sigint_handler) rKrDrMappendrNrLrGr(rAr@)callbackcbrQrrrregister_sigint_fallbacksB     rU) __future__rr+r%r(rI contextlibrrrrr#r= pyos_getsigrBr?r@rArCrDrGrKrMrLrUrrrrs0   I