
    <|hQ                        d Z ddlmZmZ ddlZddlZddlZddlm	Z	 ddl
mZ 	 ddlmZ d ZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ eek\  Zg Z	 e  G d de!      Z" e"d      Z"d Z#d Z$d Z% G d de&      Z' G d de      Z( e'def e)e(jT                              Z( G d d e      Z+ G d! d"e      Z, G d# d$e      Z- G d% d&e      Z. G d' d(e      Z/ G d) d*e      Z0 G d+ d,e      Z1 G d- d.e      Z2 G d/ d0e      Z3 G d1 d2e      Z4y# e$ r, e	j                  rddlZ G d d	e      Zd
 Zd Znd Zd ZY w xY w# e$ r  G d de       ZY w xY w)3zb
Useful base classes for watchers. The available
watchers will depend on the specific event loop.
    )absolute_importprint_functionN)config)LazyOnClass)get_object_tracebackc                     | S N inits    R/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/_ffi/watcher.pytracemallocr      s        c                       e Zd ZdZd Zd Zy)_TBlinesc                 T    |D cg c]  }|j                          c}| _        y c c}w r	   )rstripr   )selfr   xs      r   __init__z_TB.__init__   s    278Qahhj8
8s   %c                     | j                   S r	   r   r   s    r   formatz
_TB.format"   s    zz!r   N)__name__
__module____qualname__	__slots__r   r   r
   r   r   r   r      s    "I9"r   r   c                 B     t        j                          fd       }|S )Nc                 b     | g|i | t        t        j                               | _        y r	   )r   	tracebackformat_stack_captured_malloc)r   argskwargsr   s      r   tracesztracemalloc.<locals>.traces&   s+    T+D+F+(+I,B,B,D(E%r   	functoolswraps)r   r'   s   ` r   r   r   %   s'    __T"F #F Mr   c                     | j                   S r	   )r$   )objs    r   r   r   ,   s    '''r   c                      y r	   r
   )_objs    r   r   r   0   s    r   c                     | S r	   r
   r   s    r   r   r   3   s    Kr   fsencode)_dbg)GEVENT_DEBUG_LEVEL)DEBUG)GEVENT_CORE_EVENTS)_NOARGSc                       e Zd ZdZy)ResourceWarningzPython 2 fallbackN)r   r   r   __doc__r
   r   r   r8   r8   G   s    r   r8   c                       e Zd Zd Zy)_NoWatcherResultc                      y)Nz<NoWatcher>r
   r   s    r   __repr__z_NoWatcherResult.__repr__L   s    r   N)r   r   r   r=   r
   r   r   r;   r;   J   s    r   r;   c                     g }|D ]'  \  }}|}| |z  r|j                  |       | | z  } | r' n | r|j                  t        |              dj                  |      S )N|)appendhexjoin)event_field
all_eventsresultflagstringc_flags         r   events_to_strrI   Q   sj    F$ vMM&!fW%K c+&'88Fr   c                 B     t        j                          fd       }|S )Nc                 L    | j                   rt        d       | g|i | y )Nznot while active)active
ValueError)r   r%   r&   funcs      r   nwznot_while_active.<locals>.nw`   s(    ;;/00T#D#F#r   r(   )rN   rO   s   ` r   not_while_activerP   _   s%    __T$ $ Ir   c                 B     t        j                          fd       }|S )Nc                 8    | j                   r |       S t        S r	   )_watcherr;   )r   rN   s    r   if_wzonly_if_watcher.<locals>.if_wh   s    ==:r   r(   )rN   rT   s   ` r   only_if_watcherrU   g   s%    __T    Kr   c                   :    e Zd ZdZdZdZd Zed        Zd Z	d Z
y)AbstractWatcherTypez
    Base metaclass for watchers.

    To use, you will:

    - subclass the watcher class defined from this type.
    - optionally subclass this type
    Nc                     |dk7  r$|j                  d      s| j                  |||       d|v rt        st        d      t        j                  | |||      S )Nwatcher_watcher_skip_ffi__del__z-CFFI watchers are not allowed to have __del__)get_fill_watcherALLOW_WATCHER_DEL	TypeErrortype__new__)clsnamebasescls_dicts       r   ra   zAbstractWatcherType.__new__~   sT    9X\\2E%FdE84 ):KLL||Cuh77r   c                    |j                  d      r|d d }dd}|j                  d      xs	  |d|      }d|vr|dz   |z   }||d<   n$|d   j                  |      s|dz   |d   z   }||d<   |dz   fd}t        j                  ||       |j                  d      s'|j                  d	      xs  |d	|d
      xs d}|fz  fd}	t        j                  ||	       |j                  d      xs  |d|d
      xs dfd}
t        j                  ||
       d }dD ])  }d|z   }||vst        j                  | |||             + y )N_c                 f    |D ]  }	 t        ||       c S  |rt        |       y # t        $ r Y ,w xY wr	   )getattrAttributeError)attrrd   errorbs       r   _mro_getz3AbstractWatcherType._fill_watcher.<locals>._mro_get   sL     "1d++
 $T**  & s   $	00_watcher_prefix_watcher_type
_is_activec                 0    t        | j                        S r	   )rj   _LIB)r   active_names    r   _watcher_is_activez=AbstractWatcherType._fill_watcher.<locals>._watcher_is_active   s    499k22r   _watcher_struct_name_watcher_struct_patternFz	struct %sc                 @    | j                   j                  dz         S )Nz *)_FFItypeof)r   watcher_struct_names    r   _watcher_struct_pointer_typezGAbstractWatcherType._fill_watcher.<locals>._watcher_struct_pointer_type   s    99##$7$$>??r   _watcher_callback_name_gevent_generic_callbackc                 P    | j                   j                  | j                        S r	   )rz   	addressofrt   )r   callback_names    r   _watcher_callbackz<AbstractWatcherType._fill_watcher.<locals>._watcher_callback   s    99&&tyy-@@r   c                        fd}||_         |S )Nc                 T    | j                   dz   z   }t        | j                  |      S )Nrg   )rq   rj   rt   )r   lib_namerc   s     r   methzCAbstractWatcherType._fill_watcher.<locals>._make_meth.<locals>.meth   s)    --3d:tyy(33r   )r   )rc   watcher_namer   s   `  r   
_make_methz5AbstractWatcherType._fill_watcher.<locals>._make_meth   s    4 )DMKr   )startstopr   	_watcher_)T)endswithr\   
startswithr   lazy)rb   rc   rd   re   ro   rp   watcher_typerv   watcher_struct_patternr}   r   r   	meth_namer   ru   r   r|   s                 @@@r   r]   z!AbstractWatcherType._fill_watcher   s    == 9D	+ #,,'89_XFWY^=_(**S047L(4H_%/*55oF*S08O3LLL(4H_%%4	3 	#56&ll+AB"&.ll3L&M '5)12KUTY)Z'5)4 # #9L?"J	@ 	#?@!&>? 7$%=ueL76 		A 	#45	 1 	PI+i7L8+  :i+NO	Pr   c                 8    | j                   j                  |      S r	   )rz   
new_handle)rb   r,   s     r   r   zAbstractWatcherType.new_handle   s    xx""3''r   c                 8    | j                   j                  |      S r	   )rz   new)rb   kinds     r   r   zAbstractWatcherType.new   s    xx||D!!r   )r   r   r   r9   rz   rt   ra   classmethodr]   r   r   r
   r   r   rW   rW   p   s9     DD8 ?P ?PB("r   rW   c                      e Zd ZdZdZdZdZeddefd       Z	d Z
ed        Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd ZdZdZdZdZdZdZdZd Zd Z d Z!d Z"e#rd Z$dZ%d Z&e'd        Z(d Z)e'd        Z*d Z+d Z, e'e+e,      Z-d Z.d Z/ e'e.e/      Z0d Z1d  Z2d! Z3e4d"        Z5 e'e3e5      Z6e'd#        Z7e'd$        Z8y)%rY   NTc                 \    || _         || _        || _        || _        | j	                          y r	   )loop_watcher__init_priority_watcher__init_args_watcher__init_ref_watcher_full_init)r   _looprefpriorityr%   s        r   r   zwatcher.__init__   s,    	'!r   c                     | j                   }| j                  }| j                  }| j                  |       || j	                  |       	 | j                  |       | j                  |       y #  d | _         xY wr	   )r   r   r   _watcher_create_watcher_ffi_set_priority_watcher_ffi_initrS   _watcher_ffi_set_init_ref)r   r   r   r%   s       r   r   zwatcher._watcher_full_init   sy    ''ooS!**84	""4( 	&&s+	
 !DMs   
A- -
A7c                      y r	   r
   )rb   ffi_watchers     r   _watcher_ffi_closezwatcher._watcher_ffi_close       r   c                 .    | j                         | _        y r	   )_watcher_newrS   r   r   s     r   r   zwatcher._watcher_create   s    ))+r   c                 J    t        |       j                  | j                        S r	   )r`   r   r}   r   s    r   r   zwatcher._watcher_new   s    Dz~~d??@@r   c                      y r	   r
   r   s     r   r   z!watcher._watcher_ffi_set_init_ref      r   c                      y r	   r
   r   r   s     r   r   z!watcher._watcher_ffi_set_priority  r   r   c                     t               r	   NotImplementedErrorr   r%   s     r   r   zwatcher._watcher_ffi_init      !##r   c                     t               r	   r   r   s    r   _watcher_ffi_startzwatcher._watcher_ffi_start  r   r   c                 d    | j                  | j                  j                  | j                         y r	   )_watcher_stopr   ptrrS   r   s    r   _watcher_ffi_stopzwatcher._watcher_ffi_stop  s    499==$--8r   c                     t               r	   r   r   s    r   _watcher_ffi_refzwatcher._watcher_ffi_ref  r   r   c                     t               r	   r   r   s    r   _watcher_ffi_unrefzwatcher._watcher_ffi_unref  r   r   c                 $    | j                          y r	   )r   r   s    r   _watcher_ffi_start_unrefz watcher._watcher_ffi_start_unref  s    
 	!r   c                 $    | j                          y r	   )r   r   s    r   _watcher_ffi_stop_refzwatcher._watcher_ffi_stop_ref  s    r   c                     | j                   y | j                          | j                   }d | _         | j                  || j                  j                         | j                  |       d | _        y r	   )rS   r   _watcher_set_datarz   NULLr   r   )r   rS   s     r   closezwatcher.close6  sU    == 		==x8)	r   c                     ||_         |S r	   )data)r   the_watcherr   s      r   r   zwatcher._watcher_set_dataA  s      r   c                     | S r	   r
   r   s    r   	__enter__zwatcher.__enter__H  s    r   c                 $    | j                          y r	   )r   )r   tvtbs       r   __exit__zwatcher.__exit__K  s    

r   c                     | j                   rct        |       }d}|$dj                  |j                               }d|z   }t	        j
                  d| |t               | j                          y y )N 
z
Traceback:
zFailed to close watcher )rS   r   rB   r   warningswarnr8   r   )r   r   tb_msgs      r   r[   zwatcher.__del__O  sa    }})$/>!YYryy{3F-6FfM-/ 

 r   Fc                    d| j                   j                  t        |       fz  }| j                  r|dz   S d| _        	 || j	                         }| j
                  r|dz  }| j                  Jt        | j                  dd       }|| u r|d| j                  j                  z  z  }n|d| j                  z  }| j                  |d| j                  z  }| j                  | j                  |d	z  }|d
| j                  z  z  }|d| j                  z  z  }|d| j                  z  z  }|dz   d| _        S # d| _        w xY w)Nz<%s at 0x%x>Tz pending__self__z# callback=<bound method %s of self>z
 callback=z args=z stoppedz watcher=%sz
 handle=%sz ref=%sF)	__class__r   id_watcher__in_repr_formatpendingcallbackrj   r%   rS   _watcher_handler   )r   basicrE   fselfs       r   r=   zwatcher.__repr__^  s6   !8!8"T( CC>>3; 	#$dlln5F||*$}}(z4@D=Ct}}G]G]^^F@@Fyy$		44}}$):*$mt}}55Fld&:&:;;Fi488,,FC<"DNUDNs   C0D6 6	D?c                 H    | j                   r| j                   j                  S y r	   )rS   r   r   s    r   r   zwatcher._watcher_handle{  s    ====%%% r   c                      y)Nr   r
   r   s    r   r   zwatcher._format  s    r   c                     t               r	   r   r   s    r   r   zwatcher.ref      !##r   c                 :    d| j                   v r| j                  S d S )N	_callback)__dict__r   r   s    r   _get_callbackzwatcher._get_callback  s    !,!=t~~G4Gr   c                 p    t        |      s|t        d|      |d| j                  v r| `y y || _        y )NzExpected callable, not r   )callabler_   r   r   )r   cbs     r   _set_callbackzwatcher._set_callback  s?    |2@AA:dmm+N ,  DNr   c                     | j                   S r	   )_argsr   s    r   	_get_argszwatcher._get_args  s    zzr   c                 t    t        |t              s|t        d      |d| j                  v r| `y y || _        y )Nzargs must be a tuple or Noner   )
isinstancetupler_   r   r   r   s     r   	_set_argszwatcher._set_args  sA    $&4+;:;;<$--'J ( DJr   c                 F   |t        d      || _        |xs t        | _        | j                  j
                  j                  |        | j                  | j                  t        |       j                  |             | _        | j                          | j                          y )Nz#callback must be callable, not None)r_   r   r6   r%   r   _keepalivesetaddr   rS   r`   r   _handler   r   )r   r   r%   s      r   r   zwatcher.start  s~    ABB OG			##D)--dmmT$Z=R=RSW=XY!%%'r   c                 ~   | j                   '| j                  | | j                  j                  vsJ y d | _         | j                          | j	                          | j                  j                  j                  |        d | _        | j                  | j                  | j                  j                         d | _        y r	   )r   r   r   r   r   discardr   r   rS   rz   r   r%   r   s    r   r   zwatcher.stop  s    == 99$DII4K4K(KKK 	""$ 		''-t}}diinn=	r   c                      y r	   r
   r   s    r   _get_priorityzwatcher._get_priority  s    r   c                      y r	   r
   r   s     r   _set_priorityzwatcher._set_priority  r   r   c                 T    | j                   | j                  | j                         ryy)NTF)rS   rv   r   s    r   rL   zwatcher.active  s#    ==$)@)@)Or   c                      y)NFr
   r   s    r   r   zwatcher.pending  s    r   )9r   r   r   r   r   rS   r   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rq   _watcher_init_watcher_startr   r}   r   rv   r   r   r   r   r^   r[   r   r=   propertyr   r   r   r   r   r   r   r   r%   r   r   r  rP   r  r   rL   r   r
   r   r   rY   rY      s   IEH G"&G " ",*  ,A$$9$$" 
 M M N M $(  	 	 I#: & & $ $H  }5H Iy)D(   }5H  
  r   rY   c                   4     e Zd ZdZd fd	Z fdZd Z xZS )IoMixinr   c                     |dk  rt        d|z        || j                   z  rt        d|z        || _        t        t        |   ||||xs ||f       y )Nr   zfd must be non-negative: %rzillegal event mask: %rr   r   r%   )rM   
EVENT_MASK_fdsuperr
  r   )r   r   fdeventsr   r   r   r   s          r   r   zIoMixin.__init__  sk     6:R?@@T__$$5>??gt%dh+0+@RL 	& 	Br   c                 x    |xs t         }|j                  d      r
t        f|z   }t        t        |   |g|  y )Npass_events)r6   r\   r5   r  r
  r   )r   r   r%   r&   r   s       r   r   zIoMixin.start  s9    w::m$&)D0Dgt"83d3r   c                      d| j                   z  S )Nz fd=%d)r  r   s    r   r   zIoMixin._format  s    $((""r   )TNN)r   r   r   r  r   r   r   __classcell__r   s   @r   r
  r
    s    J	B4#r   r
  c                   4     e Zd ZdZd fd	Z fdZd Z xZS )
TimerMixintimerc                 z    |dk  rt        d|z        || _        || _        t        t        |   |||||f       y )N        z#repeat must be positive or zero: %rr  )rM   _after_repeatr  r  r   )r   r   afterrepeatr   r   r   s         r   r   zTimerMixin.__init__  sH    C<BVKLLj$(3QVX^P_(`r   c                     |j                  d| j                  j                        }|r| j                  j                          t	        t
        |   |g|  y )Nupdate)r\   r   #starting_timer_may_update_loop_time
update_nowr  r  r   )r   r   r%   kwr!  r   s        r   r   zTimerMixin.start  sF    $))"O"OP II  "j$%h66r   c                     t               r	   r   )r   r   r%   r$  s       r   againzTimerMixin.again  r   r   )r  r  TN)r   r   r   rq   r   r   r&  r  r  s   @r   r  r    s    Ma7"$r   r  c                   $     e Zd ZdZd fd	Z xZS )SignalMixinsignalc                     |dk  s|t         j                  k\  rt        d|z        || _        t        t
        |   ||||f       y )N   zillegal signal number: %rr  )signalmoduleNSIGrM   
_signalnumr  r(  r   )r   r   	signalnumr   r   r   s        r   r   zSignalMixin.__init__  sM    q=I):)::89DEE $k4)$C(R[Q^)_r   )TN)r   r   r   rq   r   r  r  s   @r   r(  r(    s    M	` 	`r   r(  c                       e Zd ZdZy)	IdleMixinidleNr   r   r   rq   r
   r   r   r1  r1        Mr   r1  c                       e Zd ZdZy)PrepareMixinprepareNr3  r
   r   r   r6  r6    s    Mr   r6  c                       e Zd ZdZy)
CheckMixincheckNr3  r
   r   r   r9  r9    s    Mr   r9  c                       e Zd ZdZy)	ForkMixinforkNr3  r
   r   r   r<  r<  #  r4  r   r<  c                   ,    e Zd ZdZd Zd Zed        Zy)
AsyncMixinasyncc                     t               r	   r   r   s    r   sendzAsyncMixin.send*  r   r   c                 "    | j                         S )z
        Calling compatibility with ``greenlet.switch(arg)``
        as used by waiters that have ``rawlink``.

        This is an advanced method, not usually needed.
        )rB  )r   _ignoreds     r   send_ignoring_argzAsyncMixin.send_ignoring_arg-  s     yy{r   c                     t               r	   r   r   s    r   r   zAsyncMixin.pending6  r   r   N)r   r   r   rq   rB  rE  r  r   r
   r   r   r?  r?  '  s%    M$ $ $r   r?  c                   b     e Zd ZdZd	 fd	Zd Zed        Zed        ZdZ	dZ
ed        Z xZS )

ChildMixinTr   c                     |j                   st        d      |j                          || _        | j                  rt
        t        |   ||||f       y y )Nz5child watchers are only available on the default loop)r   r%   )defaultr_   install_sigchld_pid_CALL_SUPER_INITr  rH  r   )r   r   pidtracer   r   s        r   r   zChildMixin.__init__@  sQ    ||STT	  *d,Ts#u,N !r   c                 :    d| j                   d| j                  S )Nz pid=z	 rstatus=)rN  rstatusr   s    r   r   zChildMixin._formatH  s    '+xx>>r   c                     | j                   S r	   )rL  r   s    r   rN  zChildMixin.pidK  s    yyr   c                     | j                   S r	   )_rpidr   s    r   rpidzChildMixin.rpidO  s     zzr   Nc                     | j                   S r	   )_rstatusr   s    r   rQ  zChildMixin.rstatusW  s    }}r   )r   T)r   r   r   rM  r   r   r  rN  rU  rT  rW  rQ  r  r  s   @r   rH  rH  ;  s\     O?     EH r   rH  c                   p     e Zd Zed        Zd fd	Zed        Zed        Zed        Z	ed        Z
 xZS )	StatMixinc                     t        |       S r	   r0   )paths    r   _encode_pathzStatMixin._encode_path]  s    ~r   c                     | j                  |      | _        || _        | j                  j	                  d| j                        | _        || _        t        t        | '  |||| j
                  |f       y )Nzchar[]r  )
r\  _paths_pathrz   r   _cpath	_intervalr  rY  r   )r   r   r[  intervalr   r   r   s         r   r   zStatMixin.__init__a  sj    ''- 
 iimmHdkk:!i'3.2kk.6.8 	( 	9r   c                     | j                   S r	   )r_  r   s    r   r[  zStatMixin.pathv  s    zzr   c                     t         r	   r   r   s    r   rl   zStatMixin.attrz      !!r   c                     t         r	   r   r   s    r   prevzStatMixin.prev~  re  r   c                     | j                   S r	   )ra  r   s    r   rb  zStatMixin.interval  s    ~~r   )r  TN)r   r   r   staticmethodr\  r   r  r[  rl   rg  rb  r  r  s   @r   rY  rY  [  sj     9*   " " " "  r   rY  )5r9   
__future__r   r   r)  r,  r)   r   gevent._configr   gevent._utilr   r   r   ImportErrortrace_mallocr"   objectr   gevent._compatr1   gevent._ffir2   r3   r4   gevent._ffi.loopr5   r6   r^   __all__r8   	NameErrorWarningintr;   rI   rP   rU   r`   rW   rY   dictr   r
  r  r(  r1  r6  r9  r<  r?  rH  rY  r
   r   r   <module>rx     s  
 7    ! $%0H $  *  / $&%/ 
s 
 $A& ["$ ["z@f @D i&D9I9I4J
K#f #0$ $>`& ` 6   $ $( @) )M  	"& 	"		(		=b  ' s#   	D E -EEEE