
    [g=                       d Z ddlmZ ddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZ dZdZd	Zd
ZdZdZ ed       G d d             Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      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/ Z$d0 Z%y)1um  :module: watchdog.events
:synopsis: File system events and event handlers.
:author: yesudeep@google.com (Yesudeep Mangalapilly)
:author: contact@tiger-222.fr (Mickaël Schoentgen)

Event Classes
-------------
.. autoclass:: FileSystemEvent
   :members:
   :show-inheritance:
   :inherited-members:

.. autoclass:: FileSystemMovedEvent
   :members:
   :show-inheritance:

.. autoclass:: FileMovedEvent
   :members:
   :show-inheritance:

.. autoclass:: DirMovedEvent
   :members:
   :show-inheritance:

.. autoclass:: FileModifiedEvent
   :members:
   :show-inheritance:

.. autoclass:: DirModifiedEvent
   :members:
   :show-inheritance:

.. autoclass:: FileCreatedEvent
   :members:
   :show-inheritance:

.. autoclass:: FileClosedEvent
   :members:
   :show-inheritance:

.. autoclass:: FileOpenedEvent
   :members:
   :show-inheritance:

.. autoclass:: DirCreatedEvent
   :members:
   :show-inheritance:

.. autoclass:: FileDeletedEvent
   :members:
   :show-inheritance:

.. autoclass:: DirDeletedEvent
   :members:
   :show-inheritance:


Event Handler Classes
---------------------
.. autoclass:: FileSystemEventHandler
   :members:
   :show-inheritance:

.. autoclass:: PatternMatchingEventHandler
   :members:
   :show-inheritance:

.. autoclass:: RegexMatchingEventHandler
   :members:
   :show-inheritance:

.. autoclass:: LoggingEventHandler
   :members:
   :show-inheritance:

    )annotationsN)	dataclassfield)Optional)match_any_pathsmoveddeletedcreatedmodifiedclosedopenedT)unsafe_hashc                      e Zd ZU dZded<   dZded<    edd      Zded<    edd      Zd	ed
<   	  ed      Z	d	ed<   y)FileSystemEventa  Immutable type that represents a file system event that is triggered
    when a change occurs on the monitored file system.

    All FileSystemEvent objects are required to be immutable and hence
    can be used as keys in dictionaries or be added to sets.
    strsrc_path 	dest_pathF)defaultinit
event_typeboolis_directory)r   is_syntheticN)
__name__
__module____qualname____doc____annotations__r   r   r   r   r        /lib/python3.12/site-packages/watchdog/events.pyr   r   o   sP     MIsBU3J3u59L$9
 u-L$-r!   r   c                      e Zd ZdZeZy)FileSystemMovedEventz@File system event representing any kind of file system movement.N)r   r   r   r   EVENT_TYPE_MOVEDr   r    r!   r"   r$   r$      s
    J!Jr!   r$   c                      e Zd ZdZeZy)FileDeletedEventz@File system event representing file deletion on the file system.N)r   r   r   r   EVENT_TYPE_DELETEDr   r    r!   r"   r'   r'      
    J#Jr!   r'   c                      e Zd ZdZeZy)FileModifiedEventzDFile system event representing file modification on the file system.N)r   r   r   r   EVENT_TYPE_MODIFIEDr   r    r!   r"   r+   r+      s
    N$Jr!   r+   c                      e Zd ZdZeZy)FileCreatedEventz@File system event representing file creation on the file system.N)r   r   r   r   EVENT_TYPE_CREATEDr   r    r!   r"   r.   r.      r)   r!   r.   c                      e Zd ZdZy)FileMovedEventz@File system event representing file movement on the file system.N)r   r   r   r   r    r!   r"   r1   r1      s    Jr!   r1   c                      e Zd ZdZeZy)FileClosedEvent=File system event representing file close on the file system.N)r   r   r   r   EVENT_TYPE_CLOSEDr   r    r!   r"   r3   r3      
    G"Jr!   r3   c                      e Zd ZdZeZy)FileOpenedEventr4   N)r   r   r   r   EVENT_TYPE_OPENEDr   r    r!   r"   r8   r8      r6   r!   r8   c                      e Zd ZdZeZdZy)DirDeletedEventzEFile system event representing directory deletion on the file system.TN)r   r   r   r   r(   r   r   r    r!   r"   r;   r;          O#JLr!   r;   c                      e Zd ZdZeZdZy)DirModifiedEventzIFile system event representing directory modification on the file system.TN)r   r   r   r   r,   r   r   r    r!   r"   r>   r>      s    S$JLr!   r>   c                      e Zd ZdZeZdZy)DirCreatedEventzEFile system event representing directory creation on the file system.TN)r   r   r   r   r/   r   r   r    r!   r"   r@   r@      r<   r!   r@   c                      e Zd ZdZdZy)DirMovedEventzEFile system event representing directory movement on the file system.TN)r   r   r   r   r   r    r!   r"   rB   rB      s
    OLr!   rB   c                  P    e Zd ZdZddZddZddZddZddZddZ	ddZ
dd	Zy
)FileSystemEventHandlerzBBase file system event handler that you can override methods from.c                   | j                  |       	 t        | j                  t        | j                  t
        | j                  t        | j                  t        | j                  t        | j                  i|j                     |       y)Dispatches events to the appropriate methods.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        N)on_any_eventr/   
on_createdr(   
on_deletedr,   on_modifiedr%   on_movedr5   	on_closedr9   	on_openedr   selfevents     r"   dispatchzFileSystemEventHandler.dispatch   sn     	% 	!1!1dmmt~~t~~	
 

	 "	#r!   c                     y)zCatch-all event handler.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        Nr    rN   s     r"   rG   z#FileSystemEventHandler.on_any_event       r!   c                     y)zCalled when a file or a directory is moved or renamed.

        :param event:
            Event representing file/directory movement.
        :type event:
            :class:`DirMovedEvent` or :class:`FileMovedEvent`
        Nr    rN   s     r"   rK   zFileSystemEventHandler.on_moved   rS   r!   c                     y)zCalled when a file or directory is created.

        :param event:
            Event representing file/directory creation.
        :type event:
            :class:`DirCreatedEvent` or :class:`FileCreatedEvent`
        Nr    rN   s     r"   rH   z!FileSystemEventHandler.on_created   rS   r!   c                     y)zCalled when a file or directory is deleted.

        :param event:
            Event representing file/directory deletion.
        :type event:
            :class:`DirDeletedEvent` or :class:`FileDeletedEvent`
        Nr    rN   s     r"   rI   z!FileSystemEventHandler.on_deleted   rS   r!   c                     y)zCalled when a file or directory is modified.

        :param event:
            Event representing file/directory modification.
        :type event:
            :class:`DirModifiedEvent` or :class:`FileModifiedEvent`
        Nr    rN   s     r"   rJ   z"FileSystemEventHandler.on_modified  rS   r!   c                     y)zCalled when a file opened for writing is closed.

        :param event:
            Event representing file closing.
        :type event:
            :class:`FileClosedEvent`
        Nr    rN   s     r"   rL   z FileSystemEventHandler.on_closed  rS   r!   c                     y)zCalled when a file is opened.

        :param event:
            Event representing file opening.
        :type event:
            :class:`FileOpenedEvent`
        Nr    rN   s     r"   rM   z FileSystemEventHandler.on_opened  rS   r!   NrP   r   returnNone)r   r   r   r   rQ   rG   rK   rH   rI   rJ   rL   rM   r    r!   r"   rD   rD      s-    L#$r!   rD   c                  x     e Zd ZdZ	 	 	 	 d fd	Zed        Zed        Zed        Zed        Z	d	 fdZ
 xZS )
PatternMatchingEventHandlerz
    Matches given patterns with file paths associated with occurring events.
    Uses pathlib's `PurePath.match()` method. `patterns` and `ignore_patterns`
    are expected to be a list of strings.
    c                Z    t         |           || _        || _        || _        || _        y N)super__init__	_patterns_ignore_patterns_ignore_directories_case_sensitive)rO   patternsignore_patternsignore_directoriescase_sensitive	__class__s        r"   rb   z$PatternMatchingEventHandler.__init__*  s/     	! /#5 -r!   c                    | j                   S )zD(Read-only)
        Patterns to allow matching event paths.
        )rc   rO   s    r"   rg   z$PatternMatchingEventHandler.patterns8  s    
 ~~r!   c                    | j                   S )zE(Read-only)
        Patterns to ignore matching event paths.
        )rd   rm   s    r"   rh   z+PatternMatchingEventHandler.ignore_patterns?  s    
 $$$r!   c                    | j                   S z\(Read-only)
        ``True`` if directories should be ignored; ``False`` otherwise.
        re   rm   s    r"   ri   z.PatternMatchingEventHandler.ignore_directoriesF      
 '''r!   c                    | j                   S zu(Read-only)
        ``True`` if path names should be matched sensitive to case; ``False``
        otherwise.
        rf   rm   s    r"   rj   z*PatternMatchingEventHandler.case_sensitiveM       ###r!   c                   | j                   r|j                  ryg }t        |d      r.|j                  t	        j
                  |j                               |j                  r.|j                  t	        j
                  |j                               t        || j                  | j                  | j                        rt        | 5  |       yy)rF   Nr   )included_patternsexcluded_patternsrj   )ri   r   hasattrappendosfsdecoder   r   r   rg   rh   rj   ra   rQ   rO   rP   pathsrk   s      r"   rQ   z$PatternMatchingEventHandler.dispatchU  s     ""u'9'95+&LLU__56>>LLU^^45"mm"22..	
 GU#
r!   NNFFrZ   )r   r   r   r   rb   propertyrg   rh   ri   rj   rQ   __classcell__rk   s   @r"   r^   r^   #  su      .   % % ( ( $ $$ $r!   r^   c                  x     e Zd ZdZ	 	 	 	 d fd	Zed        Zed        Zed        Zed        Z	d	 fdZ
 xZS )
RegexMatchingEventHandlerzk
    Matches given regexes with file paths associated with occurring events.
    Uses the `re` module.
    c                "   t         |           |dg}nt        |t              r|g}|g }|rQ|D cg c]  }t	        j
                  |       c}| _        |D cg c]  }t	        j
                  |       c}| _        nn|D cg c]&  }t	        j
                  |t        j                        ( c}| _        |D cg c]&  }t	        j
                  |t        j                        ( c}| _        || _	        || _
        y c c}w c c}w c c}w c c}w )Nz.*)ra   rb   
isinstancer   recompile_regexes_ignore_regexes
IGNORECASEre   rf   )rO   regexesignore_regexesri   rj   rrk   s         r"   rb   z"RegexMatchingEventHandler.__init__u  s     	?gG%iG!N4;<GqRZZ]G<DM;I#J>aBJJqM>#JD CJK7aRZZ2==97KDMJX#Y.QBJJq"--$@.#YD #5 - =#JK#Ys   C=D+D;+Dc                    | j                   S )zC(Read-only)
        Regexes to allow matching event paths.
        )r   rm   s    r"   r   z!RegexMatchingEventHandler.regexes  s    
 }}r!   c                    | j                   S )zD(Read-only)
        Regexes to ignore matching event paths.
        )r   rm   s    r"   r   z(RegexMatchingEventHandler.ignore_regexes  s    
 ###r!   c                    | j                   S rp   rq   rm   s    r"   ri   z,RegexMatchingEventHandler.ignore_directories  rr   r!   c                    | j                   S rt   ru   rm   s    r"   rj   z(RegexMatchingEventHandler.case_sensitive  rv   r!   c                   | j                   r|j                  ryg t        |d      r.j                  t	        j
                  |j                               |j                  r.j                  t	        j
                  |j                               t        fd| j                  D              ryt        fd| j                  D              rt        | 1  |       yy)rF   Nr   c              3  N   K   | ]  }D ]  }|j                  |         y wr`   match.0r   pr   s      r"   	<genexpr>z5RegexMatchingEventHandler.dispatch.<locals>.<genexpr>  s$     F#6a1qwwqzz#6   "%c              3  N   K   | ]  }D ]  }|j                  |         y wr`   r   r   s      r"   r   z5RegexMatchingEventHandler.dispatch.<locals>.<genexpr>  s"     ?<aAqwwqzz<r   )ri   r   rz   r{   r|   r}   r   r   anyr   r   ra   rQ   r~   s     @r"   rQ   z"RegexMatchingEventHandler.dispatch  s     ""u'9'95+&LLU__56>>LLU^^45F4#6#6FF?4<<??GU# @r!   r   rZ   )r   r   r   r   rb   r   r   r   ri   rj   rQ   r   r   s   @r"   r   r   o  su      .0   $ $ ( ( $ $$ $r!   r   c                  n     e Zd ZdZd	d
 fdZd fdZd fdZd fdZd fdZd fdZ	d fdZ
 xZS )LoggingEventHandlerzLogs all the events captured.c                T    t         |           |xs t        j                  | _        y r`   )ra   rb   loggingrootlogger)rO   r   rk   s     r"   rb   zLoggingEventHandler.__init__  s    ,r!   c                    t         |   |       |j                  rdnd}| j                  j	                  d||j
                  |j                         y )N	directoryfilezMoved %s: from %s to %s)ra   rK   r   r   infor   r   rO   rP   whatrk   s      r"   rK   zLoggingEventHandler.on_moved  s@    #00{f2D%..%//Zr!   c                    t         |   |       |j                  rdnd}| j                  j	                  d||j
                         y )Nr   r   zCreated %s: %s)ra   rH   r   r   r   r   r   s      r"   rH   zLoggingEventHandler.on_created  :    5!#00{f)4@r!   c                    t         |   |       |j                  rdnd}| j                  j	                  d||j
                         y )Nr   r   zDeleted %s: %s)ra   rI   r   r   r   r   r   s      r"   rI   zLoggingEventHandler.on_deleted  r   r!   c                    t         |   |       |j                  rdnd}| j                  j	                  d||j
                         y )Nr   r   zModified %s: %s)ra   rJ   r   r   r   r   r   s      r"   rJ   zLoggingEventHandler.on_modified  s:    E"#00{f*D%..Ar!   c                p    t         |   |       | j                  j                  d|j                         y )NzClosed file: %s)ra   rL   r   r   r   rO   rP   rk   s     r"   rL   zLoggingEventHandler.on_closed  )    % *ENN;r!   c                p    t         |   |       | j                  j                  d|j                         y )NzOpened file: %s)ra   rM   r   r   r   r   s     r"   rM   zLoggingEventHandler.on_opened  r   r!   r`   )r   zOptional[logging.Logger]r[   r\   rZ   )r   r   r   r   rb   rK   rH   rI   rJ   rL   rM   r   r   s   @r"   r   r     s2    '-[AAB<
< <r!   r   c              #  |  K   t        j                  |      D ]  \  }}}|D ]H  }t         j                  j                  ||      }| r|j	                  ||       nd}t        ||d       J |D ]H  }t         j                  j                  ||      }| r|j	                  ||       nd}t        ||d       J  yw)a  Generates an event list of :class:`DirMovedEvent` and
    :class:`FileMovedEvent` objects for all the files and directories within
    the given moved directory that were moved along with the directory.

    :param src_dir_path:
        The source path of the moved directory.
    :param dest_dir_path:
        The destination path of the moved directory.
    :returns:
        An iterable of file system events of type :class:`DirMovedEvent` and
        :class:`FileMovedEvent`.
    r   Tr   N)r|   walkpathjoinreplacerB   r1   )	src_dir_pathdest_dir_pathr   directories	filenamesr   	full_pathrenamed_pathfilenames	            r"   generate_sub_moved_eventsr     s      )+(>$k9$IT95IMY9,,]LI_aLidKK % "HT84IMY9,,]LI_aL ytLL " )?s   B:B<c              #    K   t        j                  |       D ]n  \  }}}|D ]/  }t        t         j                  j	                  ||      d       1 |D ]/  }t        t         j                  j	                  ||      d       1 p yw)a  Generates an event list of :class:`DirCreatedEvent` and
    :class:`FileCreatedEvent` objects for all the files and directories within
    the given moved directory that were moved along with the directory.

    :param src_dir_path:
        The source path of the created directory.
    :returns:
        An iterable of file system events of type :class:`DirCreatedEvent` and
        :class:`FileCreatedEvent`.
    Tr   N)r|   r   r@   r   r   r.   )r   r   r   r   r   r   s         r"   generate_sub_created_eventsr     sn      )+(=$k9$I!"'',,tY"?dSS %!H"277<<h#?dSS " )>s   BB
)&r   
__future__r   r   os.pathr|   r   dataclassesr   r   typingr   watchdog.utils.patternsr   r%   r(   r/   r,   r5   r9   r   r$   r'   r+   r.   r1   r3   r8   r;   r>   r@   rB   rD   r^   r   r   r   r   r    r!   r"   <module>r      s4   KZ #   	 (  3        t. . .*"? "$ $% %$ $K) K#o ##o #o  o ( R RjI$"8 I$XP$ 6 P$f'<0 '<TM0Tr!   