
    Vh                     <   d Z ddlZddlZddlmZmZ ddlmZ  G d de      Z	de
fdZd	e
d
ee   de
de
fdZd	e
de
ddfdZdej                  ddfdZej                   j#                  d      Zes ed      ej(                  j+                  e      Z ee       y)z
Very low-level ctypes-based interface to Linux inotify(7).

ctypes and a version of libc which supports inotify system calls are
required.
    N)Anycast)FilePathc                       e Zd ZdZy)INotifyErrorzR
    Unify all the possible exceptions that can be raised by the INotify API.
    N)__name__
__module____qualname____doc__     G/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/_inotify.pyr   r      s    r   r   returnc                  j    t        t        t        j                               } | dk  rt	        d      | S )zO
    Create an inotify instance and return the associated file descriptor.
    r   zINotify initialization error.)r   intlibcinotify_initr   )fds    r   initr      s1     
c4$$&	'B	Av:;;Ir   r   pathmaskc                     t        t        t        j                  | |j	                         j
                  |            }|dk  rt        d|d|d      |S )a/  
    Add a watch for the given path to the inotify file descriptor, and return
    the watch descriptor.

    @param fd: The file descriptor returned by C{libc.inotify_init}.
    @param path: The path to watch via inotify.
    @param mask: Bitmask specifying the events that inotify should monitor.
    r   zFailed to add watch on 'z' - ())r   r   r   inotify_add_watchasBytesModer   r   )r   r   r   wds       r   addr   #   sU     
c4))"d.>.>.@.E.EtL	MB	Av5dXU2&JKKIr   r   c                 0    t         j                  | |       y)zM
    Remove the given watch descriptor from the inotify file descriptor.
    N)r   inotify_rm_watch)r   r   s     r   remover    2   s    0 	"b!r   r   c                    dD ]  }t        | |d      t        d       g | j                  _        t        j
                  | j                  _        t        j
                  t        j
                  g| j                  _        t        j
                  | j                  _        t        j
                  t        j                  t        j                  g| j                  _        t        j
                  | j                  _        y)z
    Initialize the module, checking if the expected APIs exist and setting the
    argtypes and restype for C{inotify_init}, C{inotify_add_watch}, and
    C{inotify_rm_watch}.
    )r   r   r   Nzlibc6 2.4 or higher needed)getattrImportErrorr   argtypesctypesc_intrestyper   c_char_pc_uint32r   )r   functions     r   initializeModuler+   M   s     N <44(0:;;< "$D &D&,llFLL%AD"$*LLD!'-||V__foo&VD#%+\\D"r   czCan't find C library.)r   r%   ctypes.utiltypingr   r   twisted.python.filepathr   	Exceptionr   r   r   r   r    CDLLr+   utilfind_librarynamer#   cdllLoadLibraryr   r   r   r   <module>r7      s   
    ,9 c C x} C C "s " " "626;; 24 2& {{$
-
..{{t$  r   