
    fZ!                     j   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJrJ	r	  SSK
Jr  S rSq \	S 5       r\R                  r\R"                  r\R&                  " \R(                  5      \R*                  L a  \" \R(                  5      rOS	rS
 r\	S 5       rS r/ qSq\	S 5       r " S S5      rS rg)    )print_functionN)closingcontextmanager   )_gic                 ,   [        U S5      (       a  U R                  S5        g SSKnU R                  5       nUR                  X!R                  5      nUR                  X!R
                  X1R                  -  5        g! [         a    [        S5      ef = f)zEnsures that the socket is not inherited by child processes

Raises:
    EnvironmentError
    NotImplementedError: With Python <3.4 on Windows
set_inheritableFr   Nz+Not implemented for older Python on Windows)	hasattrr	   fcntlfilenoF_GETFDF_SETFD
FD_CLOEXECImportErrorNotImplementedError)sockr   fdflagss       1/usr/lib/python3/dist-packages/gi/_ossighelper.pyensure_socket_not_inheritabler      s     t&''U#	E
 BKKMM2EKKMM53C3C+CD  	?%=? ?	?s   A= =BFc               #     ^^#    [         (       a  Sv   gSSKJm  [        R                  " 5       u  mn [        T5         [        U 5         TU 4 H  nUR                  S5        [        U5        M!      [        R                  " U R                  5       5      nSq UU4S jn [        R                  S:X  a*  TR                  R                  TR                  5       5      nO)TR                  R!                  TR                  5       5      nTR#                  UTR$                  TR&                  R(                  TR&                  R*                  -  TR&                  R,                  -  TR&                  R.                  -  U5      n Sv   TR1                  U5         [        R                  " U5      nX`R                  5       :w  a  [        R                  " U5        Sq  SSS5        SSS5        g! [         a    Sv    SSS5        SSS5        gf = f! TR1                  U5        f = f! [        R                  " U5      nX`R                  5       :w  a  [        R                  " U5        Sq f = f! , (       d  f       N= f! , (       d  f       g= f7f)a  A 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                    > UTR                   -  (       a   [        TR                  S5      5      $ g! [         a  n[	        U5         S nAgS nAff = f)Nr   F)IO_INboolrecvEnvironmentErrorprint)source	conditioner   read_sockets      r   signal_notify'wakeup_on_signal.<locals>.signal_notify]   sK    4::%! 0 0 344  ( !!H !s   2 
AAAnt)_wakeup_fd_is_activegi.repositoryr   socket
socketpairr   setblockingr   signalset_wakeup_fdr   
ValueErrorosname	IOChannelwin32_new_socketunix_newio_add_watchPRIORITY_DEFAULTIOConditionINHUPNVALERRsource_remove)	write_socketr   orig_fdr#   channel	source_idwrite_fdr   r"   s	          @@r   wakeup_on_signalr@   8   s     " & 1 1 3K		w|4 ,/DU#)$/ 0	(**<+>+>+@AG $( 			)ww$..99&&(* ..11+2D2D2FG))%%!!$$t'7'7';';;!!&&')-)9)9)=)=>I.""9-++G4H..00 $$X.#( c  5		  	  5			D ""9-++G4H..00 $$X.#( c  54		s   :JI:
(I)3$G)	I)!CH# HH#AI)I: 	J)H
7I)8I: 	J	H

I)H  H##AI&&I))
I7	3I::
JJc                      [         R                  " [         R                  5      [         R                  L =(       a     [	        [         R                  5      [
        :H  $ )z?Returns if on SIGINT the default Python handler would be called)r+   	getsignalSIGINTdefault_int_handlerPyOS_getsigstartup_sigint_ptr     r   sigint_handler_is_defaultrJ      s=     V]]+v/I/II =&*<<>rI   c              #     #    [        5       (       d   e[        R                  " [        R                  U 5        [        [        R                  5      n Sv   [        R                  " [        R                  5      U L aR  [        [        R                  5      U:X  a4  [        R                  " [        R                  [        R
                  5        ggg! [        R                  " [        R                  5      U L aR  [        [        R                  5      U:X  a4  [        R                  " [        R                  [        R
                  5        f f f = f7f)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)rJ   r+   rD   rF   rC   rE   )handlersig_ptrs     r   &sigint_handler_set_and_restore_defaultrN      s      %&&&&
MM&--)&--(GEFMM*g5FMM*g5MM&--)C)CD 6 66FMM*g5FMM*g5MM&--)C)CD 6 6s    AEC A:EA;EEc                  F    [         R                  " 5       R                  S:H  $ )z@Returns True in case the function is called from the main thread
MainThread)	threadingcurrent_threadr/   rH   rI   r   is_main_threadrS      s     ##%**l::rI   c              #     #    [        5       (       d  Sv   g[        5       (       dQ  [        (       aA  [        R                  U 5         Sv   [        R	                  5       n[
        (       a  U" 5         gSv   gSqS n[        R                  U 5         [        U5         Sv   SSS5        [
        (       a&  [        R                  " [        R                  S5        g[        R	                  5         g! [        R	                  5       n[
        (       a  U" 5         f f = f! , (       d  f       N= f! [
        (       a&  [        R                  " [        R                  S5        f [        R	                  5         f = f7f)a  Installs 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.
NFc                 R    [         (       a  g Sq [        R                  5       " 5         g )NT)_sigint_called_callback_stackpop)sig_numframes     r   sigint_handler0register_sigint_fallback.<locals>.sigint_handler   s      >rI   )
rS   rJ   rW   appendrX   rV   rN   r+   rE   rD   )callbackcbr[   s      r   register_sigint_fallbackr`      s
    . $&&? ""8,$((*!>D 	 N  8$"3NC D >&&v}}d;!5 %((*!>D "& DC >&&v}}d;!sQ   AE7C0 AE7D- D"D- *AE70)DE7
D*&D- -AE44E7c                   H    \ rS rSr\\S 5       5       r\\S 5       5       rSrg)DummyEventLoop   c              #      #    S v   g 7fNrH   )clss    r   pausedDummyEventLoop.paused   s
      	s   c              #   \   #    [        5          S v   S S S 5        g ! , (       d  f       g = f7fre   )r@   )rf   	quit_funcs     r   runningDummyEventLoop.running   s        s   ,	,
),rH   N)	__name__
__module____qualname____firstlineno__classmethodr   rg   rk   __static_attributes__rH   rI   r   rb   rb      s8         rI   rb   c                    [         R                  " 5       nUc%   [         R                  " 5       R                  U 5      nU(       a8  [	        US5      (       a'  U b$  [        UR                  5      [        U 5      :X  a  U$ [        $ !    NI= f)z\Return the correct GLibEventLoop or a dummy that just registers the
signal wakeup mechanism._context)asyncio_get_running_loopget_event_loop_policyget_event_loop_for_contextr
   hashrt   rb   )ctxloops     r   get_event_loopr|     st     $$&D|	002MMcRD j))?tDMM2d3i?K	s   $B B)
__future__r   r.   r(   r+   ru   rQ   
contextlibr   r    r   r   r&   r@   pyos_getsigrF   pyos_setsigPyOS_setsigrC   rD   rE   rG   rJ   rN   rS   rW   rV   r`   rb   r|   rH   rI   r   <module>r      s     & 	     . E,  
 F) F)R oooo 
FMM"f&@&@@$V]]3 > E E&;  <" <"~
 
rI   