
    ʆhR                    ~    S r SSKJr  SSKrSSKJrJr  SSKJr  SSK	J
r
  \R                  " \5      r " S S\5      rg)	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                  p   ^  \ rS rSrSrSrSSS.SU 4S jjjrSS jrSS	 jrSS
 jr	SS jr
SS jrSrU =r$ )InotifyBuffer   zA 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U ]  5         [        S   " U R                  5      U l        [        XUS9U l        U R                  5         g )N0InotifyEvent | tuple[InotifyEvent, InotifyEvent]r   )super__init__r   delay_queuer   _inotifystart)selfpathr   r   	__class__s       Y/opt/services/DDDS/venv/lib/python3.13/site-packages/watchdog/observers/inotify_buffer.pyr   InotifyBuffer.__init__   s>    "#UVW[WaWabjQ

    c                6    U R                   R                  5       $ )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_eventInotifyBuffer.read_event!   s    
 {{  r   c                l    U R                   R                  5         U R                  R                  5         g N)r   closer   r   s    r   on_thread_stopInotifyBuffer.on_thread_stop(   s"    r   c                D    U R                  5         U R                  5         g r"   )stopjoinr   s    r   r#   InotifyBuffer.close,   s    				r   c                  ^ / nU H  m[         R                  ST5        SU4S jjnTR                  (       a  [        U5       H  u  pEU" U5      (       d  M  UT4X$'     MZ     U R                  R                  U5      nUb  UR                  UT45        M  [         R                  S5        UR                  T5        M  UR                  T5        M     U$ )zGroup any matching move eventszin-event %sc                   > [        U [        5      (       + =(       a,    U R                  =(       a    U R                  TR                  :H  $ r"   )
isinstancetupleis_moved_fromcookie)eventinotify_events    r   matching_from_event8InotifyBuffer._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)r0   r   returnbool)loggerdebugis_moved_to	enumerater   removeappend)r   
event_listgroupedr2   indexr0   
from_eventr1   s          @r   _group_eventsInotifyBuffer._group_events0   s    JL'MLL6u (($-g$6LE*511*/)? %7 "&!3!34G!HJ!-
M'BC%NO}5}-+ (, r   c                   SnU R                  5       (       Ga?  U(       Gd6  U R                  R                  5       nU R                  U5      nU H  n[	        U[
        5      (       d9  UR                  (       a(  UR                  U R                  R                  :X  a  SnMQ  [	        U[
        5      (       + =(       a    UR                  nU R                  R                  XES9  [	        U[
        5      (       a  M  UR                  (       d  M  UR                  U R                  R                  :X  d  M  SnM     U R                  5       (       a  U(       d  GM4  gggg)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_eventsr1   r   s         r   runInotifyBuffer.runK   s   
 &&((!]]668N!//?N!/!-77M<T<T$--1C1CC (, '}e<<\A\A\; #=%88%444%..$--2D2DD $(L% "0 &&((((r   )r   r   )r   bytesr   r5   r   z
int | Noner4   None)r4   z7InotifyEvent | tuple[InotifyEvent, InotifyEvent] | None)r4   rO   )r<   zlist[InotifyEvent]r4   z6list[InotifyEvent | tuple[InotifyEvent, InotifyEvent]])__name__
__module____qualname____firstlineno____doc__r   r   r   r$   r#   r@   rL   __static_attributes____classcell__)r   s   @r   r	   r	      s=     E9>Y]  !6( (r   r	   )rT   
__future__r   loggingwatchdog.observers.inotify_cr   r   watchdog.utilsr   watchdog.utils.delayed_queuer   	getLoggerrP   r6   r	    r   r   <module>r^      s9    #  > % 5			8	$S(J S(r   