+
    im              	           R R.t ^ RIt^ RIt^ RIt^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
Ht ^ RIHt ^RIHt ^ RIHt  ]! ]P$                  ]P$                  4      P&                  t ! R R	]P,                  4      t ! R
 R]P0                  4      t ! R R4      t ! R R4      t ! R R]P,                  4      t ! R R4      t]P<                  R8w  d]    ! R R ]]]P>                  4      t R t! ! R R]4      t" ! R R]PF                  4      t$ ! R R]4      t% ! R R]]PL                  4      t'ME ! R R ](4      t) ! R! R ]]]PT                  ])R"7      t  ! R# R]4      t" ! R$ R%]]PV                  4      t,]	PZ                  ! 4       ;_uu_ 4        ].! ]R&]/4      t0RRR4       ].! ]R'R( 4      t1].! ]R)R* 4      t2 ! R+ R]04      t3R#   ] d    ]P$                  P&                  t EL~i ; i  + '       g   i     LW; i),GLibEventLoopGLibEventLoopPolicyN)
coroutines)Mapping)contextmanager)_ossighelper)GLibc                   H   a a ] tR t^,t oRtV 3R ltR tR tR tRt	Vt
V ;t# )_IdleSourceziInternal helper source for idle task handling

The only advantage is that we can keep the source around.
c                f   < \        4       P                  4        Wn        V P                  R 4       R# )FN)super__init___loopset_can_recurse)selfloop	__class__s   &&+/usr/lib/python3/dist-packages/gi/events.pyr   _IdleSource.__init__2   s$    
U#    c                    V P                   P                  '       g   R# \        V P                   P                  4      R3# )FFr   r   _may_iteratebool_idle_tasksr   s   &r   prepare_IdleSource.prepare9   s2    zz&&&DJJ**+R//r   c                |    V P                   P                  '       g   R # \        V P                   P                  4      # Fr   r   s   &r   check_IdleSource.check?   s*    zz&&&DJJ**++r   c                V    V P                   P                  4        \        P                  # N)r   _glib_idle_dispatchr   SOURCE_CONTINUEr   callbackargss   &&&r   dispatch_IdleSource.dispatchE   s    

&&(###r   )r   )__name__
__module____qualname____firstlineno____doc__r   r   r"   r+   __static_attributes____classdictcell____classcell__r   __classdict__s   @@r   r
   r
   ,   s#     
$0,$ $r   r
   c                   R   a a ] tR t^Jt oRtV 3R ltR tR t]R 4       t	Rt
VtV ;t# )GLibTaskzThis is a simple asyncio.Task subclass that will be returned when using the
GLibEventLoop. It adds functionality to set the priority that is used to
iterate the task's coroutine.
c                f   < \        4       P                  ! V/ VB  \        P                  V n        R # r%   )r   r   r   PRIORITY_DEFAULT_glib_idle_priority)r   r*   kwargsr   s   &*,r   r   GLibTask.__init__P   s&    $)&)#'#8#8 r   c                B    \        V\        4      '       g   Q hWn        R# )z:Set the GLib priority used to iterate the task's coroutineN)
isinstanceintr;   r   prioritys   &&r   set_priorityGLibTask.set_priorityU   s    (C((((#+ r   c                    V P                   # )z:Get the GLib priority used to iterate the task's coroutiner;   rA   s   &&r   get_priorityGLibTask.get_priority[   s    '''r   c                    \        V3R V/VB # )r   )r8   )clsr   coror<   s   &&&,r   _factoryGLibTask._factory_   s    242622r   rF   )r-   r.   r/   r0   r1   r   rC   rG   classmethodrL   r2   r3   r4   r5   s   @@r   r8   r8   J   s2     
9
,( 3 3 3r   r8   c                      a a ] tR t^dt oRtR t]R 4       t]R 4       tR t	R t
V 3R ltR tR	 tR
 tR tR tR tRtVtV ;t# )_GLibEventLoopMixinau  Base functionally required for both proactor and selector.

The proactor/selector is always available through _selector, and we assume
it has the following extra functionality that we provide:
 * _source: the GSource subclass
 * _dispatching: boolean whether it is dispatching currently
 * attach/detach: add/remove the GSource from the main context

In principle, we simply override run_forever to call into GLib, with the
assumption that a GSource is registered which will then call back into
the python mainloop _run_once handler when needed. This in turn calls
self._selector.select(), which means we just need to make sure to return
our already prepared events at that point.

If no main_context is passed, then the current default main context will
be used when available. If the thread does not yet have any main context
set, then a main context will be created.

When creating an event loop like this, it should be used as a context
manager. This ensure that the main context is set for the thread, that
GLib routines will properly iterate the EventLoop and that no second
EventLoop for the same main context is created by accident.
c                   Vf   \         P                  P                  4       pVfa   \        P                  ! 4       \        P
                  ! 4       J d    \         P                  P                  4       pM\         P                  ! 4       pWn        \         P                  P                  V P                  R4      V n
        . V n        . V n        RV n        ^ V n        RV n        RV n        R # NF)r   MainContextget_thread_default	threadingcurrent_threadmain_threaddefault_contextMainLoopnew
_main_loop_quit_funcsr   r   _loop_enter_count_loop_was_set_ctx_was_set)r   main_contexts   &&r   r   _GLibEventLoopMixin.__init__}   s     ++>>@L#++-1F1F1HH $(#3#3#;#;#=L $(#3#3#5L$--++DMM5A!!""!r   c              #    "   V P                   '       g   Rx  R#  RV n         V P                  P                  4        Rx  RV n         V P                  P                  4        R#   RT n         T P                  P                  4        i ; i5i)zThis context manager ensures the EventLoop is *not* being iterated.

It purely exists to handle the case where python code iterates the main
context more gracefully.
NFT)r   	_selectordetachattachr   s   &r   paused_GLibEventLoopMixin.paused   sl         	$ %DNN!!# $DNN!!# !%DNN!!#s   B
%A$ #B
$#BB
c           	   #  
  "   V P                   P                  4       '       g   Q hV P                  P                  V4       V P	                  4       '       df    Rx  V P                   P                  4        V P                  P                  4        V P                  '       d   V P                  R,          ! 4        R# \        V R4      '       d   V P                  4        MV P                  4        V P                  V P                  4       \        P                  ! 4       V n        \         P"                  ! 4       p\         P$                  ! V P&                  V P(                  R7       \*        P,                  ! V 4        V P.                  P0                  P2                  '       d   Q hRV n        V P.                  P7                  4        \9        V 4      V n        V P:                  P7                  V P                   4       V P:                  P=                  R4       V P>                  '       d4   V P:                  PA                  V P>                  ^ ,          ^ ,          4       V ;_uu_ 4        Rx  RRR4       RV n        V P:                  PC                  4        RV n        V P.                  PE                  4        V P                   P                  4        RV n        \        V R4      '       d   V PG                  4        Mm\*        P,                  ! R4       \H        PJ                  ! \L        4      ;_uu_ 4        V P                  R4       RRR4       \         P$                  ! X!   RV n        V P                  P                  4        \O        V P                  4      ^ 8X  g   Q hR#   T P                   P                  4        T P                  P                  4        T P                  '       d   T P                  R,          ! 4        i i ; i  + '       g   i     EL; i  + '       g   i     L; i  RT n        T P:                  PC                  4        RT n        T P.                  PE                  4        T P                   P                  4        RT n        \        T R4      '       d   T PG                  4        M\*        P,                  ! R4       \H        PJ                  ! \L        4      ;_uu_ 4        T P                  R4       RRR4       M  + '       g   i     M; i\         P$                  ! X!   RT n        T P                  P                  4        \O        T P                  4      ^ 8X  g   Q hi ; i5i)zThis context manager ensures the EventLoop is marked as running
while other API is iterating its main context.
The passed quit function is used to stop all recursion levels when
stop() is called.
N_run_forever_setup)	firstiter	finalizerTzGLibEventLoop._idle_sourceFr   )(rY   acquirer]   append
is_runningreleasepop	_stoppinghasattrrj   _check_closed_set_coroutine_origin_tracking_debugrU   	get_ident
_thread_idsysget_asyncgen_hooksset_asyncgen_hooks_asyncgen_firstiter_hook_asyncgen_finalizer_hookasyncio_set_running_looprd   _source_dispatchingr   rf   r
   _idle_sourceset_namer   rC   destroyre   _run_forever_cleanup
contextlibsuppressAttributeErrorlen)r   	quit_funcold_agen_hookss   && r   running_GLibEventLoopMixin.running   s     }}$$&&&&	*??+%%'  $$&>>>$$R(* 4-..##%  //<'113DO 335N""7777 %%d+	.~~--::::: $DNN!!# +D 1D$$T]]3&&'CD!!..t/?/?/B1/EF  !&D%%' $DNN!!#MM!!#"DOt122))+))$/((8877> 9&&7!&  "t''(A---k %%'  $$&>>>$$R(* ":  98 !&D%%' $DNN!!#MM!!#"DOt122))+))$/((8877> 9888&&7!&  "t''(A---s   AU(N DU(;%P& !CP& #O?(P& 0B>U(.P AU(A!O<<U(?P	
	P& P#	U(&B?U%%T 	7	U% TAU%%U(c                :    \         P                  ! 4       R ,          # )i@B )r   get_monotonic_timer   s   &r   time_GLibEventLoopMixin.time   s    &&(722r   c                   V P                  4       '       g   \        P                  ! R \        4       V P                  RJ d   \        P                  ! R\        4       V P
                  '       d   ^ # V P                  '       dN   \        V P                  ^ ,          P                  V P                  4       ,
          R,          4      pV^ 8  d   V# ^ # R# )zkGLibEventLoop is iterated without being marked as running. Missing override or invalid use of existing API!TzXGLibEventLoop is not stopping properly. Missing override or invalid use of existing API!i  r   )
ro   warningswarnRuntimeWarningrr   _ready
_scheduledr@   _whenr   r   timeouts   & r   _get_timeout_ms#_GLibEventLoopMixin._get_timeout_ms   s      MM} >>T!MMj ;;;??? 4??1-33diikATIJG%l711	r   c                  <  VP                   P                  pV\        P                  8X  d   \        4       P                  WV4      # \        P                  ! WW4      pV P                  P                  WE34       V P                  P                  R  R7       V P                  P                  V P                  ^ ,          ^ ,          4       V#   \         d    \        P                  p Li ; i)c                     V ^ ,          # )     )xs   &r   <lambda>0_GLibEventLoopMixin._call_soon.<locals>.<lambda>  s    AaDr   )key)__self__r;   r   r   r:   r   
_call_soonr~   Handler   rn   sortr   rC   )r   r)   r*   contextrB   handler   s   &&&&  r   r   _GLibEventLoopMixin._call_soon  s    	-
  ((<<H t,,,7%%hg>>> 23.1 	&&t'7'7':1'=>  	-,,H	-s   C C+*C+c                j    V P                   '       g   Q hR V n         V P                  4        RV n         R# )FTN)r   	_run_oncer   s   &r   _glib_dispatch"_GLibEventLoopMixin._glib_dispatch  s0          " r   c                T   V P                   '       g   Q hV P                  4       ;_uu_ 4        V P                  P                  4       p. pV P                  '       dS   V P                  ^ ,          ^ ,          V8X  d4   VP                  V P                  P                  ^ 4      ^,          4       Kd  V F  pVP                  4        K  	  V P                  '       d4   V P                  P                  V P                  ^ ,          ^ ,          4       RRR4       R#   + '       g   i     R# ; ir   N)	r   rg   r   rG   r   rn   rq   _runrC   )r   rB   ready_handlesr   s   &   r   r&   '_GLibEventLoopMixin._glib_idle_dispatch'  s         
 [[]]((557HM"""t'7'7':1'='I$$T%5%5%9%9!%<Q%?@' ( !!..t/?/?/B1/EF ]]]s   .DA<D3DD'	c                l    R V n         V P                  '       d   V P                  R,          ! 4        R# R# )TNr   )rr   r]   r   s   &r   stop_GLibEventLoopMixin.stop;  s+    R " r   c                    R V P                   P                   RV P                  4        RV P                  4        RV P	                  4        R\        V P                  4      R R\        V P                  4      R R2# )<z	 running=z closed=z debug=z ctx=0xXz loop=0x>)r   r-   ro   	is_closed	get_debughashrY   r\   r   s   &r   __repr___GLibEventLoopMixin.__repr__A  sy    ''(	$//2C1D Enn&'wt~~/?.@ A$--(+8D4I!3LAO	
r   c                .   V P                   ^ 8  d   V ;P                   ^,          un         R# V P                  4       '       g#   \        P                  ! 4       e   \	        R4      h\
        P                  P                  4       pVfK   \        P                  ! 4       \        P                  ! 4       J d   \
        P                  P                  4       pVe   \        V4      \        P                  9   d   \        P                  \        V4      ,          P                  4       '       g]   \        P                  \        V4      ,          V Jd1   \	        R\        P                  \        V4      ,           RV  R24      hRV n        M&V \        P                  \        V P"                  4      &   \        V4      \        V P"                  4      8w  d1   \
        P                  P%                  V P"                  4       RV n        V ;P                   ^,          un         R# )r   Nz%Thread already has a python EventLoopz:A GLibEventLoop is already registered through the policy (z, self=)T)r^   ro   r~   _get_running_loopRuntimeErrorr   rS   rT   rU   rV   rW   rX   r   r   _loopsr   r_   rY   push_thread_defaultr`   r   ctxs   & r   	__enter___GLibEventLoopMixin.__enter__J  s   !!A%""a'"  W%>%>%@%LFGG 113;93359N9N9PP""**,C OS	0777'..tCy9CCEE"))$s)4D@"PQdQkQklpqtluQvPww~  @D  E  EF  G  "&D>B&&tDMM':;9T]]++00? $D!#r   c                \   V ;P                   ^,          un         V P                   ^ 8X  d   V P                  '       g%   \        P                  \	        V P
                  4       V P                  '       d*   \        P                  P                  V P
                  4       RV n        RV n        R# R# )   FN)
r^   r_   r   r   r   rY   r`   r   rS   pop_thread_default)r   exc_type	exc_value	tracebacks   &&&&r   __exit___GLibEventLoopMixin.__exit__m  s}    !#!!Q&%%%'..tDMM/BC     33DMMB!&D %D 'r   )rY   r`   r   r   r^   r_   r\   r   r]   rr   rx   )r-   r.   r/   r0   r1   r   r   rg   r   r   r   r   r   r&   r   r   r   r   r2   r3   r4   r5   s   @@r   rP   rP   d   sn     0"0 $ $& C. C.J3,.!G(#
!$F& &r   rP   c                   &   a  ] tR tRt o R tRtV tR# )_GLibEventLoopRunMixinix  c           	        V P                  4       '       d   \        R 4      h\        P                  ! V P                  P
                  4      ;_uu_ 4        V P                  V P                  P
                  4      ;_uu_ 4        \        V P                  4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)z"This event loop is already runningN)ro   r   r   register_sigint_fallbackr\   quitr   g_main_loop_runr   s   &r   run_forever"_GLibEventLoopRunMixin.run_forever  s    ??CDD 11$//2F2FGGLL--..DOO, / HG.. HGGs$   .B=B*	B=*B:5B==C	r   N)r-   r.   r/   r0   r   r2   r3   r6   s   @r   r   r   x  s     	- 	-r   r   c                   H   a a ] tR tRt oRtV 3R ltR tR tR tRt	Vt
V ;t# )_SourceBasei  z3Common Source functionality for both unix and win32c                   < \        4       P                  4        R V n        V P                  R 4       V P	                  R4       \
        P                  ! V4      V n        . V n        R# )Fzpython asyncio integrationN)	r   r   r   r   r   weakrefrefrd   r   )r   selectorr   s   &&r   r   _SourceBase.__init__  sM    !
 	U#23 X.r   c                6    V P                  4       P                  # r%   )rd   r   r   s   &r   r   _SourceBase._loop  s    ~~%%%r   c                    R V n          V P                  4       P                  4        RV n         \        P                  #   RT n         i ; i)TF)r   r   r   r   r'   r(   s   &&&r   r+   _SourceBase.dispatch  sA     	&JJL'') %D### !&Ds	   > 	Ac                f    V P                   '       g   \        R 4      hV P                  p. V n        V# )z>gi.asyncio.Selector.select only works while it is dispatching!)r   r   r   )r   readys   & r   
_get_ready_SourceBase._get_ready  s5       P  r   )r   r   rd   )r-   r.   r/   r0   r1   r   r   r+   r   r2   r3   r4   r5   s   @@r   r   r     s!     =&$ r   r   c                   \   a a ] tR tRt oRtV 3R ltV 3R ltRR ltRV 3R lltRt	Vt
V ;t# )	_SelectorMixini  z>A Mixin for common functionality of the Selector and Proactor.c                ~   < \        4       P                  4        Wn        W n        / V n        \        V 4      V n        R # r%   )r   r   rY   r   
_fd_to_key_Sourcer   r   r   r   r   s   &&&r   r   _SelectorMixin.__init__  s-    
t}r   c                   < V P                   '       d=   \        V P                   4      '       d"   V P                   P                  4        R V n         \        4       P	                  4        R # r%   )r   r   r   r   close)r   r   s   &r   r   _SelectorMixin.close  s<    <<<D..LL  "DLr   c                6    V P                   P                  4       # r%   )r   r   r   s   &&r   select_SelectorMixin.select  s    ||&&((r   c                6   < \        4       P                  V4      # r%   )r   r   )r   r   r   s   &&r   _real_select_SelectorMixin._real_select  s    w~~g&&r   )rY   r   r   r   r%   )r-   r.   r/   r0   r1   r   r   r   r   r2   r3   r4   r5   s   @@r   r   r     s!     H%)' 'r   r   win32c                      a a ] tR tRt oRt]P                  ]P                  ]P                  ]P                  ]P                  ]P                  0tR	R ltV 3R ltV 3R ltR tV 3R ltRtVtV ;t# )
r   i  ziAn asyncio event loop that runs the python mainloop inside GLib.

Based on the asyncio.SelectorEventLoop
c                    \         P                  W4       / V n        \        V P                  V 4      p\
        P                  P                  W4       R V n        \        P                  V n
        R# gMbP?N)rP   r   _GLibEventLoop__signal_handlers	_SelectorrY   r~   SelectorEventLoop_clock_resolutionr8   rL   _task_factory)r   ra   r   s   && r   r   GLibEventLoop.__init__  sX    ((< &(D" 5H%%..t> &*D" "*!2!2Dr   c                  < \         P                  ! V4      '       g   \         P                  ! V4      '       d   \        R4      hV P	                  4        WP
                  9  d   \        4       P                  ! W.VO5!  # V P                  P                  VR4      ^ ,          pV'       d   VP                  4        \        P                  ! V4      pVP                  RV 24       VP                  \        P                  4       VP!                  V P"                  4       VP%                  V P&                  V4       WBV3V P                  V&   ?R# )zAdd a handler for UNIX signalz3coroutines cannot be used with add_signal_handler()Nzasyncio signal watch for )NNN)r   iscoroutineiscoroutinefunction	TypeErrorrt   _GLIB_SIGNALSr   add_signal_handlerr   getr   r   unix_signal_source_newr   rC   PRIORITY_HIGHrf   rY   set_callback
_signal_cb)r   sigr)   r*   sourcer   s   &&&* r   r
   GLibEventLoop.add_signal_handler  s   %%h//:3Q3Q4 4   UVV 
 ,,,w11#G$GG ++//5GHKF  005FOO7u=> 2 23MM$--(5+1T*BD""3'r   c                  < WP                   9  d   \        4       P                  V4      #  V P                  V,          w  p pV P                  V VP	                  4        VP                  4        V\        P                  8X  dr   \        P                  ! \        P                  4      ^ 8X  dI   \        P                  ^ 8  d4   \        P                  ! \        P                  \        P                  4       R#   \         d     R# i ; i)r   TF)r	  r   remove_signal_handlerr   r   _clear_boxedsignalSIGINTr   PyOS_getsigstartup_sigint_ptrPyOS_setsigKeyError)r   r  r  _r   s   &&  r   r  #GLibEventLoop.remove_signal_handler  s    ,,,w44S99#55c:1**3/ ##% 6==($00?1D$77!; ,,|'F'F  s   C
C8 8DDc                j    V P                   P                  V4      w  r#pV P                  ! V.VO5!   R # r%   )r   r  	call_soon)r   r  r   cbr*   s   &&   r   r  GLibEventLoop._signal_cb8  s0     $ 6 6 : :3 ?G NN2%%r   c                   < \        4       P                  4        \        V P                  4       F  pV P	                  V4       K  	  R # r%   )r   r   listr   r  )r   sr   s   & r   r   GLibEventLoop.close>  s1    GMMO$001**1- 2r   )__signal_handlersr  r  r%   )r-   r.   r/   r0   r1   r  SIGHUPr  SIGTERMSIGUSR1SIGUSR2SIGWINCHr	  r   r
  r  r  r   r2   r3   r4   r5   s   @@r   r   r     s[     	 MMMMNNNNNNOO
,	3 	<	6	&	. 	.r   c                 R    \        V \        4      '       d   V # V P                  4       # r%   )r?   r@   fileno)fileobjs   &r   _fileobj_to_fdr/  C  s!    gs##N~~r   c                   ,   a  ] tR tRt o R tR tRtV tR# )r   iI  c                F    V P                  4       P                  4       pR V3# r!   )r   r   r   s   & r   r   _Source.prepareJ  s"    jjl224G '>!r   c                B   . pV P                  4       P                  P                  4        F  pV P                  VP                  4      p^ pV\
        P                  P                  ( ,          '       d   V\        P                  ,          pV\
        P                  P                  ( ,          '       d   V\        P                  ,          pV'       g   K  VP                  W$34       K  	  Wn        V P                  4       P                  4       pV^ 8X  d   R# \!        V4      # )r   T)rd   r   valuesquery_unix_fd_tagr   IOConditionOUT	selectors
EVENT_READINEVENT_WRITErn   r   r   r   r   )r   r   r   	conditioneventsr   s   &     r   r"   _Source.checkQ  s    E~~'2299; ..sxx8	 0 0 4 4444i222F 0 0 3 3333i333F6LL#/ <  Kjjl224G!|;r   )r   N)r-   r.   r/   r0   r   r"   r2   r3   r   s   @r   r   r   I  s     	"	 	r   r   c                       ] tR tRtRtR# )_SelectorKeyif  r   N)r-   r.   r/   r0   r2   r   r   r   rA  rA  f  s    r   rA  c                   B   a  ] tR tRt o R tR tR	R ltR tR tRt	V t
R# )
_FileObjectMappingij  c                    Wn         R # r%   fd_dict)r   rF  s   &&r   r   _FileObjectMapping.__init__k  s    "Lr   c                ,    \        V P                  4      # r%   )r   rF  r   s   &r   __len___FileObjectMapping.__len__n  s    t||$$r   Nc                N    \        V4      pV P                  P                  W24      # r%   )r/  rF  r  )r   r.  rX   fds   &&& r   r  _FileObjectMapping.getq  s!    (B<<##B00r   c                N    V P                  V4      pVf   \        V: R24      hV# )Nz is not registered)r  r  )r   r.  values   && r   __getitem___FileObjectMapping.__getitem__u  s-    HHW%E}',>?@@Lr   c                ,    \        V P                  4      # r%   )iterrF  r   s   &r   __iter___FileObjectMapping.__iter__{  s    %%r   rE  r%   )r-   r.   r/   r0   r   rI  r  rP  rT  r2   r3   r   s   @r   rC  rC  j  s#     	#	%	1		& 	&r   rC  c                   d   a a ] tR tRt oRtV 3R ltR tR tR tRR lt	R t
R	 tR
 tRtVtV ;t# )r   i~  zGA Selector for gi.events.GLibEventLoop registering python IO with GLib.c                n   < \        4       P                  W4       \        V P                  4      V n        R # r%   )r   r   rC  r   _mapr   s   &&&r   r   _Selector.__init__  s#    GW+*4??;DIr   c                d    V P                   P                  V P                  P                  4       R # r%   )r   rf   r   rY   r   s   &r   rf   _Selector.attach  s    LL

 3 34r   c                    V P                   P                  4        \        V 4      V n         V P                  P	                  4        F  pV P                  V4       K  	  R # r%   )r   r   r   r   r4  _register_key)r   r   s   & r   re   _Selector.detach  sB    LL  ""4=DL--/""3' 0r   c                   \         P                  ! ^ 4      pVP                  \        P                  ,          '       d"   V\         P                  P
                  ,          pVP                  \        P                  ,          '       d"   V\         P                  P                  ,          pV P                  P                  VP                  V4      Vn        R# r   )r   r7  r>  r9  r:  r;  r<  r8  r   add_unix_fdrL  r6  )r   r   r=  s   && r   r]  _Selector._register_key  s    ((+IzzI0000T--000	zzI1111T--111	||//	BCHr   c                J   V'       d4   V\         P                  \         P                  ,          ( ,          '       d   \        R V: 24      h\	        V4      pW@P
                  9   d   \        V: RV R24      h\        WW#4      pV P                  V4       WPP
                  V&   V# )zInvalid events: z (FD z) is already registered)	r9  r:  r<  
ValueErrorr/  r   r  rA  r]  )r   r.  r>  datarL  r   s   &&&&  r   register_Selector.register  s    9//)2G2GGHHH #3F:!>??(B__$'E"5LMNNwF9Cs#"%OOBJr   c                    \        V4      pV P                  V,          pV P                  '       dA   \        V P                  4      '       d&   V P                  P	                  VP
                  4       V P                  V V# r%   )r/  r   r   r   remove_unix_fdr6  )r   r.  rL  r   s   &&  r   
unregister_Selector.unregister  sZ    (B//"%C
 |||T\\ 2 2++CHH5#Jr   c                (    V P                   V,          # r%   rX  )r   r.  s   &&r   get_key_Selector.get_key  s    99W%%r   c                    V P                   # )zGReturn a mapping of file objects or file descriptors to
selector keys.
rl  r   s   &r   get_map_Selector.get_map  s     99r   )rX  r   r%   )r-   r.   r/   r0   r1   r   rf   re   r]  re  ri  rm  rp  r2   r3   r4   r5   s   @@r   r   r   ~  s6     U	<	5	(	C	"	 	&	 	r   r   c                   &   a  ] tR tRt o R tRtV tR# )_PushRunMixinBackMetai  c                    \         P                  V 4      pVP                  \        4      p. VR V OW^,           ,          NW,          NW^,           R  O# r%   )typemroindexr   )rJ   rv  idxs   &  r   rv  _PushRunMixinBackMeta.mro  sN    ((3-C))23CHS#YH!GHchH1WYHHr   r   N)r-   r.   r/   r0   rv  r2   r3   r   s   @r   rs  rs    s     
	I 	Ir   rs  c                   .   a  ] tR tRt o RtRR ltRtV tR# )r   i  zvAn asyncio event loop that runs the python mainloop inside GLib.

Based on the asyncio.WindowsProactorEventLoopPolicy
Nc                    \         P                  W4       \        V P                  V 4      p\        P
                  P                  W4       R V n        \        P                  V n	        R# r   )
rP   r   	_ProactorrY   r~   ProactorEventLoopr  r8   rL   r  )r   ra   proactors   && r   r   r    sN    ((< 5H%%..t> &*D" "*!2!2Dr   )r  r  r%   )r-   r.   r/   r0   r1   r   r2   r3   r   s   @r   r   r     s     		3 	3r   )	metaclassc                   J   a a ] tR tRt oV 3R ltR tR tR tR tRt	Vt
V ;t# )r   i  c                H   < \        4       P                  V4       R V n        R # r%   )r   r   _poll_fd)r   r~  r   s   &&r   r   _Source.__init__  s    GX& !DMr   c                    V P                   e   Q h\        P                  ! V P                  4       P                  \        P
                  4      V n         V P                  V P                   4       R # r%   )r  r   PollFDrd   _iocpIO_INadd_pollr   s   &r   enable_Source.enable  sE    ==((( KK(8(>(>

KDMMM$--(r   c                J    V P                  V P                  4       R V n        R # r%   )remove_pollr  r   s   &r   disable_Source.disable  s    T]]+ DMr   c                    V P                   f   R# V P                  4       P                  4       p\        V P                  4      V3# )Nr   )r  r   r   r   r   r   s   & r   r   r2    s:    }}$  jjl224G$g--r   c                4   V P                   f   R# V P                   P                  '       d9   V P                  P                  V P	                  4       P                  ^ 4      4       V P                  '       d   R# V P                  4       P                  4       ^ 8H  # )NFT)r  reventsr   extendrd   r   r   r   r   s   &r   r"   r?    si    }}$}}$$$""4>>#3#@#@#CD{{{::<//1Q66r   )r  )r-   r.   r/   r0   r   r  r  r   r"   r2   r3   r4   r5   s   @@r   r   r     s#     	!	)	!	.
	7 
	7r   c                   B   a a ] tR tRt oRtV 3R ltR tR tRtVt	V ;t
# )r|  i  zGA Proactor for gi.events.GLibEventLoop registering python IO with GLib.c                   < \        4       P                  W4       \        V 4      V n        V P                  P	                  V4       R # r%   )r   r   r   r   rf   r   s   &&&r   r   _Proactor.__init__  s2    GW+ #4=DLLL(r   c                :    V P                   P                  4        R # r%   )r   r  r   s   &r   rf   _Proactor.attach  s    LL!r   c                :    V P                   P                  4        R # r%   )r   r  r   s   &r   re   _Proactor.detach  s    LL  "r   )r   )r-   r.   r/   r0   r1   r   rf   re   r2   r3   r4   r5   s   @@r   r|  r|    s     U	)	"	# 	#r   r|  AbstractEventLoopPolicyset_event_loop_policyc                      R # r%   r   r   r   r   r   r   %      4r   get_event_loop_policyc                      R # r%   r   r   r   r   r   r   &  r  r   c                      a  ] tR tRt o Rt/ tRtR tR tR t	]
RR l4       t]
RR l4       tR	 tR
 tR tR t]P$                  R8w  d$   ]! ]R4      '       d   ]
R 4       tRtV tR# RtV tR# RtV tR# )r   i)  a  An asyncio event loop policy that runs the GLib main loop.

NOTE: Python 3.16 is removing the concept of the event loop policy.
FIXME: say what to do in the future

The policy allows creating a new EventLoop for threads other than the main
thread. For the main thread, you can use get_event_loop() to retrieve the
correct mainloop and run it.

Note that, unlike GLib, python does not support running the EventLoop
recursively. You should never iterate the GLib.MainContext from within
the python EventLoop as doing so prevents asyncio events from being
dispatched.

As such, do not use API such as GLib.MainLoop.run or Gtk.Dialog.run.
Instead use the proper asynchronous patterns to prevent entirely blocking
asyncio.
Nc                    R V n         R # r%   )!_GLibEventLoopPolicy__orig_policyr   s   &r   r   GLibEventLoopPolicy.__init__A  s
    !r   c                &    V P                  RR7      # )a  Get the event loop for the current context.

Returns an event loop object for the thread default GLib.MainContext
or in case of the main thread for the default GLib.MainContext.

An exception will be thrown if there is no GLib.MainContext for the
current thread. In that case, using new_event_loop() will create a new
main context and main loop which can subsequently attached to the thread
by calling set_event_loop().

Returns a new GLibEventLoop or raises an exception.
Tforce_implicit)_get_event_loopr   s   &r   get_event_loop"GLibEventLoopPolicy.get_event_loopD  s     ##4#88r   c                (    V P                  VRR7      # )*Get the event loop for a specific context.Tr  )_get_event_loop_for_contextr   s   &&r   get_event_loop_for_context.GLibEventLoopPolicy.get_event_loop_for_contextS  s    //D/IIr   c                t   \         P                  P                  4       pVfK   \        P                  ! 4       \        P
                  ! 4       J d   \         P                  P                  4       pVf8   V'       g   R # \        R\        P                  ! 4       P                  : R24      hV P                  W!R7      # )Nz(There is no main context set for thread .r  )
r   rS   rT   rU   rV   rW   rX   r   namer  )rJ   r  r   s   && r   r  #GLibEventLoopPolicy._get_event_loopW  s     113;93359N9N9PP""**,C ;!:9;S;S;U;Z;Z:]]^_  ..s.RRr   c                    V P                   \        V4      ,          pVP                  4       '       g   V#  V'       gQ   \        P
                  ! 4       ;_uu_ 4        \        \        4       \        4      '       g    RRR4       R#  RRR4       \        V4      V P                   \        V4      &   V P                  '       dY   V\        P                  P                  4       8X  d6   V P                  P                  V P                   \        V4      ,          4       V P                   \        V4      ,          #   \         d     ELi ; i  + '       g   i     L; i)r  N)r   r   r   r  r   catch_warningsr?   _get_event_loop_policyr   r   _child_watcherr   rS   rX   attach_loop)rJ   r   r  r   s   &&& r   r  /GLibEventLoopPolicy._get_event_loop_for_contextk  s    	::d3i(D>>## $
 ((**!"8":<OPP +*P + !.c 2

49#)9)9)A)A)C"C**3::d3i+@Azz$s)$$  		 +*s   3D6  E6EEE	c                N   Ve   \        V\        4      '       g   Q h\        P                  P	                  4       ;r#VfK   \
        P                  ! 4       \
        P                  ! 4       J d   \        P                  P                  4       pVf   V P                  P                  \        V4      R4      pV'       dj   \        VP                  4      \        V4      8w  d   \        P                  ! R\        4       V'       d"   \        P                  P!                  V4       R# R# R# V'       d.   \#        R\
        P                  ! 4       P$                  : R24      h\        P                  P'                  VP                  4       WP                  \        VP                  4      &   R# )zSet the event loop for the current context (python thread) to loop.

This is only permitted if the thread has no thread default main context
with the main thread using the default main context.
Nz<GMainContext was changed unknowingly by asyncio integration!zThread zN already has a main context, get_event_loop() will create a new loop if needed)r?   r   r   rS   rT   rU   rV   rW   rX   r   rq   r   rY   r   r   r   r   r   r  r   )r   r   r   ctx_tdolds   &&   r   set_event_loop"GLibEventLoopPolicy.set_event_loop  s3    |z$>>>>''::<<;93359N9N9PP""**,C<++//$s)T2C%c2MMV& $$77?   "i668==@ AH H 
 00?/3KKT]]+,r   c                >    \        \        P                  ! 4       4      # )zICreate and return a new event loop that iterates a new
GLib.MainContext.
)r   r   rS   r   s   &r   new_event_loop"GLibEventLoopPolicy.new_event_loop  s     T--/00r   c                    \         P                  ! 4       ;_uu_ 4        \        4       V n        \	        V 4       R R R 4       V #   + '       g   i     T # ; ir%   )r   r  r  r  _set_event_loop_policyr   s   &r   r   GLibEventLoopPolicy.__enter__  s@    $$&&!7!9D"4( ' 	 '& s   AA	c                   V P                   P                  4        F  pVP                  4        K  	  \        P                  ! 4       ;_uu_ 4        \        V P                  4       R R R 4       R#   + '       g   i     R# ; irR   )r   r4  r   r   r  r  r  )r   r   r   r   r   s   &&&& r   r   GLibEventLoopPolicy.__exit__  s[    
 KK&&(DJJL ) $$&&"4#5#56 ' 	 '& s   A//B 	r   get_child_watcherc                   V P                   fp   \        P                  ! 4       V n         \        P                  ! 4       \        P
                  ! 4       J d*   V P                   P                  V P                  4       4       V P                   # r%   )r  r~   ThreadedChildWatcherrU   rV   rW   r  r  )rJ   s   &r   r  %GLibEventLoopPolicy.get_child_watcher  sb    !!)%,%A%A%C"++-1F1F1HH&&2233F3F3HI%%%r   )__orig_policyr!   )r-   r.   r/   r0   r1   r   r  r   r  r  rN   r  r  r  r  r   r   ry   platformrs   r  r  r2   r3   r   s   @r   r   r   )  s     & FN"9J S S& % %,!4F1. ||w7!4$ $ 
	& 
	&$r   )4__all__r   ry   r~   r   r  rU   r9  r   r   collections.abcr   r    r   gi.repositoryr   r   rZ   runr   r   Sourcer
   Taskr8   rP   r   r   r   r  r  r   r/  r   SelectorKeyrA  rC  BaseSelectorr   ru  rs  r}  IocpProactorr|  r  getattrobjectr  r  r  r   r   r   r   <module>r     s  * 1
2  
        # %  (DMM4==9==O
$$++ $<3w|| 34Q& Q&h- -&'$++ 'T' '4 <<7p.3W5N5Np.d + :y,, &W &(ANI$:$: AL	I 	I3!!'	32$7+ $7L#NG$8$8 #( %g/H&Q  !*A<P  *A<P l&1 l&C  (mm''O(t s   'G	 G-	G*)G*-G=	