
    tniR                    *   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dlm
Z
mZmZ d dlmZ d dlmZ d dlmZ erd dlmZ  ej        d          Z eed          r eed	          r eed
          sdej         Z ee            ej        eee
ed          d	ef          Z  ej        eeed          d
ef          Z  ej        ed          def          Z G d d          Z ed ej        ej         ej!        ej"        ej#        ej$        ej%        ej&        ej'        ej(        ej)        g          Z* G d dej+                  Z, ej-        e,          Z.dZ/e/e.dz   z  Z0 G d d          Z1 G d d          Z2dS )    )annotationsN)c_char_pc_intc_uint32)reduce)TYPE_CHECKING)UnsupportedLibcError)	Generatorinotify_initinotify_add_watchinotify_rm_watchz Unsupported libc version found: T)	use_errnoc                      e 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	e
z  ZdZdZdZdZdZdZdZdZdZ ed eeeeeee	e
eeeeg          ZdZdZdS )InotifyConstants                   @         i   i      i    i @  i   i   i   i   i    i   @l        c                    | |z  S N xys     Y/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/watchdog/observers/inotify_c.py<lambda>zInotifyConstants.<lambda>B   s
    QU     N)__name__
__module____qualname__	IN_ACCESS	IN_MODIFY	IN_ATTRIBIN_CLOSE_WRITEIN_CLOSE_NOWRITEIN_OPENIN_MOVED_FROMIN_MOVED_TO	IN_CREATE	IN_DELETEIN_DELETE_SELFIN_MOVE_SELFIN_MOVE
IN_UNMOUNTIN_Q_OVERFLOW
IN_IGNORED
IN_ONLYDIRIN_DONT_FOLLOWIN_EXCL_UNLINKIN_MASK_ADDIN_ISDIR
IN_ONESHOTr   IN_ALL_EVENTS
IN_CLOEXECIN_NONBLOCKr   r#   r!   r   r   !   s        IIIN!GMKIINL k)G JMJ JNNKHJ F	
 M& JKKKr#   r   c                    | |z  S r   r   r   s     r!   r"   r"   Z   s
    Q r#   c                  4    e Zd ZdZdefdefdefdefdeffZdS )InotifyEventStructa  Structure representation of the inotify_event structure
    (used in buffer size calculations)::

        struct inotify_event {
            __s32 wd;            /* watch descriptor */
            __u32 mask;          /* watch mask */
            __u32 cookie;        /* cookie to synchronize two events */
            __u32 len;           /* length (including nulls) of name */
            char  name[0];       /* stub for possible name */
        };
    wdmaskcookielennameN)r$   r%   r&   __doc__r   r   r   _fields_r   r#   r!   rB   rB   k   sH        
 
 
u		8		HHHr#   rB   r   r   c                     e Zd ZdZdddd)dZed*d            Zed+d            Zed,d            Zed*d            Z	d-dZ
d.dZd/dZd0dZd0dZd-dZedd1d Zd-d!Zd2d#Zd3d$Zed-d%            Zed4d(            ZdS )5Inotifya  Linux inotify(7) API wrapper class.

    :param path:
        The directory path for which we want an inotify object.
    :type path:
        :class:`bytes`
    :param recursive:
        ``True`` if subdirectories should be monitored; ``False`` otherwise.
    FN)	recursive
event_maskpathbytesrL   boolrM   
int | NonereturnNonec               6    t                      }|dk    rt                                           | _        t	          j                     _        d _        d _        t          j
                    \   _         _        t          t          d          rzt          j                     _         j                             j        t          j                    j                             j        t          j                   d
 fd}| _        nd
 fd}| _        i  _        i  _        | _        |t.          }| _        | _        t          j                            |          r                     |||	           n                     ||           i  _        d S )NFTpollrR   rP   c                 h    t           fd j                                        D                       S )Nc              3  4   K   | ]\  }}|j         k    V  d S r   _inotify_fd).0fd_selfs      r!   	<genexpr>z4Inotify.__init__.<locals>.do_poll.<locals>.<genexpr>   s/      SSeb!2!11SSSSSSr#   )any_pollerrV   r^   s   r!   do_pollz!Inotify.__init__.<locals>.do_poll   s4    SSSSt|?P?P?R?RSSSSSSr#   c                 f    t          j         j        j        gg g           } j        | d         v S Nr   )selectrZ   _kill_r)resultr^   s    r!   	do_selectz#Inotify.__init__.<locals>.do_select   s2    (8$,'GRPP'6!944r#   )rL   rR   rP   )r   rK   _raise_errorrZ   	threadingLock_lock_closed_is_readingospiperg   _kill_whasattrrf   rV   ra   registerPOLLIN_check_inotify_fd_wd_for_path_path_for_wd_pathWATCHDOG_ALL_EVENTS_event_mask_is_recursiverN   isdir_add_dir_watch
_add_watch_moved_from_events)r^   rN   rL   rM   
inotify_fdrc   ri   s   `      r!   __init__zInotify.__init__   s   !^^
  """%^%%
%'WYY"dl 66"" 	/!;==DLL!!$"2FMBBBL!!$,>>>T T T T T T &-D""5 5 5 5 5 5 &/D" /1.0
,J%&7== 	.jIFFFFOOD*---;=r#   intc                    | j         S )z)The event mask for this inotify instance.)r|   rb   s    r!   rM   zInotify.event_mask        r#   c                    | j         S )z.The path associated with the inotify instance.)rz   rb   s    r!   rN   zInotify.path   s     zr#   c                    | j         S )z0Whether we are watching directories recursively.)r}   rb   s    r!   is_recursivezInotify.is_recursive   s     !!r#   c                    | j         S )z9The file descriptor associated with the inotify instance.rY   rb   s    r!   r\   z
Inotify.fd   r   r#   c                    i | _         dS )z)Clear cached records of MOVED_FROM eventsN)r   rb   s    r!   clear_move_recordszInotify.clear_move_records   s    "$r#   destination_eventInotifyEventbytes | Nonec                P    |j         | j        v r| j        |j                  j        S dS )zThe source path corresponding to the given MOVED_TO event.

        If the source path is outside the monitored directories, None
        is returned instead.
        N)rE   r   src_path)r^   r   s     r!   source_for_movezInotify.source_for_move   s/     #t'>>>*+<+CDMMtr#   eventc                $    || j         |j        <   dS )z]Save this event as the source event for future MOVED_TO events to
        reference.
        N)r   rE   )r^   r   s     r!   remember_move_from_eventz Inotify.remember_move_from_event   s     16---r#   c                |    | j         5  |                     || j                   ddd           dS # 1 swxY w Y   dS )zeAdds a watch for the given path.

        :param path:
            Path to begin monitoring.
        N)rn   r   r|   )r^   rN   s     r!   	add_watchzInotify.add_watch   s     Z 	4 	4OOD$"2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   155c                    | j         5  | j                            |          }| j        |= t	          | j        |          dk    rt                                           ddd           dS # 1 swxY w Y   dS )zRemoves a watch for the given path.

        :param path:
            Path string for which the watch will be removed.
        rU   N)rn   rx   popry   r   rZ   rK   rk   )r^   rN   rC   s      r!   remove_watchzInotify.remove_watch   s     Z 	' 	'"&&t,,B!"% 0"55;;$$&&&		' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   AA**A.1A.c                8   | j         5  | j        srd| _        | j        | j        v r'| j        | j                 }t	          | j        |           | j        rt          j        | j	        d           n| 
                                 ddd           dS # 1 swxY w Y   dS )z?Closes the inotify instance and removes all associated watches.T   !N)rn   ro   rz   rx   r   rZ   rp   rq   writers   _close_resources)r^   rC   s     r!   closezInotify.close   s    Z 	, 	,< ,#:!222*4:6B$T%5r:::# , HT\40000))+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   A:BBB)event_buffer_sizer   list[InotifyEvent]c          	     D    d fd}d}	 	  j         5   j        rg cddd           S d _        ddd           n# 1 swxY w Y                                    rt	          j         j        |          } j         5  d	 _         j        r"                                  g cddd           S 	 ddd           n# 1 swxY w Y   nI# t          $ r<}|j	        t          j
        k    rY d}~|j	        t          j        k    rg cY d}~S  d}~ww xY w	  j         5  g }t                              |          D ]R\  }}}}	|d
k    r j        |         }
|	r t          j                            |
|	          n|
}t#          ||||	|          }|j        r                     |           n1|j        r)                     |          }| j        v r؉ j        |         } j        |= | j        |j        <   |j         j        |<    j        r j                                        D ]}|                    |t          j        j                                        z             rI j                            |          }|                    ||j                  }| j        |<   | j        |<   t          j                            |
|	          }t#          ||||	|          }|j        r3 j                            |          } j        |         |k    r j        |= |                     |            j        rZ|j!        rS|j"        rL	  #                    | j$                   n# t          $ r Y 0w xY w|%                     ||                     T	 ddd           n# 1 swxY w Y   |S )z*Reads events from inotify and yields them.r   rO   rR   r   c           
        g }t          j        |           D ]8\  }}}|D ]}t          j        t                    5  t           j                            ||          }                    |j                  }t          |t          j        t          j        z  d||          }|                    |           d d d            n# 1 swxY w Y   |D ]~}	t           j                            ||	          }j        t           j                            |                   }
t          |
t          j        d|	|          }|                    |           :|S re   )rq   walk
contextlibsuppressOSErrorrN   joinr   r|   r   r   r/   r;   appendrx   dirname)r   eventsrootdirnames	filenamesr   	full_pathwd_direfilenamewd_parent_dirr^   s              r!   _recursive_simulatez0Inotify.read_events.<locals>._recursive_simulate  s   F-/WX->-> % %)h	' ) )G#,W55 
) 
)$&GLLw$?$?	!%D<L!M!M(",69I9RR#%  a(((
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) !* 
% 
%H "T8 < <I$($5bgooi6P6P$QM$%(2 ! A MM!$$$$
% Ms   A;CC
Cr#   TNFrU   )r   rO   rR   r   )&rn   ro   rp   rw   rq   readrZ   r   r   errnoEINTREBADFrK   _parse_event_bufferry   rN   r   r   is_moved_fromr   is_moved_tor   rx   r   r   copy
startswithsepencoder   replace
is_ignoredr   is_directory	is_creater   r|   extend)r^   r   r   event_bufferr   
event_listrC   rD   rE   rG   wd_pathr   inotify_eventmove_src_pathmoved_wdrz   _move_to_pathrN   s   `                 r!   read_eventszInotify.read_events  s.   	 	 	 	 	 	8 	Z , ,| "!, , , , , , , , (,D$	, , , , , , , , , , , , , , , ))++ P#%74+;=N#O#OLZ " "',D$| "--///!" " " " " " " """ " " " " " " " " " " " " " "    7ek))HHHH7ek))IIIIII Z 1	E 1	EJ*1*E*El*S*S /E /E&D&$88+B/:>K27<<666G ,RvtX N N . S11-@@@@". S$($8$8$G$GM$(999#'#4]#C -m<DL)-*@A6C6L)(3, P)-):)?)?)A)A P P#(#3#3MBGKDVDVDXDX4X#Y#Y !P/3/@/D/DU/K/KH49MM-Q^Qg4h4hMGOD$5m$DBOD$5h$?!w||GT::H$0T64$R$RM + 4,0044D(."44 -d3!!-000$ E)C EH_ E!$2BCCCC" ! ! ! ! %%&9&9(&C&CDDD_/E1	E 1	E 1	E 1	E 1	E 1	E 1	E 1	E 1	E 1	E 1	E 1	E 1	E 1	E 1	Ef s   C 	<C <C A  C A 8C <$B: C .C :B>>C B>C 
DD*D DDDH#N;MN
M%!N$M%%#NNNc                    t          j        | j                   t          j        | j                   t          j        | j                   d S r   )rq   r   rZ   rg   rs   rb   s    r!   r   zInotify._close_resources  s?    
!"""

r#   rD   c                  t           j                            |          s7t          t          j        t          j        t          j                  |          |                     ||           |rvt          j        |          D ]c\  }}}|D ]X}t           j        	                    ||          }t           j        
                    |          rB|                     ||           YbdS dS )a&  Adds a watch (optionally recursively) for the given directory path
        to monitor events specified by the mask.

        :param path:
            Path to monitor
        :param recursive:
            ``True`` to monitor recursively.
        :param mask:
            Event bit mask.
        N)rq   rN   r~   r   r   ENOTDIRstrerrorr   r   r   islink)	r^   rN   rD   rL   r   r   r]   r   r   s	            r!   r   zInotify._add_dir_watch  s     w}}T"" 	K%-U])C)CTJJJd### 	5%'WT]] 5 5!h' 5 5G "T7 ; ;Iw~~i00 ! OOIt4444	5	5 	55 5r#   c                    t          | j        ||          }|dk    rt                                           || j        |<   || j        |<   |S )zAdds a watch for the given path to monitor events specified by the
        mask.

        :param path:
            Path to monitor
        :param mask:
            Event bit mask.
        rU   )r   rZ   rK   rk   rx   ry   )r^   rN   rD   rC   s       r!   r   zInotify._add_watch  sR     t/t<<88  """"$$ $"	r#   c                 8   t          j                    } | t          j        k    rt	          t          j        d          | t          j        k    rt	          t          j        d          | t          j        k    r"t	          | t          j        |                     dS )z#Raises errors for inotify failures.zinotify watch limit reachedzinotify instance limit reachedN)	ctypes	get_errnor   ENOSPCr   EMFILEEACCESrq   r   )errs    r!   rk   zInotify._raise_error  s       %,%,(EFFF%,%,(HIII%,#r{3//000 r#   r   &Generator[tuple[int, int, int, bytes]]c              #    K   d}|dz   t          |           k    rit          j        d| |          \  }}}}| |dz   |dz   |z                                d          }|d|z   z  }||||fV  |dz   t          |           k    gdS dS )a  Parses an event buffer of ``inotify_event`` structs returned by
        inotify::

            struct inotify_event {
                __s32 wd;            /* watch descriptor */
                __u32 mask;          /* watch mask */
                __u32 cookie;        /* cookie to synchronize two events */
                __u32 len;           /* length (including nulls) of name */
                char  name[0];       /* stub for possible name */
            };

        The ``cookie`` member of this struct is used to pair two related
        events, for example, it pairs an IN_MOVED_FROM event with an
        IN_MOVED_TO event.
        r   r   iIII    N)rF   structunpack_fromrstrip)r   irC   rD   rE   lengthrG   s          r!   r   zInotify._parse_event_buffer  s      " "fL))))'-'9&,PQ'R'R$BffBR& 89@@GGDfAdFD((((	 "fL))))))))r#   )rN   rO   rL   rP   rM   rQ   rR   rS   rR   r   rR   rO   rj   )rR   rS   )r   r   rR   r   )r   r   rR   rS   )rN   rO   rR   rS   )r   r   rR   r   )rN   rO   rD   r   rL   rP   rR   rS   )rN   rO   rD   r   rR   r   )r   rO   rR   r   )r$   r%   r&   rH   r   propertyrM   rN   r   r\   r   r   r   r   r   r   DEFAULT_EVENT_BUFFER_SIZEr   r   r   r   staticmethodrk   r   r   r#   r!   rK   rK      s         :?Y] +> +> +> +> +> +>Z       X     X " " " X"       X % % % %	 	 	 	6 6 6 64 4 4 4
' 
' 
' 
', , , ," 7P r r r r r rh   5 5 5 5,     1 1 1 \1 ) ) ) \) ) )r#   rK   c                  J   e Zd ZdZd,dZed-d            Zed.d            Zed.d            Zed.d            Z	ed-d            Z
ed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d            Zed/d             Zed0d"            Zd1d%Zd1d&Zd.d'Zed2d)            Zd3d*Z d+S )4r   a	  Inotify event struct wrapper.

    :param wd:
        Watch descriptor
    :param mask:
        Event mask
    :param cookie:
        Event cookie
    :param name:
        Base name of the event source path.
    :param src_path:
        Full event source path.
    rC   r   rD   rE   rG   rO   r   rR   rS   c                L    || _         || _        || _        || _        || _        d S r   )_wd_mask_cookie_name	_src_path)r^   rC   rD   rE   rG   r   s         r!   r   zInotifyEvent.__init__  s)    

!r#   c                    | j         S r   )r   rb   s    r!   r   zInotifyEvent.src_path  s
    ~r#   c                    | j         S r   )r   rb   s    r!   rC   zInotifyEvent.wd  s	    xr#   c                    | j         S r   )r   rb   s    r!   rD   zInotifyEvent.mask  
    zr#   c                    | j         S r   )r   rb   s    r!   rE   zInotifyEvent.cookie  s
    |r#   c                    | j         S r   )r   rb   s    r!   rG   zInotifyEvent.name  r   r#   rP   c                2    | j         t          j        z  dk    S re   )r   r   r(   rb   s    r!   	is_modifyzInotifyEvent.is_modify      z,66::r#   c                2    | j         t          j        z  dk    S re   )r   r   r*   rb   s    r!   is_close_writezInotifyEvent.is_close_write      z,;;a??r#   c                2    | j         t          j        z  dk    S re   )r   r   r+   rb   s    r!   is_close_nowritezInotifyEvent.is_close_nowrite  s    z,==AAr#   c                2    | j         t          j        z  dk    S re   )r   r   r,   rb   s    r!   is_openzInotifyEvent.is_open
      z,44q88r#   c                2    | j         t          j        z  dk    S re   )r   r   r'   rb   s    r!   	is_accesszInotifyEvent.is_access  r   r#   c                2    | j         t          j        z  dk    S re   )r   r   r0   rb   s    r!   	is_deletezInotifyEvent.is_delete  r   r#   c                2    | j         t          j        z  dk    S re   )r   r   r1   rb   s    r!   is_delete_selfzInotifyEvent.is_delete_self  r   r#   c                2    | j         t          j        z  dk    S re   )r   r   r/   rb   s    r!   r   zInotifyEvent.is_create  r   r#   c                2    | j         t          j        z  dk    S re   )r   r   r-   rb   s    r!   r   zInotifyEvent.is_moved_from  s    z,::Q>>r#   c                2    | j         t          j        z  dk    S re   )r   r   r.   rb   s    r!   r   zInotifyEvent.is_moved_to"  s    z,881<<r#   c                2    | j         t          j        z  dk    S re   )r   r   r3   rb   s    r!   is_movezInotifyEvent.is_move&  r   r#   c                2    | j         t          j        z  dk    S re   )r   r   r2   rb   s    r!   is_move_selfzInotifyEvent.is_move_self*  s    z,99A==r#   c                2    | j         t          j        z  dk    S re   )r   r   r)   rb   s    r!   	is_attribzInotifyEvent.is_attrib.  r   r#   c                2    | j         t          j        z  dk    S re   )r   r   r6   rb   s    r!   r   zInotifyEvent.is_ignored2  s    z,77!;;r#   c                N    | j         p| j        p| j        t          j        z  dk    S re   )r  r  r   r   r;   rb   s    r!   r   zInotifyEvent.is_directory6  s+    
 "ed&7e4:HXHa;ade;eer#   "tuple[bytes, int, int, int, bytes]c                B    | j         | j        | j        | j        | j        fS r   )r   r   r   r   r   rb   s    r!   keyzInotifyEvent.key=  s    ~txT\4:MMr#   r   objectc                Z    t          |t                    st          S | j        |j        k    S r   
isinstancer   NotImplementedr  r^   r   s     r!   __eq__zInotifyEvent.__eq__A  *    -66 	"!!x=,,,r#   c                Z    t          |t                    st          S | j        |j        k    S r   r  r  s     r!   __ne__zInotifyEvent.__ne__F  r  r#   c                *    t          | j                  S r   )hashr  rb   s    r!   __hash__zInotifyEvent.__hash__K  s    DH~~r#   strc                    g }t          t                    D ]J}|                    d          r3|dvr/t          t          |          }| |z  r|                    |           Kd                    |          S )NIN_>   r3   r=   |)dirr   r   getattrr   r   )rD   maskscc_vals       r!   _get_mask_stringzInotifyEvent._get_mask_stringN  sz    %&& 	$ 	$A||E"" $q0L'L'L 0!44%< $LLOOOxxr#   c                    dt          |           j         d| j        d| j         d|                     | j                   d| j         dt          j        | j	                  dS )N<z: src_path=z, wd=z, mask=z	, cookie=z, name=>)
typer$   r   rC   r*  rD   rE   rq   fsdecoderG   rb   s    r!   __repr__zInotifyEvent.__repr__X  s    1T

# 1 1 1 1dg 1 1**49551 1@D1 1[++1 1 1	
r#   N)rC   r   rD   r   rE   r   rG   rO   r   rO   rR   rS   r   r   rj   )rR   r  )r   r  rR   rP   )rD   r   rR   r!  )rR   r!  )!r$   r%   r&   rH   r   r   r   rC   rD   rE   rG   r   r   r   r   r  r  r  r   r   r   r
  r  r  r   r   r  r  r  r   r   r*  r0  r   r#   r!   r   r     sV        " " " "    X    X    X    X    X ; ; ; X; @ @ @ X@ B B B XB 9 9 9 X9 ; ; ; X; ; ; ; X; @ @ @ X@ ; ; ; X; ? ? ? X? = = = X= 9 9 9 X9 > > > X> ; ; ; X; < < < X< f f f Xf N N N XN- - - -
- - - -
       \
 
 
 
 
 
r#   r   )3
__future__r   r   r   ctypes.utilr   rq   rf   r   rl   r   r   r   	functoolsr   typingr   watchdog.utilsr	   collections.abcr
   CDLLlibcrt   r   error	CFUNCTYPEr   r   r   r   r(   r)   r-   r.   r/   r0   r1   r8   r*   r+   r,   r{   	StructurerB   sizeof
EVENT_SIZEDEFAULT_NUM_EVENTSr   rK   r   r   r#   r!   <module>r?     s   " " " " " "           				       , , , , , , , , , ,                   / / / / / / *))))))v{4wt^$$ &GGD:M,N,N &V]V]^bdvVwVw &;tz;;E

u
%
%%V$F$UE8XQUVVVXkmqWrss K#6#E5(dKKKM_aeLfgg 6v6667MNN4 4 4 4 4 4 4 4p f""&$""''')   $    )   , V]-..
 .*r/B K) K) K) K) K) K) K) K)\
I
 I
 I
 I
 I
 I
 I
 I
 I
 I
r#   