K i?&dZddlmZddlZddlZddlZddlmZm Z ddl m Z ddl m Z e rddlmZdZd Zd Zd Zd Zd ZdZedGddZGddeZGddeZGddeZGddeZGddeZGddeZGdd eZGd!d"eZGd#d$eZ Gd%d&eZ!Gd'd(eZ"Gd)d*eZ#Gd+d,Z$Gd-d.e$Z%Gd/d0e$Z&Gd1d2e$Z' d5d3Z(d6d4Z)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) dataclassfield) TYPE_CHECKING)match_any_paths) Generatormoveddeletedcreatedmodifiedclosedclosed_no_writeopenedT) unsafe_hashceZdZUdZded<dZded<eddZded <eddZd ed < ed Z d ed <y)FileSystemEventaImmutable 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 | strsrc_path dest_pathF)defaultinitstr event_typebool is_directory)r is_syntheticN) __name__ __module__ __qualname____doc____annotations__rrrrrU/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/watchdog/events.pyrrhsQI{BU3J3u59L$9 u-L$-r$rceZdZdZeZy)FileSystemMovedEventz@File system event representing any kind of file system movement.N)rrr r!EVENT_TYPE_MOVEDrr#r$r%r'r'~s J!Jr$r'ceZdZdZeZy)FileDeletedEventz@File system event representing file deletion on the file system.N)rrr r!EVENT_TYPE_DELETEDrr#r$r%r*r* J#Jr$r*ceZdZdZeZy)FileModifiedEventzDFile system event representing file modification on the file system.N)rrr r!EVENT_TYPE_MODIFIEDrr#r$r%r.r.s N$Jr$r.ceZdZdZeZy)FileCreatedEventz@File system event representing file creation on the file system.N)rrr r!EVENT_TYPE_CREATEDrr#r$r%r1r1r,r$r1ceZdZdZy)FileMovedEventz@File system event representing file movement on the file system.N)rrr r!r#r$r%r4r4sJr$r4ceZdZdZeZy)FileClosedEvent=File system event representing file close on the file system.N)rrr r!EVENT_TYPE_CLOSEDrr#r$r%r6r6 G"Jr$r6ceZdZdZeZy)FileClosedNoWriteEventzKFile system event representing an unmodified file close on the file system.N)rrr r!EVENT_TYPE_CLOSED_NO_WRITErr#r$r%r;r;s U+Jr$r;ceZdZdZeZy)FileOpenedEventr7N)rrr r!EVENT_TYPE_OPENEDrr#r$r%r>r>r9r$r>ceZdZdZeZdZy)DirDeletedEventzEFile system event representing directory deletion on the file system.TN)rrr r!r+rrr#r$r%rArAO#JLr$rAceZdZdZeZdZy)DirModifiedEventzIFile system event representing directory modification on the file system.TN)rrr r!r/rrr#r$r%rDrDsS$JLr$rDceZdZdZeZdZy)DirCreatedEventzEFile system event representing directory creation on the file system.TN)rrr r!r2rrr#r$r%rFrFrBr$rFceZdZdZdZy) DirMovedEventzEFile system event representing directory movement on the file system.TN)rrr r!rr#r$r%rHrHs OLr$rHcXeZdZdZd dZd dZd dZddZddZddZ ddZ dd Z dd Z y )FileSystemEventHandlerzBBase file system event handler that you can override methods from.cd|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_eventgetattrrselfevents r%dispatchzFileSystemEventHandler.dispatchs1 % /E,,-./6r$cy)zCatch-all event handler. :param event: The event object representing the file system event. :type event: :class:`FileSystemEvent` Nr#rPs r%rNz#FileSystemEventHandler.on_any_eventr$cy)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#rPs r%on_movedzFileSystemEventHandler.on_movedrUr$cy)zCalled when a file or directory is created. :param event: Event representing file/directory creation. :type event: :class:`DirCreatedEvent` or :class:`FileCreatedEvent` Nr#rPs r% on_createdz!FileSystemEventHandler.on_createdrUr$cy)zCalled when a file or directory is deleted. :param event: Event representing file/directory deletion. :type event: :class:`DirDeletedEvent` or :class:`FileDeletedEvent` Nr#rPs r% on_deletedz!FileSystemEventHandler.on_deletedrUr$cy)zCalled when a file or directory is modified. :param event: Event representing file/directory modification. :type event: :class:`DirModifiedEvent` or :class:`FileModifiedEvent` Nr#rPs r% on_modifiedz"FileSystemEventHandler.on_modifiedrUr$cy)zCalled when a file opened for writing is closed. :param event: Event representing file closing. :type event: :class:`FileClosedEvent` Nr#rPs r% on_closedz FileSystemEventHandler.on_closedrUr$cy)zCalled when a file opened for reading is closed. :param event: Event representing file closing. :type event: :class:`FileClosedNoWriteEvent` Nr#rPs r%on_closed_no_writez)FileSystemEventHandler.on_closed_no_writerUr$cy)zCalled when a file is opened. :param event: Event representing file opening. :type event: :class:`FileOpenedEvent` Nr#rPs r% on_openedz FileSystemEventHandler.on_openedrUr$NrRrreturnNonerRzDirMovedEvent | FileMovedEventrerfrRz"DirCreatedEvent | FileCreatedEventrerfrRz"DirDeletedEvent | FileDeletedEventrerfrRz$DirModifiedEvent | FileModifiedEventrerfrRr6rerfrRr;rerfrRr>rerf) rrr r!rSrNrWrYr[r]r_rarcr#r$r%rJrJs2L 7        r$rJceZdZdZddddd d fdZed dZed dZed dZed d Z dfd Z xZ 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)patternsignore_patternsignore_directoriescase_sensitivecZt|||_||_||_||_yN)super__init__ _patterns_ignore_patterns_ignore_directories_case_sensitive)rQrprqrrrs __class__s r%rwz$PatternMatchingEventHandler.__init__*s/ ! /#5 -r$c|jS)zD(Read-only) Patterns to allow matching event paths. )rxrQs r%rpz$PatternMatchingEventHandler.patterns9s ~~r$c|jS)zE(Read-only) Patterns to ignore matching event paths. )ryr~s r%rqz+PatternMatchingEventHandler.ignore_patterns@s $$$r$c|jSz\(Read-only) ``True`` if directories should be ignored; ``False`` otherwise. rzr~s r%rrz.PatternMatchingEventHandler.ignore_directoriesG '''r$c|jSzu(Read-only) ``True`` if path names should be matched sensitive to case; ``False`` otherwise. r{r~s r%rsz*PatternMatchingEventHandler.case_sensitiveN ###r$c|jr |jryg}t|dr.|jt j |j |jr.|jt j |jt||j|j|jrt|5|yy)rLNr)included_patternsexcluded_patternsrs)rrrhasattrappendosfsdecoderrrrprqrsrvrSrQrRpathsr|s r%rSz$PatternMatchingEventHandler.dispatchVs  " "u'9'9  5+ & LLU__5 6 >> LLU^^4 5  "mm"22..  G U #  r$)rplist[str] | Nonerqrrrrrsr)rerrerrd) rrr r!rwpropertyrprqrrrsrS __classcell__r|s@r%roro$s&*,0#($ .# .* . ! .  . %% (( $$$$r$roceZdZdZddddd d fdZed dZed dZed dZed d Z dfd Z xZ S)RegexMatchingEventHandlerzfMatches given regexes with file paths associated with occurring events. Uses the `re` module. NF)regexesignore_regexesrrrsc"t||dg}nt|tr|g}|g}|rQ|Dcgc]}t j |c}|_|Dcgc]}t j |c}|_nn|Dcgc]&}t j |tj(c}|_|Dcgc]&}t j |tj(c}|_||_ ||_ ycc}wcc}wcc}wcc}w)Nz.*) rvrw isinstancerrecompile_regexes_ignore_regexes IGNORECASErzr{)rQrrrrrsrr|s r%rwz"RegexMatchingEventHandler.__init__us  ?gG  %iG  !N 4;z5RegexMatchingEventHandler.dispatch..s%FaF1qwwqzFzF"%c3NK|]}D]}|j|ywrurrs r%rz5RegexMatchingEventHandler.dispatch..s%?a?Aqwwqz?z?r) rrrrrrrrranyrrrvrSrs @r%rSz"RegexMatchingEventHandler.dispatchs  " "u'9'9  5+ & LLU__5 6 >> LLU^^4 5 F4#6#6F F  ?4<<? ? G U # @r$)rrrrrrrrsr)rezlist[re.Pattern[str]]rrd) rrr r!rwrrrrrrsrSrrs@r%rrps%)+/#($ .".) . ! .  .2 $$ (( $$$$r$rc~eZdZdZddd fdZd fd Zdfd Zdfd Zdfd Zdfd Z dfd Z dfd Z xZ S)LoggingEventHandlerzLogs all the events captured.N)loggercTt||xstj|_yru)rvrwloggingrootr)rQrr|s r%rwzLoggingEventHandler.__init__s ,  r$ct|||jrdnd}|jj d||j |j y)N directoryfilezMoved %s: from %s to %s)rvrWrrinforrrQrRwhatr|s r%rWzLoggingEventHandler.on_moveds@ #00{f 2D%..%//Zr$ct|||jrdnd}|jj d||j y)NrrzCreated %s: %s)rvrYrrrrrs r%rYzLoggingEventHandler.on_created: 5!#00{f )4@r$ct|||jrdnd}|jj d||j y)NrrzDeleted %s: %s)rvr[rrrrrs r%r[zLoggingEventHandler.on_deletedrr$ct|||jrdnd}|jj d||j y)NrrzModified %s: %s)rvr]rrrrrs r%r]zLoggingEventHandler.on_modifieds: E"#00{f *D%..Ar$cpt|||jjd|jy)NzClosed modified file: %s)rvr_rrrrQrRr|s r%r_zLoggingEventHandler.on_closeds) %  3U^^Dr$cpt|||jjd|jy)NzClosed read file: %s)rvrarrrrs r%raz&LoggingEventHandler.on_closed_no_writes) "5) /@r$cpt|||jjd|jy)NzOpened file: %s)rvrcrrrrs r%rczLoggingEventHandler.on_openeds) %  *ENN;r$)rzlogging.Logger | Nonererfrgrhrirjrkrlrm) rrr r!rwrWrYr[r]r_rarcrrs@r%rrs<':>-[ A A B E A <M$k9$ LI T95IMY9,,]LI_aL idK K L" MH T84IMY9,,]LI_aL ytL L M MsB:B<c# Ktj|D]r\}}}|D]1}tjj||}t |d3|D]1}tjj||}t |d3tyw)aGenerates 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`. TrN)rrrrrFr1)rrrrrrrs r%generate_sub_created_eventsr s)+ (=A$k9$ @I T95I!)$? ? @" AH T84I"94@ @ A AsB B)rrrrrez)Generator[DirMovedEvent | FileMovedEvent])rrrez-Generator[DirCreatedEvent | FileCreatedEvent])*r! __future__rros.pathrr dataclassesrrtypingrwatchdog.utils.patternsrcollections.abcrr(r+r2r/r8r<r?rr'r*r.r1r4r6r;r>rArDrFrHrJrorrrrr#r$r%rsiOb# ( 3) . t...*"?"$$ %% $$ K)K#o# ,_, #o#oo( T T nI$"8I$XP$ 6P$f,<0,<^MMM/M6Ar$