
    $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dS )	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_maskpathbytesr   boolr   
int | NonereturnNonec                   t                                                       t          d         | j                  | _        t          |||          | _        |                                  d S )N0InotifyEvent | tuple[InotifyEvent, InotifyEvent]r
   )super__init__r   delay_queuer   _inotifystart)selfr   r   r   	__class__s       a/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/watchdog/observers/inotify_buffer.pyr   zInotifyBuffer.__init__   sY    "#UVW[Wabb	jQQQ

    7InotifyEvent | tuple[InotifyEvent, InotifyEvent] | Nonec                4    | 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                j    | j                                          | j                                         d S N)r   closer   r"   s    r   on_thread_stopzInotifyBuffer.on_thread_stop(   s0    r   c                V    |                                   |                                  d S r%   )stopjoinr"   s    r   r&   zInotifyBuffer.close,   s     				r   
event_listlist[InotifyEvent]6list[InotifyEvent | tuple[InotifyEvent, InotifyEvent]]c                   g }|D ]̊t                               d           d	fd}j        rt          |          D ]\  }} ||          r	|f||<    nd| j                            |          }||                    |f           t                               d           |                               |                               |S )
zGroup any matching move eventszin-event %seventr   r   r   c                ^    t          | t                     o| j        o| j        j        k    S r%   )
isinstancetupleis_moved_fromcookie)r/   inotify_events    r   matching_from_eventz8InotifyBuffer._group_events.<locals>.matching_from_event6   s0    %eU333t8KtPUP\`m`tPttr   Nz'could not find matching move_from event)r/   r   r   r   )loggerdebugis_moved_to	enumerater   removeappend)r   r+   groupedr6   indexr/   
from_eventr5   s          @r   _group_eventszInotifyBuffer._group_events0   s   JL' 	. 	.MLL666u u u u u u ( .$-g$6$6 6 6LE5**511 */)?
 "&!3!34G!H!HJ!-
M'BCCCC%NOOO}555}----r   c                   d}|                                  r|s| j                                        }|                     |          }|D ]}t	          |t
                    s|j        r|j        | j        j        k    rd}6t	          |t
                     o|j	        }| j
                            ||           t	          |t
                    s|j        r|j        | j        j        k    rd}|                                  r|dS dS dS dS )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@   r1   r2   
is_ignoredsrc_pathr   r3   r   putis_delete_self)r   deleted_selfinotify_eventsgrouped_eventsr5   r   s         r   runzInotifyBuffer.runK   sG   
 &&(( 	( 	(!]6688N!//??N!/ ( (!-77 M<T $-1CCC (, '}e<<<\A\U;;; #=%88(%4( &.$-2DDD $(L+ &&(( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(r   )r   r   r   r   r   r   r   r   )r   r   )r   r   )r+   r,   r   r-   )__name__
__module____qualname____doc__r   r   r#   r'   r&   r@   rK   __classcell__)r   s   @r   r	   r	      s          E9>Y]        ! ! ! !         6( ( ( ( ( ( ( (r   r	   )rO   
__future__r   loggingwatchdog.observers.inotify_cr   r   watchdog.utilsr   watchdog.utils.delayed_queuer   	getLoggerrL   r7   r	    r   r   <module>rX      s     # " " " " "  > > > > > > > > % % % % % % 5 5 5 5 5 5		8	$	$S( S( S( S( S(J S( S( S( S( S(r   