
    zc!.                         d dl Z d dlZd dlmZ d dlmZ d dlmZ dZdZ	 G d de          Z
 G d d	          Z G d
 de          Z G d de          Z G d de          ZdS )    N)Path)
BaseThread)SkipRepeatsQueue   c                       e Zd ZdZdS )
EventQueuea.  Thread-safe event queue based on a special queue that skips adding
    the same event (:class:`FileSystemEvent`) multiple times consecutively.
    Thus avoiding dispatching multiple event handling
    calls when multiple identical events are produced quicker than an observer
    can consume them.
    N)__name__
__module____qualname____doc__     6lib/python3.11/site-packages/watchdog/observers/api.pyr   r      s           r   r   c                   r    e Zd ZdZd Zed             Zed             Zed             Zd Z	d Z
d Zd	 Zd
S )ObservedWatchzAn scheduled watch.

    :param path:
        Path string.
    :param recursive:
        ``True`` if watch is recursive; ``False`` otherwise.
    c                 v    t          |t                    rt          |          | _        n|| _        || _        d S N)
isinstancer   str_path_is_recursive)selfpath	recursives      r   __init__zObservedWatch.__init__0   s8    dD!! 	TDJJDJ&r   c                     | j         S )z"The path that this watch monitors.)r   r   s    r   r   zObservedWatch.path7   s     zr   c                     | j         S )z;Determines whether subdirectories are watched for the path.)r   r   s    r   is_recursivezObservedWatch.is_recursive<   s     !!r   c                     | j         | j        fS r   )r   r   r   s    r   keyzObservedWatch.keyA   s    y$+++r   c                 "    | j         |j         k    S r   r!   r   watchs     r   __eq__zObservedWatch.__eq__E       x59$$r   c                 "    | j         |j         k    S r   r#   r$   s     r   __ne__zObservedWatch.__ne__H   r'   r   c                 *    t          | j                  S r   )hashr!   r   s    r   __hash__zObservedWatch.__hash__K   s    DH~~r   c                 R    dt          |           j        d| j        d| j        dS )N<z: path=z, is_recursive=>)typer	   r   r   r   s    r   __repr__zObservedWatch.__repr__N   s3     JJD,=,=,=? 	?r   N)r	   r
   r   r   r   propertyr   r   r!   r&   r)   r,   r1   r   r   r   r   r   '   s         ' ' '   X " " X" , , X,% % %% % %  ? ? ? ? ?r   r   c                   Z    e Zd ZdZefdZed             Zed             Zd Z	d Z
d ZdS )	EventEmittera  
    Producer thread base class subclassed by event emitters
    that generate events and populate a queue with them.

    :param event_queue:
        The event queue to populate with generated events.
    :type event_queue:
        :class:`watchdog.events.EventQueue`
    :param watch:
        The watch to observe and produce events for.
    :type watch:
        :class:`ObservedWatch`
    :param timeout:
        Timeout (in seconds) between successive attempts at reading events.
    :type timeout:
        ``float``
    c                 X    t          j        |            || _        || _        || _        d S r   )r   r   _event_queue_watch_timeout)r   event_queuer%   timeouts       r   r   zEventEmitter.__init__g   s-    D!!!'r   c                     | j         S )z6
        Blocking timeout for reading events.
        r8   r   s    r   r:   zEventEmitter.timeoutm   s    
 }r   c                     | j         S )z9
        The watch associated with this emitter.
        )r7   r   s    r   r%   zEventEmitter.watcht   s    
 {r   c                 H    | j                             || j        f           dS )z
        Queues a single event.

        :param event:
            Event to be queued.
        :type event:
            An instance of :class:`watchdog.events.FileSystemEvent`
            or a subclass.
        N)r6   putr%   )r   events     r   queue_eventzEventEmitter.queue_event{   s(     	udj122222r   c                     dS )a  Override this method to populate the event queue with events
        per interval period.

        :param timeout:
            Timeout (in seconds) between successive attempts at
            reading events.
        :type timeout:
            ``float``
        Nr   r   r:   s     r   queue_eventszEventEmitter.queue_events         r   c                     |                                  r0|                     | j                   |                                  .d S d S r   )should_keep_runningrD   r:   r   s    r   runzEventEmitter.run   sV    &&(( 	,dl+++ &&(( 	, 	, 	, 	, 	,r   N)r	   r
   r   r   DEFAULT_EMITTER_TIMEOUTr   r2   r:   r%   rA   rD   rH   r   r   r   r4   r4   T   s         $ 4K           X   X
3 
3 
3	 	 	, , , , ,r   r4   c                   T    e Zd ZdZefdZed             Zed             Zd Z	d Z
dS )EventDispatchera  
    Consumer thread base class subclassed by event observer threads
    that dispatch events from an event queue to appropriate event handlers.

    :param timeout:
        Event queue blocking timeout (in seconds).
    :type timeout:
        ``float``
    c                 b    t          j        |            t                      | _        || _        d S r   )r   r   r   r6   r8   rC   s     r   r   zEventDispatcher.__init__   s*    D!!!&LLr   c                     | j         S )zEvent queue block timeout.r<   r   s    r   r:   zEventDispatcher.timeout   s     }r   c                     | j         S )zThe event queue which is populated with file system events
        by emitters and from which events are dispatched by a dispatcher
        thread.)r6   r   s    r   r9   zEventDispatcher.event_queue   s    
   r   c                     dS )a  Override this method to consume events from an event queue, blocking
        on the queue for the specified timeout before raising :class:`queue.Empty`.

        :param event_queue:
            Event queue to populate with one set of events.
        :type event_queue:
            :class:`EventQueue`
        :param timeout:
            Interval period (in seconds) to wait before timing out on the
            event queue.
        :type timeout:
            ``float``
        :raises:
            :class:`queue.Empty`
        Nr   )r   r9   r:   s      r   dispatch_eventszEventDispatcher.dispatch_events   rE   r   c                     |                                  rM	 |                     | j        | j                   n# t          j        $ r Y Gw xY w|                                  Kd S d S r   )rG   rP   r9   r:   queueEmptyr   s    r   rH   zEventDispatcher.run   s    &&(( 	$$T%5t|DDDD;    &&(( 	 	 	 	 	s    7 A	A	N)r	   r
   r   r   DEFAULT_OBSERVER_TIMEOUTr   r2   r:   r9   rP   rH   r   r   r   rK   rK      s           8        
   X ! ! X!  "    r   rK   c                        e Zd ZdZefdZd Zd Zd Zd Z	d Z
ed             Z fd	ZddZd Zd Zd Zd Zd Zd Z xZS )BaseObserverzBase observer.c                    t                               | |           || _        t          j                    | _        t                      | _        t                      | _	        t                      | _
        t                      | _        d S r   )rK   r   _emitter_class	threadingRLock_lockset_watchesdict	_handlers	_emitters_emitter_for_watch)r   emitter_classr:   s      r   r   zBaseObserver.__init__   sb      w///+_&&
"&&&r   c                 X    || j         |j        <   | j                            |           d S r   )ra   r%   r`   addr   emitters     r   _add_emitterzBaseObserver._add_emitter   s-    18.7#####r   c                     | j         |j        = | j                            |           |                                 	 |                                 d S # t          $ r Y d S w xY wr   )ra   r%   r`   removestopjoinRuntimeErrorre   s     r   _remove_emitterzBaseObserver._remove_emitter   sj    #GM2g&&&	LLNNNNN 	 	 	DD	s   A 
A! A!c                    | j         D ]}|                                 | j         D ]'}	 |                                 # t          $ r Y $w xY w| j                                          | j                                         d S r   )r`   rj   rk   rl   clearra   re   s     r   _clear_emitterszBaseObserver._clear_emitters   s    ~ 	 	GLLNNNN~ 	 	G   %%'''''s   >
A
Ac                     || j         vrt                      | j         |<   | j         |                             |           d S r   )r_   r\   rd   r   event_handlerr%   s      r   _add_handler_for_watchz#BaseObserver._add_handler_for_watch   sB    & 	*$'EEDN5!u!!-00000r   c                     | j         |= d S r   )r_   r$   s     r   _remove_handlers_for_watchz'BaseObserver._remove_handlers_for_watch   s    N5!!!r   c                     | j         S )z/Returns event emitter created by this observer.)r`   r   s    r   emitterszBaseObserver.emitters   s     ~r   c                     | j                                         D ];}	 |                                 # t          $ r |                     |            w xY wt                                                       d S r   )r`   copystart	Exceptionrm   super)r   rf   	__class__s     r   r{   zBaseObserver.start   s}    ~**,, 	 	G   $$W--- 	s	   3!AFc                    | j         5  t          ||          }|                     ||           | j                            |          _|                     | j        || j                  }|                     |           | 	                                r|
                                 | j                            |           ddd           n# 1 swxY w Y   |S )am  
        Schedules watching a path and calls appropriate methods specified
        in the given event handler in response to file system events.

        :param event_handler:
            An event handler instance that has appropriate event handling
            methods which will be called by the observer in response to
            file system events.
        :type event_handler:
            :class:`watchdog.events.FileSystemEventHandler` or a subclass
        :param path:
            Directory path that will be monitored.
        :type path:
            ``str``
        :param recursive:
            ``True`` if events will be emitted for sub-directories
            traversed recursively; ``False`` otherwise.
        :type recursive:
            ``bool``
        :return:
            An :class:`ObservedWatch` object instance representing
            a watch.
        N)r9   r%   r:   )r[   r   rt   ra   getrX   r9   r:   rg   is_aliver{   r]   rd   )r   rs   r   r   r%   rf   s         r   schedulezBaseObserver.schedule  s   0 Z 	% 	%!$	22E''u=== &**511 $--$:J496:l . D D !!'***==?? $MMOOOMe$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% s   B:CCCc                 r    | j         5  |                     ||           ddd           dS # 1 swxY w Y   dS )a!  Adds a handler for the given watch.

        :param event_handler:
            An event handler instance that has appropriate event handling
            methods which will be called by the observer in response to
            file system events.
        :type event_handler:
            :class:`watchdog.events.FileSystemEventHandler` or a subclass
        :param watch:
            The watch to add a handler for.
        :type watch:
            An instance of :class:`ObservedWatch` or a subclass of
            :class:`ObservedWatch`
        N)r[   rt   rr   s      r   add_handler_for_watchz"BaseObserver.add_handler_for_watch-  s     Z 	> 	>''u===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   ,00c                     | j         5  | j        |                             |           ddd           dS # 1 swxY w Y   dS )a'  Removes a handler for the given watch.

        :param event_handler:
            An event handler instance that has appropriate event handling
            methods which will be called by the observer in response to
            file system events.
        :type event_handler:
            :class:`watchdog.events.FileSystemEventHandler` or a subclass
        :param watch:
            The watch to remove a handler for.
        :type watch:
            An instance of :class:`ObservedWatch` or a subclass of
            :class:`ObservedWatch`
        N)r[   r_   ri   rr   s      r   remove_handler_for_watchz%BaseObserver.remove_handler_for_watch?  s     Z 	8 	8N5!((777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   !6::c                     | j         5  | j        |         }| j        |= |                     |           | j                            |           ddd           dS # 1 swxY w Y   dS )zUnschedules a watch.

        :param watch:
            The watch to unschedule.
        :type watch:
            An instance of :class:`ObservedWatch` or a subclass of
            :class:`ObservedWatch`
        N)r[   ra   r_   rm   r]   ri   )r   r%   rf   s      r   
unschedulezBaseObserver.unscheduleQ  s     Z 	( 	(-e4Gu%  )))M  '''		( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   AAA!Ac                     | j         5  | j                                         |                                  | j                                         ddd           dS # 1 swxY w Y   dS )zKUnschedules all watches and detaches all associated event
        handlers.N)r[   r_   ro   rp   r]   r   s    r   unschedule_allzBaseObserver.unschedule_all`  s     Z 	" 	"N  """  """M!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   AAA #A c                 .    |                                   d S r   )r   r   s    r   on_thread_stopzBaseObserver.on_thread_stoph  s    r   c                 \   |                     d|          \  }}| j        5  t          | j                             |g                     D ]4}|| j                             |g           v r|                    |           5	 d d d            n# 1 swxY w Y   |                                 d S )NT)blockr:   )r   r[   listr_   dispatch	task_done)r   r9   r:   r@   r%   handlers         r   rP   zBaseObserver.dispatch_eventsk  s    "T7CCuZ 	, 	,   2 25" = =>> , ,dn00;;; ,$$U+++,		, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	s   ABBB)F)r	   r
   r   r   rT   r   rg   rm   rp   rt   rv   r2   rx   r{   r   r   r   r   r   r   rP   __classcell__)r~   s   @r   rV   rV      s*       .F ) ) ) )$ $ $  	( 	( 	(1 1 1
" " "   X    % % % %N> > >$8 8 8$( ( (" " "  
  
  
  
  
  
  
 r   rV   )rR   rY   pathlibr   watchdog.utilsr   watchdog.utils.bricksr   rI   rT   r   r   r4   rK   rV   r   r   r   <module>r      sN  $            % % % % % % 2 2 2 2 2 2      !   )? )? )? )? )? )? )? )?Z@, @, @, @, @,: @, @, @,F2 2 2 2 2j 2 2 2ji  i  i  i  i ? i  i  i  i  i r   