
    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'	 	 	 	 	 	 d5d3Z(d6d4Z)y)7u  :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<   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.
    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        D/var/www/openai/venv/lib/python3.12/site-packages/watchdog/events.pyr   r   h   sQ     I{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%   r1   r1      r,   r$   r1   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%   r4   r4      s    Jr$   r4   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%   r6   r6      
    G"Jr$   r6   c                      e Zd ZdZeZy)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+Jr$   r;   c                      e Zd ZdZeZy)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y)DirDeletedEventzEFile system event representing directory deletion on the file system.TN)r   r   r    r!   r+   r   r   r#   r$   r%   rA   rA          O#JLr$   rA   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%   rD   rD      s    S$JLr$   rD   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!   r2   r   r   r#   r$   r%   rF   rF      rB   r$   rF   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%   rH   rH      s
    OLr$   rH   c                  X    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y)FileSystemEventHandlerzBBase file system event handler that you can override methods from.c                d    | j                  |        t        | d|j                         |       y)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   selfevents     r%   dispatchzFileSystemEventHandler.dispatch   s1     	% /E,,-./6r$   c                     y)zCatch-all event handler.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        Nr#   rP   s     r%   rN   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#   rP   s     r%   on_movedzFileSystemEventHandler.on_moved   rU   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#   rP   s     r%   
on_createdz!FileSystemEventHandler.on_created   rU   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#   rP   s     r%   
on_deletedz!FileSystemEventHandler.on_deleted   rU   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#   rP   s     r%   on_modifiedz"FileSystemEventHandler.on_modified   rU   r$   c                     y)zCalled when a file opened for writing is closed.

        :param event:
            Event representing file closing.
        :type event:
            :class:`FileClosedEvent`
        Nr#   rP   s     r%   	on_closedz FileSystemEventHandler.on_closed  rU   r$   c                     y)zCalled when a file opened for reading is closed.

        :param event:
            Event representing file closing.
        :type event:
            :class:`FileClosedNoWriteEvent`
        Nr#   rP   s     r%   on_closed_no_writez)FileSystemEventHandler.on_closed_no_write  rU   r$   c                     y)zCalled when a file is opened.

        :param event:
            Event representing file opening.
        :type event:
            :class:`FileOpenedEvent`
        Nr#   rP   s     r%   	on_openedz FileSystemEventHandler.on_opened  rU   r$   NrR   r   returnNonerR   zDirMovedEvent | FileMovedEventre   rf   rR   z"DirCreatedEvent | FileCreatedEventre   rf   rR   z"DirDeletedEvent | FileDeletedEventre   rf   rR   z$DirModifiedEvent | FileModifiedEventre   rf   rR   r6   re   rf   rR   r;   re   rf   rR   r>   re   rf   )r   r   r    r!   rS   rN   rW   rY   r[   r]   r_   ra   rc   r#   r$   r%   rJ   rJ      s2    L	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_sensitivec               Z    t         |           || _        || _        || _        || _        y N)super__init__	_patterns_ignore_patterns_ignore_directories_case_sensitive)rQ   rp   rq   rr   rs   	__class__s        r%   rw   z$PatternMatchingEventHandler.__init__*  s/     	! /#5 -r$   c                    | j                   S )zD(Read-only)
        Patterns to allow matching event paths.
        )rx   rQ   s    r%   rp   z$PatternMatchingEventHandler.patterns9  s    
 ~~r$   c                    | j                   S )zE(Read-only)
        Patterns to ignore matching event paths.
        )ry   r~   s    r%   rq   z+PatternMatchingEventHandler.ignore_patterns@  s    
 $$$r$   c                    | j                   S z\(Read-only)
        ``True`` if directories should be ignored; ``False`` otherwise.
        rz   r~   s    r%   rr   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%   rs   z*PatternMatchingEventHandler.case_sensitiveN       ###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)rL   Nr   )included_patternsexcluded_patternsrs   )rr   r   hasattrappendosfsdecoder   r   r   rp   rq   rs   rv   rS   rQ   rR   pathsr|   s      r%   rS   z$PatternMatchingEventHandler.dispatchV  s     ""u'9'95+&LLU__56>>LLU^^45"mm"22..	
 GU#
r$   )rp   list[str] | Nonerq   r   rr   r   rs   r   )re   r   re   r   rd   )r   r   r    r!   rw   propertyrp   rq   rr   rs   rS   __classcell__r|   s   @r%   ro   ro   $  s     &*,0#($. #. *	.
 !. .   % % ( ( $ $$ $r$   ro   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_regexesrr   rs   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.*)rv   rw   
isinstancer   recompile_regexes_ignore_regexes
IGNORECASErz   r{   )rQ   r   r   rr   rs   rr|   s         r%   rw   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   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%   rr   z,RegexMatchingEventHandler.ignore_directories  r   r$   c                    | j                   S r   r   r~   s    r%   rs   z(RegexMatchingEventHandler.case_sensitive  r   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)rL   Nr   c              3  N   K   | ]  }D ]  }|j                  |         y wru   match.0r   pr   s      r%   	<genexpr>z5RegexMatchingEventHandler.dispatch.<locals>.<genexpr>  s$     F#6a1qwwqzz#6   "%c              3  N   K   | ]  }D ]  }|j                  |         y wru   r   r   s      r%   r   z5RegexMatchingEventHandler.dispatch.<locals>.<genexpr>  s"     ?<aAqwwqzz<r   )rr   r   r   r   r   r   r   r   anyr   r   rv   rS   r   s     @r%   rS   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   r   r   r   rr   r   rs   r   )re   zlist[re.Pattern[str]]r   rd   )r   r   r    r!   rw   r   r   r   rr   rs   rS   r   r   s   @r%   r   r   p  s     %)+/#($. ". )	.
 !. .2   $ $ ( ( $ $$ $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)loggerc               T    t         |           |xs t        j                  | _        y ru   )rv   rw   loggingrootr   )rQ   r   r|   s     r%   rw   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)rv   rW   r   r   infor   r   rQ   rR   whatr|   s      r%   rW   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)rv   rY   r   r   r   r   r   s      r%   rY   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)rv   r[   r   r   r   r   r   s      r%   r[   zLoggingEventHandler.on_deleted  r   r$   c                    t         |   |       |j                  rdnd}| j                  j	                  d||j
                         y )Nr   r   zModified %s: %s)rv   r]   r   r   r   r   r   s      r%   r]   zLoggingEventHandler.on_modified  s:    E"#00{f*D%..Ar$   c                p    t         |   |       | j                  j                  d|j                         y )NzClosed modified file: %s)rv   r_   r   r   r   rQ   rR   r|   s     r%   r_   zLoggingEventHandler.on_closed  s)    % 3U^^Dr$   c                p    t         |   |       | j                  j                  d|j                         y )NzClosed read file: %s)rv   ra   r   r   r   r   s     r%   ra   z&LoggingEventHandler.on_closed_no_write  s)    "5)/@r$   c                p    t         |   |       | j                  j                  d|j                         y )NzOpened file: %s)rv   rc   r   r   r   r   s     r%   rc   zLoggingEventHandler.on_opened  s)    % *ENN;r$   )r   zlogging.Logger | Nonere   rf   rg   rh   ri   rj   rk   rl   rm   )r   r   r    r!   rw   rW   rY   r[   r]   r_   ra   rc   r   r   s   @r%   r   r     s<    ':> -[AABE
A
< <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replacerH   r4   )	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 ]r  \  }}}|D ]1  }t         j                  j                  ||      }t	        |d       3 |D ]1  }t         j                  j                  ||      }t        |d       3 t 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   rF   r1   )r   r   r   r   r   r   r   s          r%   generate_sub_created_eventsr     sz      )+(=$k9$IT95I!)$?? % "HT84I"94@@ "	 )>s   BB)r   r   r   r   re   z)Generator[DirMovedEvent | FileMovedEvent])r   r   re   z-Generator[DirCreatedEvent | FileCreatedEvent])*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   ro   r   r   r   r   r#   r$   r%   <module>r      si  Ob #   	 (   3)      .   t. . .*"? "$ $% %$ $K) K#o #,_ ,#o #o  o ( T TnI$"8 I$XP$ 6 P$f,<0 ,<^MMM /M6Ar$   