
    $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 erddlmZ d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*e          Z# G d+ d,          Z$ G d- d.e$          Z% G d/ d0e$          Z& G d1 d2e$          Z'd;d8Z(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                      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<   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        O/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/watchdog/events.pyr   r   h   s           IeBU333J3333u5999L9999
 u---L------r$   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'   ~   s        JJ!JJJr$   r'   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   r#   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   r#   r$   r%   r.   r.      s        NN$JJJr$   r.   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   r#   r$   r%   r1   r1      r,   r$   r1   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!   r#   r$   r%   r4   r4      s        JJJJr$   r4   c                      e Zd ZdZeZdS )FileClosedEvent=File system event representing file close on the file system.N)r   r   r    r!   EVENT_TYPE_CLOSEDr   r#   r$   r%   r6   r6              GG"JJJr$   r6   c                      e Zd ZdZeZdS )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;   r;      s        UU+JJJr$   r;   c                      e Zd ZdZeZdS )FileOpenedEventr7   N)r   r   r    r!   EVENT_TYPE_OPENEDr   r#   r$   r%   r>   r>      r9   r$   r>   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%   rA   rA              OO#JLLLr$   rA   c                      e Zd ZdZeZdZdS )DirModifiedEventzIFile system event representing directory modification on the file system.TN)r   r   r    r!   r/   r   r   r#   r$   r%   rD   rD      s        SS$JLLLr$   rD   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!   r2   r   r   r#   r$   r%   rF   rF      rB   r$   rF   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   r#   r$   r%   rH   rH      s        OOLLLr$   rH   c                  Z    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ddZdS )FileSystemEventHandlerzBBase file system event handler that you can override methods from.eventr   returnNonec                r    |                      |            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   selfrK   s     r%   dispatchzFileSystemEventHandler.dispatch   sD     	%   /.E,..//66666r$   c                    dS )zCatch-all event handler.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        Nr#   rS   s     r%   rQ   z#FileSystemEventHandler.on_any_event         r$   DirMovedEvent | FileMovedEventc                    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`
        Nr#   rS   s     r%   on_movedzFileSystemEventHandler.on_moved   rW   r$   "DirCreatedEvent | FileCreatedEventc                    dS )zCalled when a file or directory is created.

        :param event:
            Event representing file/directory creation.
        :type event:
            :class:`DirCreatedEvent` or :class:`FileCreatedEvent`
        Nr#   rS   s     r%   
on_createdz!FileSystemEventHandler.on_created   rW   r$   "DirDeletedEvent | FileDeletedEventc                    dS )zCalled when a file or directory is deleted.

        :param event:
            Event representing file/directory deletion.
        :type event:
            :class:`DirDeletedEvent` or :class:`FileDeletedEvent`
        Nr#   rS   s     r%   
on_deletedz!FileSystemEventHandler.on_deleted   rW   r$   $DirModifiedEvent | FileModifiedEventc                    dS )zCalled when a file or directory is modified.

        :param event:
            Event representing file/directory modification.
        :type event:
            :class:`DirModifiedEvent` or :class:`FileModifiedEvent`
        Nr#   rS   s     r%   on_modifiedz"FileSystemEventHandler.on_modified   rW   r$   r6   c                    dS )zCalled when a file opened for writing is closed.

        :param event:
            Event representing file closing.
        :type event:
            :class:`FileClosedEvent`
        Nr#   rS   s     r%   	on_closedz FileSystemEventHandler.on_closed  rW   r$   r;   c                    dS )zCalled when a file opened for reading is closed.

        :param event:
            Event representing file closing.
        :type event:
            :class:`FileClosedNoWriteEvent`
        Nr#   rS   s     r%   on_closed_no_writez)FileSystemEventHandler.on_closed_no_write  rW   r$   r>   c                    dS )zCalled when a file is opened.

        :param event:
            Event representing file opening.
        :type event:
            :class:`FileOpenedEvent`
        Nr#   rS   s     r%   	on_openedz FileSystemEventHandler.on_opened  rW   r$   NrK   r   rL   rM   rK   rX   rL   rM   rK   r[   rL   rM   rK   r^   rL   rM   rK   ra   rL   rM   rK   r6   rL   rM   rK   r;   rL   rM   rK   r>   rL   rM   )r   r   r    r!   rU   rQ   rZ   r]   r`   rc   re   rg   ri   r#   r$   r%   rJ   rJ      s        LL	7 	7 	7 	7                          r$   rJ   c                       e Zd ZdZdddddd fdZedd            Zedd            Zedd            Zedd            Z	d fdZ
 x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_sensitivert   list[str] | Noneru   rv   r   rw   c                   t                                                       || _        || _        || _        || _        d S N)super__init__	_patterns_ignore_patterns_ignore_directories_case_sensitive)rT   rt   ru   rv   rw   	__class__s        r%   r|   z$PatternMatchingEventHandler.__init__*  s@     	! /#5 -r$   rL   c                    | j         S )zD(Read-only)
        Patterns to allow matching event paths.
        )r}   rT   s    r%   rt   z$PatternMatchingEventHandler.patterns9  s    
 ~r$   c                    | j         S )zE(Read-only)
        Patterns to ignore matching event paths.
        )r~   r   s    r%   ru   z+PatternMatchingEventHandler.ignore_patterns@  s    
 $$r$   c                    | j         S z\(Read-only)
        ``True`` if directories should be ignored; ``False`` otherwise.
        r   r   s    r%   rv   z.PatternMatchingEventHandler.ignore_directoriesG      
 ''r$   c                    | j         S zu(Read-only)
        ``True`` if path names should be matched sensitive to case; ``False``
        otherwise.
        r   r   s    r%   rw   z*PatternMatchingEventHandler.case_sensitiveN       ##r$   rK   r   rM   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 )rO   Nr   )included_patternsexcluded_patternsrw   )rv   r   hasattrappendosfsdecoder   r   r   rt   ru   rw   r{   rU   rT   rK   pathsr   s      r%   rU   z$PatternMatchingEventHandler.dispatchV  s     " 	u'9 	F5+&& 	7LLU_55666> 	6LLU^44555"m"2.	
 
 
 	$ GGU#####	$ 	$r$   )rt   rx   ru   rx   rv   r   rw   r   )rL   rx   rL   r   rj   )r   r   r    r!   r|   propertyrt   ru   rv   rw   rU   __classcell__r   s   @r%   rs   rs   $  s          &*,0#($. . . . . . . .    X % % % X% ( ( ( X( $ $ $ X$$ $ $ $ $ $ $ $ $ $r$   rs   c                       e Zd ZdZdddddd fdZedd            Zedd            Zedd            Zedd            Z	d fdZ
 xZS )RegexMatchingEventHandlerzfMatches given regexes with file paths associated with occurring events.
    Uses the `re` module.
    NF)regexesignore_regexesrv   rw   r   rx   r   rv   r   rw   c               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 r#   recompile.0rs     r%   
<listcomp>z6RegexMatchingEventHandler.__init__.<locals>.<listcomp>  s     <<<qRZ]]<<<r$   c                6    g | ]}t          j        |          S r#   r   r   s     r%   r   z6RegexMatchingEventHandler.__init__.<locals>.<listcomp>  s     #J#J#JaBJqMM#J#J#Jr$   c                L    g | ]!}t          j        |t           j                  "S r#   r   r   
IGNORECASEr   s     r%   r   z6RegexMatchingEventHandler.__init__.<locals>.<listcomp>  s&    KKKaRZ2=99KKKr$   c                L    g | ]!}t          j        |t           j                  "S r#   r   r   s     r%   r   z6RegexMatchingEventHandler.__init__.<locals>.<listcomp>  s&    #Y#Y#YQBJq"-$@$@#Y#Y#Yr$   )r{   r|   
isinstancer   _regexes_ignore_regexesr   r   )rT   r   r   rv   rw   r   s        r%   r|   z"RegexMatchingEventHandler.__init__u  s     	?gGG%% 	 iG!N 	Z<<G<<<DM#J#J>#J#J#JD  KK7KKKDM#Y#Y.#Y#Y#YD #5 -r$   rL   list[re.Pattern[str]]c                    | j         S )zC(Read-only)
        Regexes to allow matching event paths.
        )r   r   s    r%   r   z!RegexMatchingEventHandler.regexes  s    
 }r$   c                    | j         S )zD(Read-only)
        Regexes to ignore matching event paths.
        )r   r   s    r%   r   z(RegexMatchingEventHandler.ignore_regexes  s    
 ##r$   c                    | j         S r   r   r   s    r%   rv   z,RegexMatchingEventHandler.ignore_directories  r   r$   c                    | j         S r   r   r   s    r%   rw   z(RegexMatchingEventHandler.case_sensitive  r   r$   rK   r   rM   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 )rO   Nr   c              3  L   K   | ]}D ]}|                     |          V  d S rz   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 rz   r   r   s      r%   r   z5RegexMatchingEventHandler.dispatch.<locals>.<genexpr>  s:      ??a??Aqwwqzz???????r$   )rv   r   r   r   r   r   r   r   anyr   r   r{   rU   r   s     @r%   rU   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   rx   r   rx   rv   r   rw   r   )rL   r   r   rj   )r   r   r    r!   r|   r   r   r   rv   rw   rU   r   r   s   @r%   r   r   p  s          %)+/#($. . . . . . . .2    X $ $ $ X$ ( ( ( X( $ $ $ X$$ $ $ $ $ $ $ $ $ $r$   r   c                  ~     e Zd ZdZd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
d fdZ xZS ) LoggingEventHandlerzLogs all the events captured.N)loggerr   logging.Logger | NonerL   rM   c               n    t                                                       |pt          j        | _        d S rz   )r{   r|   loggingrootr   )rT   r   r   s     r%   r|   zLoggingEventHandler.__init__  s+    ,r$   rK   rX   c                    t                                          |           |j        rdnd}| j                            d||j        |j                   d S )N	directoryfilezMoved %s: from %s to %s)r{   rZ   r   r   infor   r   rT   rK   whatr   s      r%   rZ   zLoggingEventHandler.on_moved  sS    #0<{{f2D%.%/ZZZZZr$   r[   c                    t                                          |           |j        rdnd}| j                            d||j                   d S )Nr   r   zCreated %s: %s)r{   r]   r   r   r   r   r   s      r%   r]   zLoggingEventHandler.on_created  O    5!!!#0<{{f)4@@@@@r$   r^   c                    t                                          |           |j        rdnd}| j                            d||j                   d S )Nr   r   zDeleted %s: %s)r{   r`   r   r   r   r   r   s      r%   r`   zLoggingEventHandler.on_deleted  r   r$   ra   c                    t                                          |           |j        rdnd}| j                            d||j                   d S )Nr   r   zModified %s: %s)r{   rc   r   r   r   r   r   s      r%   rc   zLoggingEventHandler.on_modified  sO    E"""#0<{{f*D%.AAAAAr$   r6   c                    t                                          |           | j                            d|j                   d S )NzClosed modified file: %s)r{   re   r   r   r   rT   rK   r   s     r%   re   zLoggingEventHandler.on_closed  s<    %   3U^DDDDDr$   r;   c                    t                                          |           | j                            d|j                   d S )NzClosed read file: %s)r{   rg   r   r   r   r   s     r%   rg   z&LoggingEventHandler.on_closed_no_write  s<    ""5)))/@@@@@r$   r>   c                    t                                          |           | j                            d|j                   d S )NzOpened file: %s)r{   ri   r   r   r   r   s     r%   ri   zLoggingEventHandler.on_opened  s<    %   *EN;;;;;r$   )r   r   rL   rM   rk   rl   rm   rn   ro   rp   rq   )r   r   r    r!   r|   rZ   r]   r`   rc   re   rg   ri   r   r   s   @r%   r   r     sF       '':> - - - - - - - -[ [ [ [ [ [A A A A A AA A A A A AB B B B B BE E E E E E
A A A A A A
< < < < < < < < < <r$   r   src_dir_pathr   dest_dir_pathrL   )Generator[DirMovedEvent | FileMovedEvent]c              #    K   t          j        |          D ]\  }}}|D ]P}t           j                            ||          }| r|                    ||           nd}t          ||d          V  Q|D ]P}t           j                            ||          }| r|                    ||           nd}t          ||d          V  Qd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)r   walkpathjoinreplacerH   r4   )	r   r   r   directories	filenamesr   	full_pathrenamed_pathfilenames	            r%   generate_sub_moved_eventsr     s       )+(>(> M M$k9$ 	L 	LIT955IMYa9,,]LIII_aLidKKKKKKK! 	M 	MHT844IMYa9,,]LIII_aL ytLLLLLLL	MM Mr$   -Generator[DirCreatedEvent | FileCreatedEvent]c              #     K   t          j        |           D ]v\  }}}|D ]5}t           j                            ||          }t	          |d          V  6|D ]5}t           j                            ||          }t          |d          V  6wd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)r   r   r   r   rF   r1   )r   r   r   r   r   r   r   s          r%   generate_sub_created_eventsr     s       )+(=(= A A$k9$ 	@ 	@IT955I!)$???????! 	A 	AHT844I"94@@@@@@@	A	A Ar$   )r   r   r   r   rL   r   )r   r   rL   r   )*r!   
__future__r   r   os.pathr   r   dataclassesr   r   typingr   watchdog.utils.patternsr   collections.abcr   r(   r+   r2   r/   r8   r<   r?   r   r'   r*   r.   r1   r4   r6   r;   r>   rA   rD   rF   rH   rJ   rs   r   r   r   r   r#   r$   r%   <module>r      s  O Ob # " " " " "   				 ( ( ( ( ( ( ( (             3 3 3 3 3 3 *))))))      .   t. . . . . . . .*" " " " "? " " "$ $ $ $ $ $ $ $% % % % % % % %$ $ $ $ $ $ $ $K K K K K) K K K# # # # #o # # #, , , , ,_ , , ,# # # # #o # # #    o              o       (   T T T T T T T TnI$ I$ I$ I$ I$"8 I$ I$ I$XP$ P$ P$ P$ P$ 6 P$ P$ P$f,< ,< ,< ,< ,<0 ,< ,< ,<^M M M M6A A A A A Ar$   