
    ʆh5                        S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  \
(       a  S SKJrJr  S	rS	r " S
 S\5      r " S S5      r " S S\5      r " S S\5      r " S S\5      rg)    )annotationsN)defaultdict)Path)TYPE_CHECKING)
BaseThread)SkipRepeatsQueue)FileSystemEventFileSystemEventHandlerg      ?c                      \ rS rSrSrSrg)
EventQueue   a  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____firstlineno____doc____static_attributes__r       N/opt/services/DDDS/venv/lib/python3.13/site-packages/watchdog/observers/api.pyr   r      s    r   r   c                      \ rS rSrSrSS.SS jjr\SS j5       r\SS j5       r\SS j5       r	\SS	 j5       r
SS
 jrSS jrSS jrSS jrSrg)ObservedWatch   zAn scheduled watch.

:param path:
    Path string.
:param recursive:
    ``True`` if watch is recursive; ``False`` otherwise.
:param event_filter:
    Optional collection of :class:`watchdog.events.FileSystemEvent` to watch
N)event_filterc                   [        U[        5      (       a  [        U5      OUU l        X l        Ub  [        U5      U l        g S U l        g N)
isinstancer   str_path_is_recursive	frozenset_event_filter)selfpath	recursiver   s       r   __init__ObservedWatch.__init__(   s;    ",T4"8"8SYd
&8D8PY|4VZr   c                    U R                   $ )z"The path that this watch monitors.)r   r#   s    r   r$   ObservedWatch.path-   s     zzr   c                    U R                   $ )z;Determines whether subdirectories are watched for the path.)r    r)   s    r   is_recursiveObservedWatch.is_recursive2        !!!r   c                    U R                   $ )z.Collection of event types watched for the path)r"   r)   s    r   r   ObservedWatch.event_filter7   r.   r   c                H    U R                   U R                  U R                  4$ r   )r$   r,   r   r)   s    r   keyObservedWatch.key<   s    yy$++T->->>>r   c                j    [        U[        5      (       d  [        $ U R                  UR                  :H  $ r   r   r   NotImplementedr2   r#   watchs     r   __eq__ObservedWatch.__eq__@   (    %//!!xx599$$r   c                j    [        U[        5      (       d  [        $ U R                  UR                  :g  $ r   r5   r7   s     r   __ne__ObservedWatch.__ne__E   r;   r   c                ,    [        U R                  5      $ r   )hashr2   r)   s    r   __hash__ObservedWatch.__hash__J   s    DHH~r   c                    U R                   b1  SR                  [        S U R                    5       5      5      nSU 3nOSnS[        U 5      R                   SU R
                  < SU R                   U S3$ )	N|c              3  8   #    U  H  oR                   v   M     g 7fr   )r   ).0_clss     r   	<genexpr>)ObservedWatch.__repr__.<locals>.<genexpr>O   s     .[IZ}}IZs   z, event_filter= <z: path=z, is_recursive=>)r   joinsortedtyper   r$   r,   )r#   event_filter_strs     r   __repr__ObservedWatch.__repr__M   s{    ("xx.[IZIZ.[([\!01A0BC!4:&&'wtyym?4K\K\J]^n]oopqqr   )r"   r    r   )r$   z
str | Pathr%   boolr   "list[type[FileSystemEvent]] | None)returnr   )rU   rS   )rU   z'frozenset[type[FileSystemEvent]] | None)rU   z9tuple[str, bool, frozenset[type[FileSystemEvent]] | None])r8   objectrU   rS   )rU   int)r   r   r   r   r   r&   propertyr$   r,   r   r2   r9   r=   rA   rQ   r   r   r   r   r   r      sy     qu [
   " " " " ? ?%
%
rr   r   c                     ^  \ rS rSrSr\SS.         SU 4S jjjr\SS j5       r\SS j5       r	SS jr
SS	 jrSS
 jrSrU =r$ )EventEmitterW   a  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``
:param event_filter:
    Collection of event types to emit, or None for no filtering (default).
:type event_filter:
    Iterable[:class:`watchdog.events.FileSystemEvent`] | None
Ntimeoutr   c               |   > [         TU ]  5         Xl        X l        X0l        Ub  [        U5      U l        g S U l        g r   )superr&   _event_queue_watch_timeoutr!   r"   )r#   event_queuer8   r]   r   	__class__s        r   r&   EventEmitter.__init__m   s:     	'8D8PY|4VZr   c                    U R                   $ )z$Blocking timeout for reading events.rb   r)   s    r   r]   EventEmitter.timeout{        }}r   c                    U R                   $ )z'The watch associated with this emitter.)ra   r)   s    r   r8   EventEmitter.watch   s     {{r   c                   ^ U R                   b$  [        U4S jU R                    5       5      (       a(  U R                  R                  TU R                  45        gg)zQueues a single event.

:param event:
    Event to be queued.
:type event:
    An instance of :class:`watchdog.events.FileSystemEvent`
    or a subclass.
Nc              3  <   >#    U  H  n[        TU5      v   M     g 7fr   )r   )rF   clsevents     r   rH   +EventEmitter.queue_event.<locals>.<genexpr>   s     ,bOaZs-C-COas   )r"   anyr`   putr8   )r#   ro   s    `r   queue_eventEventEmitter.queue_event   sJ     %,btOaOa,b)b)b!!5$**"56 *cr   c                    g)zOverride 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_eventsEventEmitter.queue_events       r   c                    U R                  5       (       a3  U R                  U R                  5        U R                  5       (       a  M2  g g r   )should_keep_runningrv   r]   r)   s    r   runEventEmitter.run   s4    &&((dll+ &&((r   )r"   r`   rb   ra   )
rc   r   r8   r   r]   floatr   rT   rU   NonerU   r}   )rU   r   )ro   r	   rU   r~   r]   r}   rU   r~   rU   r~   )r   r   r   r   r   DEFAULT_EMITTER_TIMEOUTr&   rX   r]   r8   rs   rv   r{   r   __classcell__rd   s   @r   rZ   rZ   W   s    4 1;?[[ [
 [ 9[ 
[ [    
7	, ,r   rZ   c                     ^  \ rS rSrSr\" 5       r \S.SU 4S jjjr\	SS j5       r
SS jr\	SS j5       rSS jrSS	 jrS
rU =r$ )EventDispatcher   a  Consumer thread base class subclassed by event observer threads
that dispatch events from an event queue to appropriate event handlers.

:param timeout:
    Timeout value (in seconds) passed to emitters
    constructions in the child class BaseObserver.
:type timeout:
    ``float``
r]   c               L   > [         TU ]  5         [        5       U l        Xl        g r   )r_   r&   r   r`   rb   )r#   r]   rd   s     r   r&   EventDispatcher.__init__   s    &Lr   c                    U R                   $ )z)Timeout value to construct emitters with.rg   r)   s    r   r]   EventDispatcher.timeout   ri   r   c                    [         R                  " U 5        [        R                  " [        R
                  5         U R                  R                  [        R                  5        S S S 5        g ! , (       d  f       g = fr   )
r   stop
contextlibsuppressqueueFullrc   
put_nowaitr   
stop_eventr)   s    r   r   EventDispatcher.stop   sF      ,''(B(BC -,,s   *A..
A<c                    U R                   $ )zThe event queue which is populated with file system events
by emitters and from which events are dispatched by a dispatcher
thread.
)r`   r)   s    r   rc   EventDispatcher.event_queue   s        r   c                    g)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`
:raises:
    :class:`queue.Empty`
Nr   )r#   rc   s     r   dispatch_eventsEventDispatcher.dispatch_events   rx   r   c                    U R                  5       (       a4   U R                  U R                  5        U R                  5       (       a  M3  g g ! [        R                   a     Ma  f = fr   )rz   r   rc   r   Emptyr)   s    r   r{   EventDispatcher.run   sS    &&(($$T%5%56 &&(( ;; s   A A#"A#)r`   rb   r   r   r   )rU   r   rc   r   rU   r~   )r   r   r   r   r   rV   r   DEFAULT_OBSERVER_TIMEOUTr&   rX   r]   r   rc   r   r{   r   r   r   s   @r   r   r      s^     JC+C    
  D
 ! !
 r   r   c                     ^  \ rS rSrSr\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S
 j5       rSU 4S jjrSSS.         SS jjrSS 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$ )BaseObserver   zBase observer.r   c                  > [         TU ]  US9  Xl        [        R                  " 5       U l        [        5       U l        [        [        5      U l	        [        5       U l
        0 U l        g )Nr   )r_   r&   _emitter_class	threadingRLock_lockset_watchesr   	_handlers	_emitters_emitter_for_watch)r#   emitter_classr]   rd   s      r   r&   BaseObserver.__init__   sN    )+__&
,/ER]^aRb,/EEGr   c                j    XR                   UR                  '   U R                  R                  U5        g r   )r   r8   r   addr#   emitters     r   _add_emitterBaseObserver._add_emitter   s&    18.7#r   c                   U R                   UR                  	 U R                  R                  U5        UR	                  5         [
        R                  " [        5         UR                  5         S S S 5        g ! , (       d  f       g = fr   )	r   r8   r   remover   r   r   RuntimeErrorrM   r   s     r   _remove_emitterBaseObserver._remove_emitter   sR    ##GMM2g&  .LLN /..s   A77
Bc                b   U R                    H  nUR                  5         M     U R                    H6  n[        R                  " [        5         UR                  5         S S S 5        M8     U R                   R                  5         U R                  R                  5         g ! , (       d  f       M~  = fr   )r   r   r   r   r   rM   clearr   r   s     r   _clear_emittersBaseObserver._clear_emitters   ss    ~~GLLN &~~G$$\2 32 & 	%%' 32s   B
B.	c                @    U R                   U   R                  U5        g r   )r   r   r#   event_handlerr8   s      r   _add_handler_for_watch#BaseObserver._add_handler_for_watch   s    u!!-0r   c                    U R                   U	 g r   )r   r7   s     r   _remove_handlers_for_watch'BaseObserver._remove_handlers_for_watch   s    NN5!r   c                    U R                   $ )z/Returns event emitter created by this observer.)r   r)   s    r   emittersBaseObserver.emitters   s     ~~r   c                   > U R                   R                  5        H  n UR                  5         M     [
        TU ]	  5         g ! [         a    U R	                  U5        e f = fr   )r   copystart	Exceptionr   r_   )r#   r   rd   s     r   r   BaseObserver.start  sU    ~~**,G - 	  $$W-s   AA FNr%   r   c                  U R                      [        X#US9nU R                  X5        XPR                  ;  a[  U R	                  U R
                  XPR                  US9nU R                  5       (       a  UR                  5         U R                  U5        U R                  R                  U5        SSS5        U$ ! , (       d  f       W$ = f)av  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``
:param event_filter:
    Collection of event types to emit, or None for no filtering (default).
:type event_filter:
    Iterable[:class:`watchdog.events.FileSystemEvent`] | None
:return:
    An :class:`ObservedWatch` object instance representing
    a watch.
r   r\   N)r   r   r   r   r   rc   r]   is_aliver   r   r   r   )r#   r   r$   r%   r   r8   r   s          r   scheduleBaseObserver.schedule  s    D ZZ!$,WE''= 333--d.>.>||jv-w==??MMO!!'*MMe$   Z s   B!B88
Cc                r    U R                      U R                  X5        SSS5        g! , (       d  f       g= f)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   r   r   s      r   add_handler_for_watch"BaseObserver.add_handler_for_watch=  s#     ZZ''= ZZs   (
6c                    U R                      U R                  U   R                  U5        SSS5        g! , (       d  f       g= f)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   r   r   s      r   remove_handler_for_watch%BaseObserver.remove_handler_for_watchO  s,     ZZNN5!((7 ZZs	   5
Ac                    U R                      U R                  U   nU R                  U	 U R                  U5        U R                  R                  U5        SSS5        g! , (       d  f       g= f)zUnschedules a watch.

:param watch:
    The watch to unschedule.
:type watch:
    An instance of :class:`ObservedWatch` or a subclass of
    :class:`ObservedWatch`
N)r   r   r   r   r   r   )r#   r8   r   s      r   
unscheduleBaseObserver.unschedulea  sQ     ZZ--e4Gu%  )MM  '	 ZZs   A	A
A-c                    U R                      U R                  R                  5         U R                  5         U R                  R                  5         SSS5        g! , (       d  f       g= f)zCUnschedules all watches and detaches all associated event handlers.N)r   r   r   r   r   r)   s    r   unschedule_allBaseObserver.unschedule_allp  s?    ZZNN  "  "MM! ZZs   AA
A)c                $    U R                  5         g r   )r   r)   s    r   on_thread_stopBaseObserver.on_thread_stopw  s    r   c                P   UR                  SS9nU[        R                  L a  g Uu  p4U R                     U R                  U   R                  5        H(  nXPR                  U   ;   d  M  UR                  U5        M*     S S S 5        UR                  5         g ! , (       d  f       N= f)NT)block)getr   r   r   r   r   dispatch	task_done)r#   rc   entryro   r8   handlers         r   r   BaseObserver.dispatch_eventsz  s    d+O...ZZ  >>%0557nnU33$$U+ 8	  	 Zs   1B)B
B%)r   r   r   r   r   r   )r   ztype[EventEmitter]r]   r}   rU   r~   )r   rZ   rU   r~   r   )r   r
   r8   r   rU   r~   )r8   r   rU   r~   )rU   zset[EventEmitter])
r   r
   r$   r   r%   rS   r   rT   rU   r   r   )r   r   r   r   r   r   r&   r   r   r   r   r   rX   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r      s    Nf H H$(1"    ;?--- -
 - 9- 
-^>$8$("   r   r   )
__future__r   r   r   r   collectionsr   pathlibr   typingr   watchdog.utilsr   watchdog.utils.bricksr   watchdog.eventsr	   r
   r   r   r   r   rZ   r   r   r   r   r   <module>r      sv    "    #    % 2G  ! 6r 6rtG,: G,T6j 6rn ? n r   