o
    沪g                     @  s   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 dZdS )z.A class that watches a given path via polling.    )annotationsN)ThreadPoolExecutor)CallableFinal)
get_loggerrepr_)utilr   _LOGGER   _MAX_WORKERSg?_POLLING_PERIOD_SECSc                   @  sb   e Zd ZdZeedZedddZddd	dddZ	dddZ
dddZdddZdddZdS )PollingPathWatcherz*Watches a path on disk via a polling loop.)max_workersreturnNonec                   C  s   t d dS )zClose top-level watcher object.

        This is a no-op, and exists for interface parity with
        EventBasedPathWatcher.
        zWatcher closedN)r
   debug r   r   b/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/watcher/polling_path_watcher.py	close_all&   s   zPollingPathWatcher.close_allNFglob_patternallow_nonexistentpathstr
on_changedCallable[[str], None]r   
str | Noner   boolc                C  sT   || _ || _|| _|| _d| _t| j | j| _tj| j | j| jd| _	| 
  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   r   r   r   __init__/   s   zPollingPathWatcher.__init__c                 C  s   t | S Nr   r)   r   r   r   __repr__P   s   zPollingPathWatcher.__repr__c                   s    fdd}t j| d S )Nc                     s   t t    d S r+   )timesleepr   _check_if_path_changedr   r,   r   r   taskT   s   
z*PollingPathWatcher._schedule.<locals>.task)r   	_executorsubmit)r)   r1   r   r,   r   r(   S   s   zPollingPathWatcher._schedulec                 C  s   | j sd S t| j| j}|dkr|| jkr|   d S || _tj| j| j| jd}|| j	kr5|   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md5r   r   r   r0   Z   s*   
z)PollingPathWatcher._check_if_path_changedc                 C  s
   d| _ dS )zStop watching the file system.FN)r#   r,   r   r   r   closez   s   
zPollingPathWatcher.close)r   r   )
r   r   r   r   r   r   r   r   r   r   )r   r   )__name__
__module____qualname____doc__r   r   r2   staticmethodr   r*   r-   r(   r0   r6   r   r   r   r   r   !   s    

!

 r   )r:   
__future__r   r.   concurrent.futuresr   typingr   r   streamlit.loggerr   streamlit.utilr   streamlit.watcherr	   r7   r
   __annotations__r   r   r   r   r   r   r   <module>   s   