
    /_i2                        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	r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)Path)TYPE_CHECKINGFinal)StreamlitMaxRetriesError)
get_loggerrepr_)util)Callabler   _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     e/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/watcher/polling_path_watcher.py	close_allzPollingPathWatcher.close_all+   s     	&'r   NFglob_patternallow_nonexistentc               t   t        |      | _        || _        || _        || _        d| _        t        j                  t        | j                        | j                        | _	        t        j                  t        | 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)r   _path_on_changed_glob_pattern_allow_nonexistent_activer   path_modification_timestr_modification_timecalc_md5_with_blocking_retries_md5	_schedule)selfpath
on_changedr   r   s        r   __init__zPollingPathWatcher.__init__4   s     $Z
%)"3"&"="=

OT44#
 77

O++"55
	
 	r   c                    t        |       S Nr
   r*   s    r   __repr__zPollingPathWatcher.__repr__U   s    T{r   c                P     d fd}t         j                  j                  |       y )Nc                 X    t        j                  t                j                          y r/   )timesleepr   _check_if_path_changedr0   s   r   taskz*PollingPathWatcher._schedule.<locals>.taskY   s    JJ+,'')r   returnNone)r   	_executorsubmit)r*   r7   s   ` r   r)   zPollingPathWatcher._scheduleX   s    	* 	$$++D1r   c                   | j                   sy 	 t        j                  t        | j                        | j
                        }|dk7  r || j                  k  r| j                          y || _        t        j                  t        | j                        | j                  | j
                        }|| j                  k(  r| j                          y 	 || _
        t        j                  d| j                         | j                  t        | j                               | j                          y # t        $ r,}t        j                  d| j                  |       Y d }~y d }~ww xY w)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exs       r   r6   z)PollingPathWatcher._check_if_path_changed_   s    ||	 $ ; ;DJJ!8!8! "S(%)@)@@ &7D#55DJJ!//"&"9"9C
 dii    	+TZZ8TZZ) ( 	MMK

  
 	s   AD* 'A%D* *	E3"EEc                    d| _         y)zStop watching the file system.FN)r#   r0   s    r   closezPollingPathWatcher.close   s	    r   r8   )
r+   r%   r,   zCallable[[str], None]r   z
str | Noner   boolr9   r:   )r9   r%   )__name__
__module____qualname____doc__r   r   r;   staticmethodr   r-   r1   r)   r6   rC   r   r   r   r   r   &   st    4"|<I( ( $("' *
 !   
B2)Vr   r   )rH   
__future__r   r4   concurrent.futuresr   pathlibr   typingr   r   streamlit.errorsr   streamlit.loggerr	   streamlit.utilr   streamlit.watcherr   collections.abcr   rE   r   __annotations__r   r   r   r   r   r   <module>rT      s[    5 "  1  ' 5 '   "(H% %e ! e !f fr   