
    gR                    ~    d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
  ej                  e      Z G d de      Zy)	u   :module: watchdog.observers.inotify_buffer
:synopsis: A wrapper for ``Inotify``.
:author: thomas.amland@gmail.com (Thomas Amland)
:author: contact@tiger-222.fr (Mickaël Schoentgen)
:platforms: linux
    )annotationsN)InotifyInotifyEvent)
BaseThread)DelayedQueuec                  X     e Zd ZdZdZdddd fdZddZddZdd	Zdd
Z	ddZ
 xZS )InotifyBufferzA wrapper for `Inotify` that holds events for `delay` seconds. During
    this time, IN_MOVED_FROM and IN_MOVED_TO events are paired.
    g      ?FN	recursive
event_maskc                   t         |           t        d   | j                        | _        t        |||      | _        | j                          y )N0InotifyEvent | tuple[InotifyEvent, InotifyEvent]r
   )super__init__r   delay_queuer   _inotifystart)selfpathr   r   	__class__s       V/var/www/openai/venv/lib/python3.12/site-packages/watchdog/observers/inotify_buffer.pyr   zInotifyBuffer.__init__   s@    "#UVW[WaWab	jQ

    c                6    | j                   j                         S )zReturns a single event or a tuple of from/to events in case of a
        paired move event. If this buffer has been closed, immediately return
        None.
        )r   getr   s    r   
read_eventzInotifyBuffer.read_event!   s    
 {{  r   c                l    | j                   j                          | j                  j                          y N)r   closer   r   s    r   on_thread_stopzInotifyBuffer.on_thread_stop(   s"    r   c                D    | j                          | j                          y r   )stopjoinr   s    r   r    zInotifyBuffer.close,   s    				r   c                   g }|D ]  t         j                  d       dfd}j                  r|t        |      D ]  \  }} ||      s|f||<    N | j                  j                  |      }||j                  |f       t         j                  d       |j                         |j                          |S )zGroup any matching move eventszin-event %sc                x    t        | t               xr' | j                  xr | j                  j                  k(  S r   )
isinstancetupleis_moved_fromcookie)eventinotify_events    r   matching_from_eventz8InotifyBuffer._group_events.<locals>.matching_from_event6   s6    %eU33t8K8KtPUP\P\`m`t`tPttr   z'could not find matching move_from event)r+   r   returnbool)loggerdebugis_moved_to	enumerater   removeappend)r   
event_listgroupedr-   indexr+   
from_eventr,   s          @r   _group_eventszInotifyBuffer._group_events0   s    JL'MLL6u (($-g$6LE5*51*/)? %7 "&!3!34G!HJ!-
M'BC%NO}5}-+ (, r   c                F   d}| j                         r|s
| j                  j                         }| j                  |      }|D ]  }t	        |t
              s2|j                  r&|j                  | j                  j                  k(  rd}Et	        |t
               xr |j                  }| j                  j                  ||       t	        |t
              r|j                  s|j                  | j                  j                  k(  sd} | j                         r|syyyy)zRead event from `inotify` and add them to `queue`. When reading a
        IN_MOVE_TO event, remove the previous added matching IN_MOVE_FROM event
        and add them back to the queue as a tuple.
        FT)r   N)should_keep_runningr   read_eventsr:   r'   r(   
is_ignoredsrc_pathr   r)   r   putis_delete_self)r   deleted_selfinotify_eventsgrouped_eventsr,   r   s         r   runzInotifyBuffer.runK   s    
 &&(!]]668N!//?N!/!-7M<T<T$--1C1CC (, '}e<<\A\A\U; #=%8%44%..$--2D2DD $(L% "0 &&(((r   )r   bytesr   r/   r   z
int | Noner.   None)r.   z7InotifyEvent | tuple[InotifyEvent, InotifyEvent] | None)r.   rG   )r6   zlist[InotifyEvent]r.   z6list[InotifyEvent | tuple[InotifyEvent, InotifyEvent]])__name__
__module____qualname____doc__r   r   r   r!   r    r:   rE   __classcell__)r   s   @r   r	   r	      s3     E9>Y] !6(r   r	   )rK   
__future__r   loggingwatchdog.observers.inotify_cr   r   watchdog.utilsr   watchdog.utils.delayed_queuer   	getLoggerrH   r0   r	    r   r   <module>rT      s;    #  > % 5			8	$S(J S(r   