o
    Zh                     @  s   U d Z ddlmZ ddlZddlm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 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)Path)CallableFinal)StreamlitMaxRetriesError)
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   g/var/www/html/Persson_Maskin/env/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  s`   t || _|| _|| _|| _d| _tt| j| j| _	tj
t| 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)r   _path_on_changed_glob_pattern_allow_nonexistent_activer   path_modification_timer   _modification_timecalc_md5_with_blocking_retries_md5	_schedule)selfr   r   r   r   r   r   r   __init__1   s   
zPollingPathWatcher.__init__c                 C  s   t | S Nr	   r+   r   r   r   __repr__R   s   zPollingPathWatcher.__repr__c                   s   d fdd}t j| d S )Nr   r   c                     s   t t    d S r-   )timesleepr   _check_if_path_changedr   r.   r   r   taskV   s   
z*PollingPathWatcher._schedule.<locals>.taskr   r   )r   	_executorsubmit)r+   r3   r   r.   r   r*   U   s   zPollingPathWatcher._schedulec              
   C  s   | j sd S z8tt| j| j}|dkr || jkr |   W d S || _tjt| j| j	| jd}|| j
kr<|   W d S W n tyY } ztjd| j|d W Y d }~d S d }~ww || _
td| j | t| j |   d S )Ng        r   z9Ignoring file change. Failed to calculate MD5 for path %s)exc_infozChange detected: %s)r%   r   r&   r   r!   r$   r'   r*   r(   r#   r)   r   r   r   r"   )r+   modification_timemd5exr   r   r   r2   \   sB   

z)PollingPathWatcher._check_if_path_changedc                 C  s
   d| _ dS )zStop watching the file system.FN)r%   r.   r   r   r   close   s   
zPollingPathWatcher.closer4   )
r   r   r   r   r   r   r   r    r   r   )r   r   )__name__
__module____qualname____doc__r   r   r5   staticmethodr   r,   r/   r*   r2   r;   r   r   r   r   r   #   s    

!

+r   )r?   
__future__r   r0   concurrent.futuresr   pathlibr   typingr   r   streamlit.errorsr   streamlit.loggerr   streamlit.utilr
   streamlit.watcherr   r<   r   __annotations__r   r   r   r   r   r   r   <module>   s   