
    &e                         d 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Zd	Z G d
 d          ZdS )z.A class that watches a given path via polling.    N)ThreadPoolExecutor)CallableOptional)
get_loggerrepr_)util   g?c                       e Zd ZdZ ee          Zedd            Zdddde	d	e
e	gdf         d
ee	         deddf
dZde	fdZddZddZddZdS )PollingPathWatcherz*Watches a path on disk via a polling loop.)max_workersreturnNc                  :    t                               d           dS )zClose top-level watcher object.

        This is a no-op, and exists for interface parity with
        EventBasedPathWatcher.
        zWatcher closedN)LOGGERdebug     Flib/python3.11/site-packages/streamlit/watcher/polling_path_watcher.py	close_allzPollingPathWatcher.close_all%   s     	%&&&&&r   Fglob_patternallow_nonexistentpath
on_changedr   r   c                   || _         || _        || _        || _        d| _        t          j        | j         | j                  | _        t          j        | j         | j        | j                  | _	        | 
                                 dS )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)selfr   r   r   r   s        r   __init__zPollingPathWatcher.__init__.   s     
%)"3"&"=J/#
 #
 7J+"5
 
 
	
 	r   c                      t          |           S Nr   r&   s    r   __repr__zPollingPathWatcher.__repr__O   s    T{{r   c                 P      fd}t           j                            |           d S )Nc                  b    t          j        t                                                       d S r)   )timesleep_POLLING_PERIOD_SECS_check_if_path_changedr*   s   r   taskz*PollingPathWatcher._schedule.<locals>.taskS   s,    J+,,,'')))))r   )r   	_executorsubmit)r&   r2   s   ` r   r%   zPollingPathWatcher._scheduleR   s;    	* 	* 	* 	* 	* 	$++D11111r   c                    | j         sd S t          j        | j        | j                  }|dk    r!|| j        k    r|                                  d S || _        t          j        | j        | j        | j                  }|| j	        k    r|                                  d S || _	        t                              d| j                   |                     | j                   |                                  d S )Ng        r   zChange detected: %s)r    r	   r!   r   r   r"   r%   r#   r   r$   r   r   r   )r&   modification_timemd5s      r   r1   z)PollingPathWatcher._check_if_path_changedY   s    | 	F 7J/
 

 ##(9T=T(T(TNNF"31J+"5
 
 

 $)NNF	*DJ777$$$r   c                     d| _         dS )zStop watching the file system.FN)r    r*   s    r   closezPollingPathWatcher.closey   s    r   )r   N)__name__
__module____qualname____doc__r   _MAX_WORKERSr3   staticmethodr   strr   r   boolr'   r+   r%   r1   r9   r   r   r   r   r       s	       44""|<<<I' ' ' \' '+"'   cUD[)
 sm   
   B#    2 2 2 2   @     r   r   )r=   r.   concurrent.futuresr   typingr   r   streamlit.loggerr   streamlit.utilr   streamlit.watcherr	   r:   r   r>   r0   r   r   r   r   <module>rG      s    5 4  1 1 1 1 1 1 % % % % % % % % ' ' ' ' ' '             " " " " " "	H		  [ [ [ [ [ [ [ [ [ [r   