K i5ddlmZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZe rddlmZmZd Zd ZGd d eZGd d ZGdde ZGdde ZGddeZy)) annotationsN) defaultdict)Path) TYPE_CHECKING) BaseThread)SkipRepeatsQueue)FileSystemEventFileSystemEventHandlerg?ceZdZdZy) EventQueuea.Thread-safe event queue based on a special queue that skips adding the same event (:class:`FileSystemEvent`) multiple times consecutively. Thus avoiding dispatching multiple event handling calls when multiple identical events are produced quicker than an observer can consume them. N)__name__ __module__ __qualname____doc__\/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/watchdog/observers/api.pyr r srr ceZdZdZddd dZeddZeddZeddZeddZ dd Z dd Z dd Z dd Z y) ObservedWatchzAn scheduled watch. :param path: Path string. :param recursive: ``True`` if watch is recursive; ``False`` otherwise. :param event_filter: Optional collection of :class:`watchdog.events.FileSystemEvent` to watch N) event_filterct|tr t|n||_||_|t ||_yd|_yN) isinstancerstr_path _is_recursive frozenset _event_filter)selfpath recursivers r__init__zObservedWatch.__init__(s:",T4"8SYd &8D8PY|4VZrc|jS)z"The path that this watch monitors.)rrs rr zObservedWatch.path-szzrc|jS)z;Determines whether subdirectories are watched for the path.)rr$s r is_recursivezObservedWatch.is_recursive2!!!rc|jS)z.Collection of event types watched for the path)rr$s rrzObservedWatch.event_filter7r'rcH|j|j|jfSr)r r&rr$s rkeyzObservedWatch.key<syy$++T->->>>rc`t|tstS|j|jk(SrrrNotImplementedr*rwatchs r__eq__zObservedWatch.__eq__@%%/! !xx599$$rc`t|tstS|j|jk7Srr,r.s r__ne__zObservedWatch.__ne__Er1rc,t|jSr)hashr*r$s r__hash__zObservedWatch.__hash__JsDHH~rc|j1djtd|jD}d|}nd}dt|jd|j d|j |dS) N|c34K|]}|jywr)r ).0_clss r z)ObservedWatch.__repr__..Os.[t}}.[sz, event_filter=)rjoinsortedtyper r r&)revent_filter_strs r__repr__zObservedWatch.__repr__Ms{    ("xx.[IZIZ.[([\ !01A0BC ! 4:&&'wtyym?4K\K\J]^n]oopqqr)r z str | Pathr!boolr"list[type[FileSystemEvent]] | None)returnr)rGrE)rGz'frozenset[type[FileSystemEvent]] | None)rGz9tuple[str, bool, frozenset[type[FileSystemEvent]] | None])r/objectrGrE)rGint)r rrrr"propertyr r&rr*r0r3r6rDrrrrrsyqu[ """"??% % rrrczeZdZdZedd d fdZed dZed dZd dZ ddZ dd Z xZ S) EventEmitteraProducer thread base class subclassed by event emitters that generate events and populate a queue with them. :param event_queue: The event queue to populate with generated events. :type event_queue: :class:`watchdog.events.EventQueue` :param watch: The watch to observe and produce events for. :type watch: :class:`ObservedWatch` :param timeout: Timeout (in seconds) between successive attempts at reading events. :type timeout: ``float`` :param event_filter: Collection of event types to emit, or None for no filtering (default). :type event_filter: Iterable[:class:`watchdog.events.FileSystemEvent`] | None Ntimeoutrct|||_||_||_|t ||_yd|_yr)superr" _event_queue_watch_timeoutrr)r event_queuer/rNr __class__s rr"zEventEmitter.__init__ms@ '  8D8PY|4VZrc|jS)z$Blocking timeout for reading events.rSr$s rrNzEventEmitter.timeout{}}rc|jS)z'The watch associated with this emitter.)rRr$s rr/zEventEmitter.watchs{{rc|jtfd|jDr(|jj|jfyy)zQueues a single event. :param event: Event to be queued. :type event: An instance of :class:`watchdog.events.FileSystemEvent` or a subclass. Nc36K|]}t|ywr)r)r:clsevents rr<z+EventEmitter.queue_event..s,bZs-C,bs)ranyrQputr/)rr]s `r queue_eventzEventEmitter.queue_eventsG    %,btOaOa,b)b    ! !5$**"5 6*crcy)aOverride this method to populate the event queue with events per interval period. :param timeout: Timeout (in seconds) between successive attempts at reading events. :type timeout: ``float`` Nr)rrNs r queue_eventszEventEmitter.queue_eventsrc~|jr-|j|j|jr,yyr)should_keep_runningrbrNr$s rrunzEventEmitter.runs.&&(   dll +&&(r) rTr r/rrNfloatrrFrGNonerGrg)rGr)r]r rGrhrNrgrGrhrGrh) r rrrDEFAULT_EMITTER_TIMEOUTr"rJrNr/r`rbrf __classcell__rUs@rrLrLWs41;? [ [ [  [ 9 [  [ 7  ,rrLcveZdZdZeZ edd fdZed dZ d dZ ed dZ d dZ d dZ xZS)EventDispatchera7Consumer thread base class subclassed by event observer threads that dispatch events from an event queue to appropriate event handlers. :param timeout: Timeout value (in seconds) passed to emitters constructions in the child class BaseObserver. :type timeout: ``float`` rNcNt|t|_||_yr)rPr"r rQrS)rrNrUs rr"zEventDispatcher.__init__s &L rc|jS)z)Timeout value to construct emitters with.rWr$s rrNzEventDispatcher.timeoutrXrctj|tjtj 5|j jtjdddy#1swYyxYwr) rstop contextlibsuppressqueueFullrT put_nowaitrp stop_eventr$s rruzEventDispatcher.stopsS   , D    ' '(B(B C D D Ds *A,,A5c|jS)zThe event queue which is populated with file system events by emitters and from which events are dispatched by a dispatcher thread. )rQr$s rrTzEventDispatcher.event_queues    rcy)agOverride this method to consume events from an event queue, blocking on the queue for the specified timeout before raising :class:`queue.Empty`. :param event_queue: Event queue to populate with one set of events. :type event_queue: :class:`EventQueue` :raises: :class:`queue.Empty` Nr)rrTs rdispatch_eventszEventDispatcher.dispatch_eventsrcrc|jr. |j|j|jr-yy#tj$rYTwxYwr)rer~rTrxEmptyr$s rrfzEventDispatcher.runsM&&( $$T%5%56&&(;;  sAAArjrirk)rGr rTr rGrh)r rrrrHr{DEFAULT_OBSERVER_TIMEOUTr"rJrNrurTr~rfrmrns@rrprpsTJC+C D !!  rrpceZdZdZeddfdZddZddZddZddZ ddZ e dd Z dfd Z d d d  ddZddZddZddZddZddZddZxZS) BaseObserverzBase observer.rqct||||_tj|_t |_tt |_ t |_ i|_ y)Nrq) rPr"_emitter_class threadingRLock_lockset_watchesr _handlers _emitters_emitter_for_watch)r emitter_classrNrUs rr"zBaseObserver.__init__sP )+__& ,/E R]^aRb,/EEGrcl||j|j<|jj|yr)rr/raddremitters r _add_emitterzBaseObserver._add_emitters(18 . 7#rc|j|j=|jj||j t j t5|jdddy#1swYyxYwr) rr/rremoverurvrw RuntimeErrorr@rs r_remove_emitterzBaseObserver._remove_emitters[  # #GMM 2 g&    .  LLN   s A66A?cL|jD]}|j|jD]4}tjt5|j ddd6|jj |jj y#1swYuxYwr)rrurvrwrr@clearrrs r_clear_emitterszBaseObserver._clear_emitterss~~ G LLN ~~ G$$\2       %%'  s BB# c@|j|j|yr)rrr event_handlerr/s r_add_handler_for_watchz#BaseObserver._add_handler_for_watchs u!!-0rc|j|=yr)rr.s r_remove_handlers_for_watchz'BaseObserver._remove_handlers_for_watchs NN5 !rc|jS)z/Returns event emitter created by this observer.)rr$s remitterszBaseObserver.emitterss~~rc|jjD]} |jt | y#t$r|j |wxYwr)rcopystart ExceptionrrP)rrrUs rrzBaseObserver.startsZ~~**, G      $$W- s AAFNr!rc|j5t|||}|j||||jvrZ|j |j ||j |}|jr|j|j||jj|ddd|S#1swYSxYw)a6Schedules watching a path and calls appropriate methods specified in the given event handler in response to file system events. :param event_handler: An event handler instance that has appropriate event handling methods which will be called by the observer in response to file system events. :type event_handler: :class:`watchdog.events.FileSystemEventHandler` or a subclass :param path: Directory path that will be monitored. :type path: ``str`` :param recursive: ``True`` if events will be emitted for sub-directories traversed recursively; ``False`` otherwise. :type recursive: ``bool`` :param event_filter: Collection of event types to emit, or None for no filtering (default). :type event_filter: Iterable[:class:`watchdog.events.FileSystemEvent`] | None :return: An :class:`ObservedWatch` object instance representing a watch. rrMN) rrrrrrTrNis_aliverrrr)rrr r!rr/rs rschedulezBaseObserver.schedulesDZZ %!$),WE  ' ' u =D333--d.>.>t||jv-w==?MMO!!'* MM  e $ %  % s B$B;;Ccj|j5|j||dddy#1swYyxYw)a!Adds a handler for the given watch. :param event_handler: An event handler instance that has appropriate event handling methods which will be called by the observer in response to file system events. :type event_handler: :class:`watchdog.events.FileSystemEventHandler` or a subclass :param watch: The watch to add a handler for. :type watch: An instance of :class:`ObservedWatch` or a subclass of :class:`ObservedWatch` N)rrrs radd_handler_for_watchz"BaseObserver.add_handler_for_watch=s0ZZ >  ' ' u = > > >s)2c|j5|j|j|dddy#1swYyxYw)a'Removes a handler for the given watch. :param event_handler: An event handler instance that has appropriate event handling methods which will be called by the observer in response to file system events. :type event_handler: :class:`watchdog.events.FileSystemEventHandler` or a subclass :param watch: The watch to remove a handler for. :type watch: An instance of :class:`ObservedWatch` or a subclass of :class:`ObservedWatch` N)rrrrs rremove_handler_for_watchz%BaseObserver.remove_handler_for_watchOs7ZZ 8 NN5 ! ( ( 7 8 8 8s5>c|j5|j|}|j|=|j||jj |dddy#1swYyxYw)zUnschedules a watch. :param watch: The watch to unschedule. :type watch: An instance of :class:`ObservedWatch` or a subclass of :class:`ObservedWatch` N)rrrrrr)rr/rs r unschedulezBaseObserver.unscheduleas\ZZ (--e4Gu%   ) MM  '  ( ( (s A AA(c|j5|jj|j|jjdddy#1swYyxYw)zCUnschedules all watches and detaches all associated event handlers.N)rrrrrr$s runschedule_allzBaseObserver.unschedule_allpsJ ZZ " NN "  " MM   ! " " "s AAA$c$|jyr)rr$s ron_thread_stopzBaseObserver.on_thread_stopws rcF|jd}|tjury|\}}|j5|j|j D]%}||j|vs|j |' ddd|jy#1swYxYw)NT)block)getrpr{rrrdispatch task_done)rrTentryr]r/handlers rr~zBaseObserver.dispatch_eventszsd+ O.. .  u ZZ , >>%0557 ,dnnU33$$U+ ,  ,  , ,s2B*BB )rztype[EventEmitter]rNrgrGrh)rrLrGrhrk)rr r/rrGrh)r/rrGrh)rGzset[EventEmitter]) rr r rr!rErrFrGrr)r rrrrr"rrrrrrJrrrrrrrrr~rmrns@rrrsNfH$(1" ;? ----  - 9 - -^>$8$ (" rr) __future__rrvrxr collectionsrpathlibrtypingrwatchdog.utilsrwatchdog.utils.bricksrwatchdog.eventsr r rlrr rrLrprrrrrsv" # %2G!6r6rtG,:G,T6j6rn ?n r