U ö üe…3ã@súddlZddlZddlZddlZddlZddlZddlmZddlZ ddl Z dZ dZ dZ e e¡Ze dddd d g¡Ze e ¡Zeeej d d ¡ƒƒZGd d„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZ Gdd„deƒZ!dS)éN)ÚEINTRéZiIII)Z IN_Q_OVERFLOWZ IN_UNMOUNTÚ_INOTIFY_EVENTÚwdÚmaskÚcookieÚlenÚDEBUGÚ0c@s eZdZdS)ÚEventTimeoutExceptionN)Ú__name__Ú __module__Ú __qualname__©rrú>/opt/hc_python/lib/python3.8/site-packages/inotify/adapters.pyr (sr cseZdZ‡fdd„Z‡ZS)ÚTerminalEventExceptioncstt|ƒ |¡||_dS©N)ÚsuperrÚ__init__Úevent)ÚselfÚ type_namer©Ú __class__rrr-szTerminalEventException.__init__)r r rrÚ __classcell__rrrrr,src@s|eZdZgefdd„Zdd„Zdd„Zejj fdd„Z dd d „Z dd d „Z dd„Z dd„Zdddefdd„Zedd„ƒZdS)ÚInotifycCsl||_i|_i|_d|_tj ¡|_t  d|j¡t   ¡|_ |j   |jt j¡d|_|D]}| |¡qXdS)NózInotify handle is (%d).)Ú_Inotify__block_durationÚ_Inotify__watchesÚ_Inotify__watches_rÚ_Inotify__bufferÚinotifyÚcallsZ inotify_initÚ_Inotify__inotify_fdÚ_LOGGERÚdebugÚselectÚepollÚ_Inotify__epollÚregisterÚPOLLINÚ_Inotify__last_success_returnÚ add_watch)rÚpathsÚblock_duration_sÚpathrrrr3s  zInotify.__init__cCs*z | ¡WStk r$|jYSXdS)z=Allow the block-duration to be an integer or a function-call.N)rÚ TypeError©rrrrZ__get_block_durationDs zInotify.__get_block_durationcCst d¡t |j¡dS)NzCleaning-up inotify.)r$r%ÚosÚcloser#r1rrrÚ__del__Ms zInotify.__del__cCsht d|¡||jkr&t d|¡dS| d¡}tj |j||¡}t d||¡||j|<||j |<|S)NzAdding watch: [%s]z Path already being watched: [%s]Úutf8zAdded watch (%d): [%s]) r$r%rÚwarningÚencoder!r"Zinotify_add_watchr#r)rZ path_unicoderZ path_bytesrrrrr,Qs      zInotify.add_watchFcCs<|j |¡}|dkrdSt d||¡|j|=| |¡dS)zÙRemove our tracking information and call inotify to stop watching the given path. When a directory is removed, we'll just have to remove our tracking since inotify already cleans-up the watch. Nz*Removing watch for watch-handle (%d): [%s])rÚgetr$r%Úremove_watch_with_id)rr/Ú superficialrrrrÚ remove_watchgs ÿzInotify.remove_watchcCs0|j|=|dkr,t d|¡tj |j|¡dS)NFz%Removing watch for watch-handle (%d).)rr$r%r!r"Zinotify_rm_watchr#)rrr:rrrr9xs zInotify.remove_watch_with_idcCsZg}tjj ¡D].\}}||@r| |¡||8}|dkrq@q|dksVtd|fƒ‚|S)Nrz*We could not resolve all event-types: (%d))r!Ú constantsZ MASK_LOOKUPÚitemsÚappendÚAssertionError)rÚ event_typeÚnamesÚbitÚnamerrrÚ_get_event_names€s  ÿzInotify._get_event_namesccst |d¡}|sdS|j|7_t|jƒ}|tkrBt d¡dS|jdt…}t t |¡}t |Ž}|  |j ¡}t d  |¡¡t|j}||kr–dS|jt|…} |  d¡} |j|d…|_|j |j¡} | dk rì|  d¡} ||| | fVt|jƒ} | tkr"qq"dS)z1Handle a series of events coming-in from inotify.iNzNot enough bytes for a header.zEvents received in stream: {}ór5)r2Úreadr rÚ_STRUCT_HEADER_LENGTHr$r%ÚstructÚunpackÚ_HEADER_STRUCT_FORMATrrDrÚformatÚrstriprr8rÚdecode)rrÚbÚlengthZ peek_sliceZ header_rawÚheaderÚ type_namesZ event_lengthÚfilenameZfilename_bytesr/Zfilename_unicodeZ buffer_lengthrrrÚ_handle_inotify_events:   þ     zInotify._handle_inotify_eventNTc cs`d|_t ¡}| ¡}z|j |¡}Wn\tk r‚}z>|jtkrD‚|dk rjt ¡|} | |krjWY¢q\WY¢qW5d}~XYnX|D]ž\} } | | ¡} t   d  | ¡¡|  | ¡D]p\} }}}t ¡}| |||f}|D]D}|dk r |||ƒdkr ||f|_dS||krØt ||ƒ‚qØ|Vq´qˆ|dk rLt ¡|} | |krLq\|dkrdVqdS)zˆYield one event after another. If `timeout_s` is provided, we'll break when no event is received for that many seconds. NzEvents received from epoll: {}FT)r+ÚtimeÚ_Inotify__get_block_durationr(ÚpollÚIOErrorÚerrnorrDr$r%rKrSr)rZ timeout_sZ yield_nonesZfilter_predicateZterminal_eventsZ last_hit_sr.ÚeventsÚeZtime_since_event_sÚfdr@rArPrQr/rRrrrrÚ event_gen¿sF      ÿ   ÿ       zInotify.event_gencCs|jSr)r+r1rrrÚlast_success_returnýszInotify.last_success_return)F)F)r r rÚ_DEFAULT_EPOLL_BLOCK_DURATION_SrrUr4r!r<Ú IN_ALL_EVENTSr,r;r9rDrSÚ_DEFAULT_TERMINAL_EVENTSr\Úpropertyr]rrrrr2s   1þ >rc@s4eZdZejjefdd„Zd dd„Ze dd„ƒZdS) Ú _BaseTreecCs.|tjjBtjjBtjjB|_t|d|_dS)N)r.)r!r<ÚIN_ISDIRÚ IN_CREATEZ IN_DELETEÚ_maskrÚ_i)rrr.rrrrsÿþýz_BaseTree.__init__Fc ks(|jjf|ŽD]}|dk r|\}}}}|jtjj@rtj ||¡}|jtjj @sd|jtjj @r˜tj  |¡dks||dkr˜t   d|¡|j ||j¡|jtjj@rÄt   d|¡|jj|ddnX|jtjj@rðt   d|¡|jj|ddn,|jtjj @rt   d|¡|j ||j¡|VqdS) aJThis is a secondary generator that wraps the principal one, and adds/removes watches as directories are added/removed. If we're doing anything funky and allowing the events to queue while a rename occurs then the folder may no longer exist. In this case, set `ignore_missing_new_folders`. NTFz^A directory has been created. We're adding a watch on it (because we're being recursive): [%s]zlA directory has been removed. We're being recursive, but it would have automatically been deregistered: [%s])r:zlA directory has been renamed. We're being recursive, but it would have automatically been deregistered: [%s]z^A directory has been renamed. We're adding a watch on it (because we're being recursive): [%s])rfr\rr!r<rcr2r/ÚjoinZ IN_MOVED_TOrdÚexistsr$r%r,reZ IN_MOVED_FROMr;) rZignore_missing_new_foldersÚkwargsrrPrQr/rRÚ full_pathrrrr\sB    ÿ þûúþýýþz_BaseTree.event_gencCs|jSr)rfr1rrrr!Fsz_BaseTree.inotifyN)F) r r rr!r<r_r^rr\rarrrrrbs ÿ 7rbcs2eZdZdZejjef‡fdd„ Zdd„Z ‡Z S)Ú InotifyTreezRecursively watch a path.cs(tt|ƒj||d||_| |¡dS©N)rr.)rrkrZ_InotifyTree__root_pathÚ_InotifyTree__load_tree)rr/rr.rrrrNszInotifyTree.__init__cCsŒt d|¡g}|g}|rn|d}|d=| |¡t |¡D].}tj ||¡}tj |¡dkr`q<| |¡qr2Úlistdirr/rgÚisdirrfr,re)rr/r-ÚqÚ current_pathrRÚentry_filepathrrrZ __load_treeVs  zInotifyTree.__load_tree) r r rÚ__doc__r!r<r_r^rrmrrrrrrkKs ÿrkcs2eZdZdZejjef‡fdd„ Zdd„Z ‡Z S)Ú InotifyTreesz'Recursively watch over a list of trees.cs"tt|ƒj||d| |¡dSrl)rrtrÚ_InotifyTrees__load_trees)rr-rr.rrrrpszInotifyTrees.__init__cCs–t dd tt|ƒ¡¡g}|}|rx|d}|d=| |¡t |¡D].}tj ||¡}tj  |¡dkrjqF| |¡qFq |D]}|j   ||j ¡q|dS)Nz%Adding initial watches on trees: [%s]ú,rF) r$r%rgÚmapÚstrr>r2rnr/rorfr,re)rr-ÚfoundrprqrRrrr/rrrZ __load_treesvs zInotifyTrees.__load_trees) r r rrsr!r<r_r^rrurrrrrrtms ÿrt)"Úloggingr&r2rHÚ collectionsrTrXrZinotify.constantsr!Z inotify.callsr^rJr`Ú getLoggerr r$Ú namedtuplerÚcalcsizerGÚboolÚintÚenvironr8Z _IS_DEBUGÚ Exceptionr rÚobjectrrbrkrtrrrrÚs:  üþ QI"