K iR~dZddlmZddlZddlmZmZddlmZddl m Z eje Z GddeZy) u:module: watchdog.observers.inotify_buffer :synopsis: A wrapper for ``Inotify``. :author: thomas.amland@gmail.com (Thomas Amland) :author: contact@tiger-222.fr (Mickaël Schoentgen) :platforms: linux ) annotationsN)Inotify InotifyEvent) BaseThread) DelayedQueuecXeZdZdZdZdddd fdZd dZddZdd Zdd Z dd Z xZ S) InotifyBufferzA wrapper for `Inotify` that holds events for `delay` seconds. During this time, IN_MOVED_FROM and IN_MOVED_TO events are paired. g?FN recursive event_maskct|td|j|_t ||||_|jy)N0InotifyEvent | tuple[InotifyEvent, InotifyEvent]r )super__init__rdelay_queuer_inotifystart)selfpathr r __class__s g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/watchdog/observers/inotify_buffer.pyrzInotifyBuffer.__init__s@ "#UVW[WaWab  jQ  c6|jjS)zReturns a single event or a tuple of from/to events in case of a paired move event. If this buffer has been closed, immediately return None. )rgetrs r read_eventzInotifyBuffer.read_event!s {{  rcl|jj|jjyN)rcloserrs ron_thread_stopzInotifyBuffer.on_thread_stop(s"  rcD|j|jyr)stopjoinrs rr zInotifyBuffer.close,s  rcg}|D]tjddfd }jr|t|D]\}}||s|f||<N|jj |}||j |ftjd|j |j |S)zGroup any matching move eventsz in-event %scxt|t xr'|jxr|jjk(Sr) isinstancetuple is_moved_fromcookie)event inotify_events rmatching_from_eventz8InotifyBuffer._group_events..matching_from_event6s6%eU33t8K8KtPUP\P\`m`t`tPttrz'could not find matching move_from event)r+rreturnbool)loggerdebug is_moved_to enumeraterremoveappend)r event_listgroupedr-indexr+ from_eventr,s @r _group_eventszInotifyBuffer._group_events0sJL' .M LL 6 u(($-g$6 6LE5*51*/)? 6 "&!3!34G!HJ!- M'BC %NO}5}-+ .,rcFd}|jr|s |jj}|j|}|D]}t |t s2|j r&|j|jjk(rd}Et |t  xr |j}|jj||t |t r|js|j|jjk(sd}|jr|syyyy)zRead event from `inotify` and add them to `queue`. When reading a IN_MOVE_TO event, remove the previous added matching IN_MOVE_FROM event and add them back to the queue as a tuple. FT)rN) should_keep_runningr read_eventsr:r'r( is_ignoredsrc_pathrr)rputis_delete_self)r deleted_selfinotify_eventsgrouped_eventsr,rs rrunzInotifyBuffer.runKs  &&(!]]668N!//?N!/ ( !-7MY]!6(rr )rK __future__rloggingwatchdog.observers.inotify_crrwatchdog.utilsrwatchdog.utils.delayed_queuer getLoggerrHr0r rrrTs;#>%5   8 $S(JS(r