
    g                        U d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ  e
e      Zd	ed
<   dZd	ed<   dZd	ed<    G d d      Zy)z.A class that watches a given path via polling.    )annotationsN)ThreadPoolExecutor)CallableFinal)
get_loggerrepr_)utilr   _LOGGER   _MAX_WORKERSg?_POLLING_PERIOD_SECSc                  v    e Zd ZdZ ee      Zedd       Zddd	 	 	 	 	 	 	 	 	 ddZ	ddZ
dd	Zdd
ZddZy)PollingPathWatcherz*Watches a path on disk via a polling loop.)max_workersc                 .    t         j                  d       y)zClose top-level watcher object.

        This is a no-op, and exists for interface parity with
        EventBasedPathWatcher.
        zWatcher closedN)r   debug     [/var/www/openai/venv/lib/python3.12/site-packages/streamlit/watcher/polling_path_watcher.py	close_allzPollingPathWatcher.close_all&   s     	&'r   NFglob_patternallow_nonexistentc               >   || _         || _        || _        || _        d| _        t        j                  | j                   | j                        | _        t        j                  | j                   | j                  | j                        | _	        | j                          y)zConstructor.

        You do not need to retain a reference to a PollingPathWatcher to
        prevent it from being garbage collected. (The global _executor object
        retains references to all active instances.)
        Tr   N)_path_on_changed_glob_pattern_allow_nonexistent_activer
   path_modification_time_modification_timecalc_md5_with_blocking_retries_md5	_schedule)selfpath
on_changedr   r   s        r   __init__zPollingPathWatcher.__init__/   s     
%)"3"&"="=JJ//#
 77JJ++"55
	
 	r   c                    t        |       S Nr   r&   s    r   __repr__zPollingPathWatcher.__repr__P   s    T{r   c                N      fd}t         j                  j                  |       y )Nc                 X    t        j                  t                j                          y r+   )timesleepr   _check_if_path_changedr,   s   r   taskz*PollingPathWatcher._schedule.<locals>.taskT   s    JJ+,'')r   )r   	_executorsubmit)r&   r3   s   ` r   r%   zPollingPathWatcher._scheduleS   s    	* 	$$++D1r   c                   | j                   sy t        j                  | j                  | j                        }|dk7  r || j
                  k  r| j                          y || _        t        j                  | j                  | j                  | j                        }|| j                  k(  r| j                          y || _	        t        j                  d| j                         | j                  | j                         | j                          y )Ng        r   zChange detected: %s)r    r
   r!   r   r   r"   r%   r#   r   r$   r   r   r   )r&   modification_timemd5s      r   r2   z)PollingPathWatcher._check_if_path_changedZ   s    || 77JJ//

 #(9T=T=T(TNN"311JJ++"55

 $))NN	+TZZ8$r   c                    d| _         y)zStop watching the file system.FN)r    r,   s    r   closezPollingPathWatcher.closez   s	    r   )returnNone)
r'   strr(   zCallable[[str], None]r   z
str | Noner   boolr;   r<   )r;   r=   )__name__
__module____qualname____doc__r   r   r4   staticmethodr   r)   r-   r%   r2   r:   r   r   r   r   r   !   st    4"|<I( ( $("' *
 !   
B2@r   r   )rB   
__future__r   r0   concurrent.futuresr   typingr   r   streamlit.loggerr   streamlit.utilr	   streamlit.watcherr
   r?   r   __annotations__r   r   r   r   r   r   <module>rK      sO    5 "  1 " '   "H% %e ! e ![ [r   