
    zcj?                        d Z ddlZddlZddlZddlmZ dZdZdZ	dZ
dZ 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           Z G d! d"e          Z G d# d$e          Z G d% d&e          Zd' Zd( ZdS ))u+  
: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:: 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:

    N)match_any_pathsmoveddeletedcreatedmodifiedclosedc                   t    e Zd ZdZdZ	 dZ	 dZ	 d Zed             Z	d Z
d Zed             Zd	 Zd
 Zd ZdS )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.
    NFc                     || _         d S N	_src_path)selfsrc_paths     /lib/python3.11/site-packages/watchdog/events.py__init__zFileSystemEvent.__init__   s    !    c                     | j         S )z@Source path of the file system object that triggered this event.r   r   s    r   r   zFileSystemEvent.src_path   s     ~r   c                 *    |                                  S r   )__repr__r   s    r   __str__zFileSystemEvent.__str__   s    }}r   c                 `    dt          | j        j        | j        | j        | j                  z  S )Nza<%(class_name)s: event_type=%(event_type)s, src_path=%(src_path)r, is_directory=%(is_directory)s>)
class_name
event_typer   is_directory)dict	__class____name__r   r   r   r   s    r   r   zFileSystemEvent.__repr__   s=    1  $ 7 $"m"&"3	5 5 56 	6r   c                 *    | j         | j        | j        fS r   )r   r   r   r   s    r   keyzFileSystemEvent.key   s    0ABBr   c                 "    | j         |j         k    S r   r!   r   events     r   __eq__zFileSystemEvent.__eq__       x59$$r   c                 "    | j         |j         k    S r   r#   r$   s     r   __ne__zFileSystemEvent.__ne__   r'   r   c                 *    t          | j                  S r   )hashr!   r   s    r   __hash__zFileSystemEvent.__hash__   s    DH~~r   )r   
__module____qualname____doc__r   r   is_syntheticr   propertyr   r   r   r!   r&   r)   r,    r   r   r
   r
   i   s          J,LEL" " "   X  6 6 6 C C XC% % %% % %    r   r
   c                   X     e Zd ZdZeZ fdZed             Zed             Z	d Z
 xZS )FileSystemMovedEventzJ
    File system event representing any kind of file system movement.
    c                 X    t                                          |           || _        d S r   )superr   
_dest_path)r   r   	dest_pathr   s      r   r   zFileSystemMovedEvent.__init__   s&    """#r   c                     | j         S )z'The destination path of the move event.)r7   r   s    r   r8   zFileSystemMovedEvent.dest_path   s     r   c                 6    | j         | j        | j        | j        fS r   )r   r   r8   r   r   s    r   r!   zFileSystemMovedEvent.key   s    @QRRr   c                 `    dt          | j        j        | j        | j        | j                  z  S )Nz_<%(class_name)s: src_path=%(src_path)r, dest_path=%(dest_path)r, is_directory=%(is_directory)s>)r   r   r8   r   )r   r   r   r   r8   r   r   s    r   r   zFileSystemMovedEvent.__repr__   s<    1 T^%<#'=$(N'+'8: : :; 	;r   )r   r-   r.   r/   EVENT_TYPE_MOVEDr   r   r1   r8   r!   r   __classcell__r   s   @r   r4   r4      s          "J$ $ $ $ $   X
 S S XS; ; ; ; ; ; ;r   r4   c                       e Zd ZdZeZdS )FileDeletedEventz@File system event representing file deletion on the file system.N)r   r-   r.   r/   EVENT_TYPE_DELETEDr   r2   r   r   r@   r@              JJ#JJJr   r@   c                       e Zd ZdZeZdS )FileModifiedEventzDFile system event representing file modification on the file system.N)r   r-   r.   r/   EVENT_TYPE_MODIFIEDr   r2   r   r   rD   rD      s        NN$JJJr   rD   c                       e Zd ZdZeZdS )FileCreatedEventz@File system event representing file creation on the file system.N)r   r-   r.   r/   EVENT_TYPE_CREATEDr   r2   r   r   rG   rG      rB   r   rG   c                       e Zd ZdZdS )FileMovedEventz@File system event representing file movement on the file system.N)r   r-   r.   r/   r2   r   r   rJ   rJ      s        JJJJr   rJ   c                       e Zd ZdZeZdS )FileClosedEventz=File system event representing file close on the file system.N)r   r-   r.   r/   EVENT_TYPE_CLOSEDr   r2   r   r   rL   rL      s        GG"JJJr   rL   c                       e Zd ZdZeZdZdS )DirDeletedEventzEFile system event representing directory deletion on the file system.TN)r   r-   r.   r/   rA   r   r   r2   r   r   rO   rO              OO#JLLLr   rO   c                       e Zd ZdZeZdZdS )DirModifiedEventzS
    File system event representing directory modification on the file system.
    TN)r   r-   r.   r/   rE   r   r   r2   r   r   rR   rR      s$          %JLLLr   rR   c                       e Zd ZdZeZdZdS )DirCreatedEventzEFile system event representing directory creation on the file system.TN)r   r-   r.   r/   rH   r   r   r2   r   r   rT   rT      rP   r   rT   c                       e Zd ZdZdZdS )DirMovedEventzEFile system event representing directory movement on the file system.TN)r   r-   r.   r/   r   r2   r   r   rV   rV      s        OOLLLr   rV   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
FileSystemEventHandlerzL
    Base file system event handler that you can override methods from.
    c                     |                      |           	 t          | j        t          | j        t
          | j        t          | j        t          | j
        i|j                 |           dS )Dispatches events to the appropriate methods.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        N)on_any_eventrH   
on_createdrA   
on_deletedrE   on_modifiedr<   on_movedrM   	on_closedr   r$   s     r   dispatchzFileSystemEventHandler.dispatch  sq     	%   	!1dmt~	
 
	 "	# 	# 	# 	# 	#r   c                     dS )zCatch-all event handler.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        Nr2   r$   s     r   r[   z#FileSystemEventHandler.on_any_event        r   c                     dS )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`
        Nr2   r$   s     r   r_   zFileSystemEventHandler.on_moved!  rc   r   c                     dS )zCalled when a file or directory is created.

        :param event:
            Event representing file/directory creation.
        :type event:
            :class:`DirCreatedEvent` or :class:`FileCreatedEvent`
        Nr2   r$   s     r   r\   z!FileSystemEventHandler.on_created*  rc   r   c                     dS )zCalled when a file or directory is deleted.

        :param event:
            Event representing file/directory deletion.
        :type event:
            :class:`DirDeletedEvent` or :class:`FileDeletedEvent`
        Nr2   r$   s     r   r]   z!FileSystemEventHandler.on_deleted3  rc   r   c                     dS )zCalled when a file or directory is modified.

        :param event:
            Event representing file/directory modification.
        :type event:
            :class:`DirModifiedEvent` or :class:`FileModifiedEvent`
        Nr2   r$   s     r   r^   z"FileSystemEventHandler.on_modified<  rc   r   c                     dS )zCalled when a file opened for writing is closed.

        :param event:
            Event representing file closing.
        :type event:
            :class:`FileClosedEvent`
        Nr2   r$   s     r   r`   z FileSystemEventHandler.on_closedE  rc   r   N)r   r-   r.   r/   ra   r[   r_   r\   r]   r^   r`   r2   r   r   rX   rX     s         # # #"              r   rX   c                        e Zd ZdZ	 	 d
 fd	Zed             Zed             Zed             Zed             Z	 fd	Z
 xZS )PatternMatchingEventHandlerzR
    Matches given patterns with file paths associated with occurring events.
    NFc                     t                                                       || _        || _        || _        || _        d S r   )r6   r   	_patterns_ignore_patterns_ignore_directories_case_sensitive)r   patternsignore_patternsignore_directoriescase_sensitiver   s        r   r   z$PatternMatchingEventHandler.__init__T  s>    ! /#5 -r   c                     | j         S )zM
        (Read-only)
        Patterns to allow matching event paths.
        )rl   r   s    r   rp   z$PatternMatchingEventHandler.patterns]  s     ~r   c                     | j         S )zN
        (Read-only)
        Patterns to ignore matching event paths.
        )rm   r   s    r   rq   z+PatternMatchingEventHandler.ignore_patternse  s     $$r   c                     | j         S ze
        (Read-only)
        ``True`` if directories should be ignored; ``False`` otherwise.
        rn   r   s    r   rr   z.PatternMatchingEventHandler.ignore_directoriesm       ''r   c                     | j         S z~
        (Read-only)
        ``True`` if path names should be matched sensitive to case; ``False``
        otherwise.
        ro   r   s    r   rs   z*PatternMatchingEventHandler.case_sensitiveu       ##r   c                    | j         r	|j        rdS g }t          |d          r,|                    t	          j        |j                             |j        r,|                    t	          j        |j                             t          || j	        | j
        | j                  r#t                                          |           dS dS )rZ   Nr8   )included_patternsexcluded_patternsrs   )rr   r   hasattrappendosfsdecoder8   r   r   rp   rq   rs   r6   ra   r   r%   pathsr   s      r   ra   z$PatternMatchingEventHandler.dispatch~  s     " 	u'9 	F5+&& 	7LLU_55666> 	6LLU^445555-1]-1-A*.*=? ? ? 	$ GGU#####		$ 	$r   NNFF)r   r-   r.   r/   r   r1   rp   rq   rr   rs   ra   r=   r>   s   @r   rj   rj   O  s          7;:?. . . . . .   X % % X% ( ( X( $ $ X$$ $ $ $ $ $ $ $ $r   rj   c                        e Zd ZdZ	 	 d
 fd	Zed             Zed             Zed             Zed             Z	 fd	Z
 xZS )RegexMatchingEventHandlerzQ
    Matches given regexes with file paths associated with occurring events.
    NFc                 6   t                                                       |dg}nt          |t                    r|g}|g }|r#d |D             | _        d |D             | _        n"d |D             | _        d |D             | _        || _        || _        d S )Nz.*c                 6    g | ]}t          j        |          S r2   recompile.0rs     r   
<listcomp>z6RegexMatchingEventHandler.__init__.<locals>.<listcomp>  s     <<<qRZ]]<<<r   c                 6    g | ]}t          j        |          S r2   r   r   s     r   r   z6RegexMatchingEventHandler.__init__.<locals>.<listcomp>  s     #J#J#JaBJqMM#J#J#Jr   c                 L    g | ]!}t          j        |t           j                  "S r2   r   r   Ir   s     r   r   z6RegexMatchingEventHandler.__init__.<locals>.<listcomp>  s&    BBBQRZ2400BBBr   c                 L    g | ]!}t          j        |t           j                  "S r2   r   r   s     r   r   z6RegexMatchingEventHandler.__init__.<locals>.<listcomp>  s&    #P#P#PABJq"$$7$7#P#P#Pr   )r6   r   
isinstancestr_regexes_ignore_regexesrn   ro   )r   regexesignore_regexesrr   rs   r   s        r   r   z"RegexMatchingEventHandler.__init__  s     	 gGG%% 	 iG 	 N 	Q<<G<<<DM#J#J>#J#J#JD  BB'BBBDM#P#P#P#P#PD #5 -r   c                     | j         S )zL
        (Read-only)
        Regexes to allow matching event paths.
        )r   r   s    r   r   z!RegexMatchingEventHandler.regexes  s     }r   c                     | j         S )zM
        (Read-only)
        Regexes to ignore matching event paths.
        )r   r   s    r   r   z(RegexMatchingEventHandler.ignore_regexes  s     ##r   c                     | j         S rw   rx   r   s    r   rr   z,RegexMatchingEventHandler.ignore_directories  ry   r   c                     | j         S r{   r|   r   s    r   rs   z(RegexMatchingEventHandler.case_sensitive  r}   r   c                    | j         r	|j        rdS g t          |d          r,                    t	          j        |j                             |j        r,                    t	          j        |j                             t          fd| j	        D                       rdS t          fd| j
        D                       r#t                                          |           dS dS )rZ   Nr8   c              3   L   K   | ]}D ]}|                     |          V  d S r   matchr   r   pr   s      r   	<genexpr>z5RegexMatchingEventHandler.dispatch.<locals>.<genexpr>  s:      FFaFF1qwwqzzFFFFFFFr   c              3   L   K   | ]}D ]}|                     |          V  d S r   r   r   s      r   r   z5RegexMatchingEventHandler.dispatch.<locals>.<genexpr>  s:      ??a??Aqwwqzz???????r   )rr   r   r   r   r   r   r8   r   anyr   r   r6   ra   r   s     @r   ra   z"RegexMatchingEventHandler.dispatch  s     " 	u'9 	F5+&& 	7LLU_55666> 	6LLU^44555FFFF4#6FFFFF 	F????4<????? 	$GGU#####	$ 	$r   r   )r   r-   r.   r/   r   r1   r   r   rr   rs   ra   r=   r>   s   @r   r   r     s          59:?. . . . . .&   X $ $ X$ ( ( X( $ $ X$$ $ $ $ $ $ $ $ $r   r   c                   L     e Zd ZdZd fd	Z fdZ fdZ fdZ fdZ xZ	S )	LoggingEventHandlerzLogs all the events captured.Nc                 n    t                                                       |pt          j        | _        d S r   )r6   r   loggingrootlogger)r   r   r   s     r   r   zLoggingEventHandler.__init__  s+    ,r   c                     t                                          |           |j        rdnd}| j                            d||j        |j                   d S )N	directoryfilezMoved %s: from %s to %s)r6   r_   r   r   infor   r8   r   r%   whatr   s      r   r_   zLoggingEventHandler.on_moved  s^    #0<{{f2D%.	* 	* 	* 	* 	*r   c                     t                                          |           |j        rdnd}| j                            d||j                   d S )Nr   r   zCreated %s: %s)r6   r\   r   r   r   r   r   s      r   r\   zLoggingEventHandler.on_created  O    5!!!#0<{{f)4@@@@@r   c                     t                                          |           |j        rdnd}| j                            d||j                   d S )Nr   r   zDeleted %s: %s)r6   r]   r   r   r   r   r   s      r   r]   zLoggingEventHandler.on_deleted  r   r   c                     t                                          |           |j        rdnd}| j                            d||j                   d S )Nr   r   zModified %s: %s)r6   r^   r   r   r   r   r   s      r   r^   zLoggingEventHandler.on_modified  sO    E"""#0<{{f*D%.AAAAAr   r   )
r   r-   r.   r/   r   r_   r\   r]   r^   r=   r>   s   @r   r   r     s        ''- - - - - -
* * * * *A A A A AA A A A AB B B B B B B B Br   r   c              #     K   t          j        |          D ]\  }}}|D ]W}t           j                            ||          }| r|                    ||           nd}t          ||          }d|_        |V  X|D ]W}	t           j                            ||	          }| r|                    ||           nd}t          ||          }d|_        |V  XdS )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`.
    NT)r   walkpathjoinreplacerV   r0   rJ   )
src_dir_pathdest_dir_pathr   directories	filenamesr   	full_pathrenamed_pathr%   filenames
             r   generate_sub_moved_eventsr   	  s      )+(>(>  $k9$ 	 	IT955IMYc9,,]LIII_cL!,	::E!%EKKKK! 	 	HT844IMYc9,,]LIII_cL"<;;E!%EKKKK	 r   c              #   4  K   t          j        |           D ]\  }}}|D ]:}t          t           j                            ||                    }d|_        |V  ;|D ]:}t          t           j                            ||                    }d|_        |V  ;dS )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`.
    TN)r   r   rT   r   r   r0   rG   )r   r   r   r   r   r%   r   s          r   generate_sub_created_eventsr   %  s       )+(=(=  $k9$ 	 	I#BGLLy$A$ABBE!%EKKKK! 	 	H$RW\\$%A%ABBE!%EKKKK	 r   )r/   os.pathr   r   r   watchdog.utils.patternsr   r<   rA   rH   rE   rM   r
   r4   r@   rD   rG   rJ   rL   rO   rR   rT   rV   rX   rj   r   r   r   r   r2   r   r   <module>r      s.  $H HT   				 3 3 3 3 3 3       8 8 8 8 8 8 8 8v; ; ; ; ;? ; ; ;D$ $ $ $ $ $ $ $% % % % % % % %$ $ $ $ $ $ $ $K K K K K) K K K# # # # #o # # #    o              o       (   J J J J J J J JZD$ D$ D$ D$ D$"8 D$ D$ D$NN$ N$ N$ N$ N$ 6 N$ N$ N$bB B B B B0 B B BD  8    r   