o
    9Bi                     @   s   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 deZ	de
fdd	Zd
e
dee de
de
fddZd
e
de
ddfddZdejddfddZejdZesWe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)Anycast)FilePathc                   @   s   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__ r
   r
   W/var/www/html/Trade-python/venv/lib/python3.10/site-packages/twisted/python/_inotify.pyr      s    r   returnc                  C   s"   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   )fdr
   r
   r   init   s   r   r   pathmaskc                 C   s<   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   wdr
   r
   r   add#   s   	r   r   c                 C   s   t | | dS )zM
    Remove the given watch descriptor from the inotify file descriptor.
    N)r   inotify_rm_watch)r   r   r
   r
   r   remove2   s   r   r   c                 C   sp   dD ]}t | |ddu rtdq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   functionr
   r
   r   initializeModuleM   s   

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
   r   <module>   s   
