
    \d                     8   d Z ddlZddlZddlmZ ddlmZ  G d de          Zde	fdZ
d	e	d
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                            d          Zes ed          ej                            e          Z ee           dS )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)cast)FilePathc                       e Zd ZdZdS )INotifyErrorzR
    Unify all the possible exceptions that can be raised by the INotify API.
    N)__name__
__module____qualname____doc__     7lib/python3.11/site-packages/twisted/python/_inotify.pyr   r      s           r   r   returnc                      t          t          t                                                    } | 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      s<     
c4$$&&	'	'B	Avv:;;;Ir   r   pathmaskc                     t          t          t                              | |                                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   #   sd     
c4))"d.>.>.@.@.EtLL	M	MB	AvvJdJJ2JJJKKKIr   r   c                 <    t                               | |           dS )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
        _        dS )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:;;; 1!#D &D&,lFL%AD"$*LD!'-|V_fo&VD#%+\D"""r   czCan't find C library.)r
   r$   ctypes.utiltypingr   twisted.python.filepathr   	Exceptionr   r   r   r   r   CDLLr*   utilfind_librarynamer"   cdllLoadLibraryr   r   r   r   <module>r6      sh  
             , , , , , ,    9   c    C x s s    "s " " " " " "626; 24 2 2 2 2& {$$ /
+-
.
..{t$$       r   