+
    RiB                     t    R t ^ RIt^ RIHt ^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
Ht R	R ltR tR tR tR tR# )
z*Patch asyncio to allow nested event loops.N)contextmanagersuppress)heappopc                    \        4        \        4        \        4        T ;'       g    \        P                  ! 4       p \        V 4       R# )z/Patch asyncio to make its event loop reentrant.N)_patch_asyncio_patch_policy_patch_tornadoasyncioget_event_loop_patch_looploops   &K/home/ubuntu/hermes-agent/venv/lib/python3.14/site-packages/nest_asyncio.pyapplyr      s1    O++7))+D    c                 6   RR/R lp RR lp\        \        R4      '       d   R# \        P                  R	8  d   \        P                  P
                  ;\        n        ;\        P                  n        \        P                  n        \        P                  P                  ;\        n
        ;\        P                  n        \        P                  n
        \        P                  R
8  de   \        P                  P                  P                  \        P                  n        \        P                  P                  P                  \        n        \        P                  R8  d"   V;\        n        ;\        n        \        n        V \        n        R\        n        R# )z:Patch asyncio module to use pure Python tasks and futures.debugFc          	      |   \         P                  ! 4       pVP                  V4       \         P                  ! V 4      p VP	                  V4      VP                  4       '       gM   VP                  4        \        \         P                  4      ;_uu_ 4        VP	                  V4       R R R 4       # #   + '       g   i     # ; i  TP                  4       '       g`   TP                  4        \        \         P                  4      ;_uu_ 4        TP	                  T4       R R R 4       i   + '       g   i     i ; ii ; iN)	r	   r
   	set_debugensure_futurerun_until_completedonecancelr   CancelledError)mainr   r   tasks   &$  r   run_patch_asyncio.<locals>.run   s    %%'u$$T*	2**4099;;g4455++D1 65 55 99;;g4455++D1 6555 s0   C B11CAD;D'		D;'D72	D;c                 ~    \         P                  ! 4       pVf$   \         P                  ! 4       P                  4       pV# r   )events_get_running_loopget_event_loop_policyr
   )
stacklevelr   s   & r   _get_event_loop'_patch_asyncio.<locals>._get_event_loop%   s1    '')<//1@@BDr   _nest_patchedNT)   )r'          r'      r)   )r'   	   r)   )hasattrr	   sysversion_infotasks_PyTaskTask_CTaskfutures	_PyFutureFuture_CFuture_current_tasks	all_tasksr    r$   r
   r   r&   )r   r$   s     r   r   r      s   
25 
2 w((
9$MM!!	" 	"w}}+gmm.@ OO%%	& 	&1GOO4J
)#'.}}'9'9'H'H$#MM..88
9$%4	5 	5!6"GK Gr   c                 V    R p \         P                  ! 4       pWP                  n        R# )z1Patch the policy to always return a patched loop.c                     V P                   P                  f-   V P                  4       p\        V4       V P	                  V4       V P                   P                  # r   )_local_loopnew_event_loopr   set_event_loop)selfr   s   & r   r
   %_patch_policy.<locals>.get_event_loop@   sF    ;;$&&(D%{{   r   N)r    r"   	__class__r
   )r
   policys     r   r   r   =   s#    ! ))+F&4#r   c                  aaa VV3R lpV3R lpV3R lp\         R 4       o\         R 4       oR p\        V R4      '       d   R# \        V \        P                  4      '       g   \        R	\        V 4      ,          4      hV P                  pWn        W%n	        W5n
        WEn        WEn        V P                  4       '       d   ^M^ Vn        \        P                   R
8H  ;'       d    \#        V\        P$                  4      Vn        \(        P*                  R8  d   VP,                  Vn        \(        P*                  R8  d   \        P0                  P2                  M\        P4                  P2                  oRVn        R# )z Patch loop to make it reentrant.c           	        < S! V 4      ;_uu_ 4        S! V 4      ;_uu_ 4         V P                  4        V P                  '       g   K%   RRR4       RRR4       RT n        R#   + '       g   i     L!; i  + '       g   i     L,; i)TNF)	_run_once	_stopping)r@   manage_asyncgens
manage_runs   &r   run_forever _patch_loop.<locals>.run_foreverN   sS    /55 >>>	  6
   65s(   A6!A#		A#	
A6#A3.A66B	c                   < S! V 4      ;_uu_ 4        \         P                  ! WR 7      pW!Jd   RVn        VP                  4       '       g&   V P	                  4        V P
                  '       g   K:   VP                  4       '       g   \        R4      hVP                  4       uuRRR4       #   + '       g   i     R# ; i)r   Fz+Event loop stopped before Future completed.N)r	   r   _log_destroy_pendingr   rF   rG   RuntimeErrorresult)r@   futurefrI   s   && r   r   '_patch_loop.<locals>.run_until_completeV   s    %%f8A).&ffhh >>>6688"AC C88: s   9B,B,0B,B,,B=	c                  < V P                   pV P                  pV'       d'   V^ ,          P                  '       d   \        V4       K.  V'       g   V P                  '       d   ^ MEV'       d=   \        \        V^ ,          P                  V P                  4       ,
          ^ 4      R4      MRpV P                  P                  V4      pV P                  V4       V P                  4       V P                  ,           pV'       d7   V^ ,          P                  V8  d   \        V4      pVP                  V4       K>  \        \        V4      4       Fb  pV'       g    RpR# VP!                  4       pVP                  '       d   K4  S	P#                  V R4      p VP%                  4        Ve   VS	V &   Kb  Kd  	  RpR#   Te   TS	T &   i i ; i)z]
Simplified re-implementation of asyncio's _run_once that
runs handles as they become ready.
iQ N)_ready
_scheduled
_cancelledr   rG   minmax_whentime	_selectorselect_process_events_clock_resolutionappendrangelenpopleftpop_run)
r@   ready	scheduledtimeout
event_listend_timehandle_	curr_task
curr_taskss
   &        r   rF   _patch_loop.<locals>._run_onced   sm   
 OO	IaL333I $...A@I S!""TYY[0!56;=	 	
 ^^**73
Z(99;!7!77IaL..9Y'FLL s5z"A  ]]_F$$$ 'NN46	5KKM !,+4
4( - #   !,+4
4( -s   F33F?c              3    "   V P                  4        V P                  p\        P                  ! 4       p \        P
                  ! 4       V n        \        P                  ! V 4       V ;P                  ^,          un        V P                  '       d*   V P                  f   V P                  V P                  4       Rx  Wn        \        P                  ! V4       V ;P                  ^,          un        V P                  '       d|   V P                  ^ 8X  di   V P                  eY   V P                  P                  pV P                  P                  4        Ve   V P                  P                  V4       RV n	        R# R# R# R#   Yn        \        P                  ! T4       T ;P                  ^,          un        T P                  '       dy   T P                  ^ 8X  dg   T P                  eX   T P                  P                  pT P                  P                  4        Te   T P                  P                  T4       RT n	        i i i i ; i5i)zSet up the loop for running.N)_check_closed
_thread_idr    r!   	threading	get_ident_set_running_loop_num_runs_pending_is_proactorloop_self_reading_future	call_soon_loop_self_reading_ovr   	_proactor_unregister)r@   old_thread_idold_running_loopovs   &   r   rI   _patch_loop.<locals>.manage_run   s     	!335	5'113DO$$T*""a'"$$$,,4NN4#:#:;+O$$%56""a'"$$$**a/ 55A2266B--446~222604D- B 0 % ,O$$%56""a'"$$$**a/ 55A2266B--446~222604D- B 0 %s   2IBF =CICIIc              3     "   \        \        R 4      '       g   R# \        P                  ! 4       p V P                  V P                  4       V P
                  e-   \        P                  ! V P                  V P                  R7       Rx  V P                  R4       V P
                  e   \        P                  ! V!   R# R#   T P                  R4       T P
                  e   \        P                  ! T!   i i ; i5i)get_asyncgen_hooksN)	firstiter	finalizerF)	r-   r.   r   _set_coroutine_origin_tracking_debug
_asyncgensset_asyncgen_hooks_asyncgen_firstiter_hook_asyncgen_finalizer_hook)r@   old_agen_hookss   & r   rH   %_patch_loop.<locals>.manage_asyncgens   s     s011//1
	8//<*&&";;";;= //6*&&7 + //6*&&7 +s   .C:AC 
7C:6C77C:c                    R# )z2Do not throw exception if loop is already running.N )r@   s   &r   _check_running#_patch_loop.<locals>._check_running   s    r   r&   NzCan't patch loop of type %sntTr*   )r   r-   
isinstancer	   BaseEventLoop
ValueErrortyperB   rJ   r   rF   r   _check_runnung
is_runningru   osname
issubclassProactorEventLooprv   r.   r/   _set_coroutine_wrapperr   r0   r8   r2   r&   )	r   rJ   r   rF   r   clsrm   rH   rI   s	   &     @@@r   r   r   K   s0   'R 5 54 8 8" t_%%dG11227$t*DEE
..C!O/M''!%!2!2AC
4FFJsG,E,EF 
)#-0-G-G*y( --.5ll.I.I Cr   c                     R\         P                  9   dg   ^ RIHp  \        P
                  V n        \        P
                  V P                  9  d+   V ;P                  \        P
                  3,          un        R# R# R# )zc
If tornado is imported before nest_asyncio, make tornado aware of
the pure-Python asyncio Future.
tornadoN)r.   modulestornado.concurrent
concurrentr	   r6   FUTURES)tcs    r   r   r      sM    
 CKK'NN	>>+JJ7>>++J ,  r   r   )__doc__r	   asyncio.eventsr    r   r.   rr   
contextlibr   r   heapqr   r   r   r   r   r   r   r   r   <module>r      s9    0   	 
  / $!N5DN	,r   