o
    h?                     @  s  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 er0ddlmZ dZd	Zd
ZdZdZdZdZeddG dd dZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZ G d%d& d&eZ!G d'd( d(eZ"G d)d* d*eZ#G d+d, d,Z$G d-d. d.e$Z%G d/d0 d0e$Z&G d1d2 d2e$Z'd=d8d9Z(d>d;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:: FileClosedNoWriteEvent
   :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)TYPE_CHECKING)match_any_paths)	Generatormoveddeletedcreatedmodifiedclosedclosed_no_writeopenedT)unsafe_hashc                   @  sb   e Zd ZU dZded< dZded< edddZded	< edddZd
ed< 	 eddZ	d
ed< 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.
    bytes | strsrc_path 	dest_pathF)defaultinitstr
event_typeboolis_directory)r   is_syntheticN)
__name__
__module____qualname____doc____annotations__r   r   r   r   r    r!   r!   C/var/www/vscode/kcb/lib/python3.10/site-packages/watchdog/events.pyr   h   s   
 r   c                   @     e Zd ZdZeZdS )FileSystemMovedEventz@File system event representing any kind of file system movement.N)r   r   r   r   EVENT_TYPE_MOVEDr   r!   r!   r!   r"   r$   ~       r$   c                   @  r#   )FileDeletedEventz@File system event representing file deletion on the file system.N)r   r   r   r   EVENT_TYPE_DELETEDr   r!   r!   r!   r"   r'      r&   r'   c                   @  r#   )FileModifiedEventzDFile system event representing file modification on the file system.N)r   r   r   r   EVENT_TYPE_MODIFIEDr   r!   r!   r!   r"   r)      r&   r)   c                   @  r#   )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+   c                   @  s   e Zd ZdZdS )FileMovedEventz@File system event representing file movement on the file system.N)r   r   r   r   r!   r!   r!   r"   r-      s    r-   c                   @  r#   )FileClosedEvent=File system event representing file close on the file system.N)r   r   r   r   EVENT_TYPE_CLOSEDr   r!   r!   r!   r"   r.      r&   r.   c                   @  r#   )FileClosedNoWriteEventzKFile system event representing an unmodified file close on the file system.N)r   r   r   r   EVENT_TYPE_CLOSED_NO_WRITEr   r!   r!   r!   r"   r1      r&   r1   c                   @  r#   )FileOpenedEventr/   N)r   r   r   r   EVENT_TYPE_OPENEDr   r!   r!   r!   r"   r3      r&   r3   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   r(   r   r   r!   r!   r!   r"   r6          r6   c                   @  r5   )DirModifiedEventzIFile system event representing directory modification on the file system.TN)r   r   r   r   r*   r   r   r!   r!   r!   r"   r8      r7   r8   c                   @  r5   )DirCreatedEventzEFile system event representing directory creation on the file system.TN)r   r   r   r   r,   r   r   r!   r!   r!   r"   r9      r7   r9   c                   @  s   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   r!   r!   r!   r"   r:      r&   r:   c                   @  sj   e Zd ZdZd ddZd dd	Zd!ddZd"ddZd#ddZd$ddZ	d%ddZ
d&ddZd'ddZdS )(FileSystemEventHandlerzBBase file system event handler that you can override methods from.eventr   returnNonec                 C  s$   |  | t| d|j | dS )Dispatches events to the appropriate methods.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        on_N)on_any_eventgetattrr   selfr<   r!   r!   r"   dispatch   s   
zFileSystemEventHandler.dispatchc                 C     dS )zCatch-all event handler.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        Nr!   rC   r!   r!   r"   rA          z#FileSystemEventHandler.on_any_eventDirMovedEvent | FileMovedEventc                 C  rF   )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!   rC   r!   r!   r"   on_moved   rG   zFileSystemEventHandler.on_moved"DirCreatedEvent | FileCreatedEventc                 C  rF   )zCalled when a file or directory is created.

        :param event:
            Event representing file/directory creation.
        :type event:
            :class:`DirCreatedEvent` or :class:`FileCreatedEvent`
        Nr!   rC   r!   r!   r"   
on_created   rG   z!FileSystemEventHandler.on_created"DirDeletedEvent | FileDeletedEventc                 C  rF   )zCalled when a file or directory is deleted.

        :param event:
            Event representing file/directory deletion.
        :type event:
            :class:`DirDeletedEvent` or :class:`FileDeletedEvent`
        Nr!   rC   r!   r!   r"   
on_deleted   rG   z!FileSystemEventHandler.on_deleted$DirModifiedEvent | FileModifiedEventc                 C  rF   )zCalled when a file or directory is modified.

        :param event:
            Event representing file/directory modification.
        :type event:
            :class:`DirModifiedEvent` or :class:`FileModifiedEvent`
        Nr!   rC   r!   r!   r"   on_modified   rG   z"FileSystemEventHandler.on_modifiedr.   c                 C  rF   )zCalled when a file opened for writing is closed.

        :param event:
            Event representing file closing.
        :type event:
            :class:`FileClosedEvent`
        Nr!   rC   r!   r!   r"   	on_closed  rG   z FileSystemEventHandler.on_closedr1   c                 C  rF   )zCalled when a file opened for reading is closed.

        :param event:
            Event representing file closing.
        :type event:
            :class:`FileClosedNoWriteEvent`
        Nr!   rC   r!   r!   r"   on_closed_no_write  rG   z)FileSystemEventHandler.on_closed_no_writer3   c                 C  rF   )zCalled when a file is opened.

        :param event:
            Event representing file opening.
        :type event:
            :class:`FileOpenedEvent`
        Nr!   rC   r!   r!   r"   	on_opened  rG   z FileSystemEventHandler.on_openedNr<   r   r=   r>   r<   rH   r=   r>   r<   rJ   r=   r>   r<   rL   r=   r>   r<   rN   r=   r>   r<   r.   r=   r>   r<   r1   r=   r>   r<   r3   r=   r>   )r   r   r   r   rE   rA   rI   rK   rM   rO   rP   rQ   rR   r!   r!   r!   r"   r;      s    


	
	
	
	
	
		r;   c                      st   e Zd ZdZdddddd fddZedddZedddZedddZedddZ	d fddZ
  ZS )PatternMatchingEventHandlerzMatches 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.
    NF)patternsignore_patternsignore_directoriescase_sensitiver\   list[str] | Noner]   r^   r   r_   c                  s&   t    || _|| _|| _|| _d S N)super__init__	_patterns_ignore_patterns_ignore_directories_case_sensitive)rD   r\   r]   r^   r_   	__class__r!   r"   rc   *  s
   

z$PatternMatchingEventHandler.__init__r=   c                 C     | j S )zD(Read-only)
        Patterns to allow matching event paths.
        )rd   rD   r!   r!   r"   r\   9     z$PatternMatchingEventHandler.patternsc                 C  rj   )zE(Read-only)
        Patterns to ignore matching event paths.
        )re   rk   r!   r!   r"   r]   @  rl   z+PatternMatchingEventHandler.ignore_patternsc                 C  rj   z\(Read-only)
        ``True`` if directories should be ignored; ``False`` otherwise.
        rf   rk   r!   r!   r"   r^   G  rl   z.PatternMatchingEventHandler.ignore_directoriesc                 C  rj   zu(Read-only)
        ``True`` if path names should be matched sensitive to case; ``False``
        otherwise.
        rg   rk   r!   r!   r"   r_   N     z*PatternMatchingEventHandler.case_sensitiver<   r   r>   c                   sr   | j r|jrdS g }t|dr|t|j |jr$|t|j t|| j	| j
| jdr7t | dS dS )r?   Nr   )included_patternsexcluded_patternsr_   )r^   r   hasattrappendosfsdecoder   r   r   r\   r]   r_   rb   rE   )rD   r<   pathsrh   r!   r"   rE   V  s   
z$PatternMatchingEventHandler.dispatch)r\   r`   r]   r`   r^   r   r_   r   )r=   r`   r=   r   rS   )r   r   r   r   rc   propertyr\   r]   r^   r_   rE   __classcell__r!   r!   rh   r"   r[   $  s     r[   c                      st   e Zd ZdZdddddd fddZedddZedddZedddZedddZ	d fddZ
  ZS ) RegexMatchingEventHandlerzfMatches given regexes with file paths associated with occurring events.
    Uses the `re` module.
    NF)regexesignore_regexesr^   r_   r}   r`   r~   r^   r   r_   c                  s   t    |d u rdg}nt|tr|g}|d u rg }|r.dd |D | _dd |D | _ndd |D | _dd |D | _|| _|| _d S )Nz.*c                 S     g | ]}t |qS r!   recompile.0rr!   r!   r"   
<listcomp>      z6RegexMatchingEventHandler.__init__.<locals>.<listcomp>c                 S  r   r!   r   r   r!   r!   r"   r     r   c                 S     g | ]	}t |t jqS r!   r   r   
IGNORECASEr   r!   r!   r"   r         c                 S  r   r!   r   r   r!   r!   r"   r     r   )rb   rc   
isinstancer   _regexes_ignore_regexesrf   rg   )rD   r}   r~   r^   r_   rh   r!   r"   rc   u  s   


z"RegexMatchingEventHandler.__init__r=   list[re.Pattern[str]]c                 C  rj   )zC(Read-only)
        Regexes to allow matching event paths.
        )r   rk   r!   r!   r"   r}     rl   z!RegexMatchingEventHandler.regexesc                 C  rj   )zD(Read-only)
        Regexes to ignore matching event paths.
        )r   rk   r!   r!   r"   r~     rl   z(RegexMatchingEventHandler.ignore_regexesc                 C  rj   rm   rn   rk   r!   r!   r"   r^     rl   z,RegexMatchingEventHandler.ignore_directoriesc                 C  rj   ro   rp   rk   r!   r!   r"   r_     rq   z(RegexMatchingEventHandler.case_sensitiver<   r   r>   c                   s   | j r|jrdS g  t|dr t|j |jr$ t|j t fdd| j	D r2dS t fdd| j
D rFt | dS dS )r?   Nr   c                 3  $    | ]} D ]}| |V  qqd S ra   matchr   r   prx   r!   r"   	<genexpr>     " z5RegexMatchingEventHandler.dispatch.<locals>.<genexpr>c                 3  r   ra   r   r   r   r!   r"   r     r   )r^   r   rt   ru   rv   rw   r   r   anyr~   r}   rb   rE   rC   rh   r   r"   rE     s   
z"RegexMatchingEventHandler.dispatch)r}   r`   r~   r`   r^   r   r_   r   )r=   r   ry   rS   )r   r   r   r   rc   rz   r}   r~   r^   r_   rE   r{   r!   r!   rh   r"   r|   p  s     r|   c                      s   e Zd ZdZddd  fdd	Zd! fddZd" fddZd# fddZd$ fddZd% fddZ	d& fddZ
d' fddZ  ZS )(LoggingEventHandlerzLogs all the events captured.N)loggerr   logging.Logger | Noner=   r>   c                  s   t    |p	tj| _d S ra   )rb   rc   loggingrootr   )rD   r   rh   r!   r"   rc     s   
zLoggingEventHandler.__init__r<   rH   c                   s4   t  | |jrdnd}| jd||j|j d S )N	directoryfilezMoved %s: from %s to %s)rb   rI   r   r   infor   r   rD   r<   whatrh   r!   r"   rI     s   zLoggingEventHandler.on_movedrJ   c                   0   t  | |jrdnd}| jd||j d S )Nr   r   zCreated %s: %s)rb   rK   r   r   r   r   r   rh   r!   r"   rK        zLoggingEventHandler.on_createdrL   c                   r   )Nr   r   zDeleted %s: %s)rb   rM   r   r   r   r   r   rh   r!   r"   rM     r   zLoggingEventHandler.on_deletedrN   c                   r   )Nr   r   zModified %s: %s)rb   rO   r   r   r   r   r   rh   r!   r"   rO     r   zLoggingEventHandler.on_modifiedr.   c                       t  | | jd|j d S )NzClosed modified file: %s)rb   rP   r   r   r   rC   rh   r!   r"   rP        zLoggingEventHandler.on_closedr1   c                   r   )NzClosed read file: %s)rb   rQ   r   r   r   rC   rh   r!   r"   rQ     r   z&LoggingEventHandler.on_closed_no_writer3   c                   r   )NzOpened file: %s)rb   rR   r   r   r   rC   rh   r!   r"   rR     r   zLoggingEventHandler.on_opened)r   r   r=   r>   rT   rU   rV   rW   rX   rY   rZ   )r   r   r   r   rc   rI   rK   rM   rO   rP   rQ   rR   r{   r!   r!   rh   r"   r     s    r   src_dir_pathr   dest_dir_pathr=   )Generator[DirMovedEvent | FileMovedEvent]c           	      c  s    t |D ]A\}}}|D ]}t j||}| r||| nd}t||ddV  q|D ]}t j||}| r<||| nd}t||ddV  q+qd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`.
    r   Tr   N)rv   walkpathjoinreplacer:   r-   )	r   r   r   directories	filenamesr   	full_pathrenamed_pathfilenamer!   r!   r"   generate_sub_moved_events  s   r   -Generator[DirCreatedEvent | FileCreatedEvent]c                 c  sh    t | D ]+\}}}|D ]}t j||}t|ddV  q|D ]}t j||}t|ddV  q q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`.
    Tr   N)rv   r   r   r   r9   r+   )r   r   r   r   r   r   r   r!   r!   r"   generate_sub_created_events  s   r   )r   r   r   r   r=   r   )r   r   r=   r   )*r   
__future__r   r   os.pathrv   r   dataclassesr   r   typingr   watchdog.utils.patternsr   collections.abcr   r%   r(   r,   r*   r0   r2   r4   r   r$   r'   r)   r+   r-   r.   r1   r3   r6   r8   r9   r:   r;   r[   r|   r   r   r   r!   r!   r!   r"   <module>   sJ    Q		WLS
/