o
    沪gV                     @  s   d dl mZ d dlZd dlmZmZ d dlZd dlmZm	Z	m
Z
 d dlmZ G dd dZeed ee ee f Zd&ddZdd Z	d'dddd(ddZ	d'd)ddZ	d'dddd*dd Zd+d"d#Zd,d$d%ZdS )-    )annotationsN)CallableUnion)cli_utilconfigenv_util)PollingPathWatcherc                   @  s   e Zd ZddddddZdS )NoOpPathWatcherNFglob_patternallow_nonexistent	_path_strstr_on_changedCallable[[str], None]r   
str | Noner   boolc                C  s   d S N )selfr   r   r   r   r   r   Z/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/watcher/path_watcher.py__init__"   s   zNoOpPathWatcher.__init__)r   r   r   r   r   r   r   r   )__name__
__module____qualname__r   r   r   r   r   r	   !   s    r	   z@streamlit.watcher.event_based_path_watcher.EventBasedPathWatcherreturnr   c                  C  s$   zddl } W dS  ty   Y dS w )z*Check if the watchdog module is installed.r   NTF)watchdogImportError)r   r   r   r   _is_watchdog_available7   s   r   c                  C  sP   t ddvr$t s&tjrdnd} tjdd ddd	 td
|   d S d S d S )Nserver.fileWatcherType)pollnonez
  $ xcode-select --install z  %sz4For better performance, install the Watchdog module:blueT)fgboldz(%s
  $ pip install watchdog
            )r   
get_optionr   r   	IS_DARWINr   print_to_cli)msgr   r   r   report_watchdog_availabilityA   s   r*   Fr
   pathr   on_path_changedr   watcher_typer   r   r   c                C  s:   |du r	t d}t|}|tu rdS || |||d dS )a&  Create a PathWatcher for the given path if we have a viable
    PathWatcher class.

    Parameters
    ----------
    path
        Path to watch.
    on_path_changed
        Function that's called when the path changes.
    watcher_type
        Optional watcher_type string. If None, it will default to the
        'server.fileWatcherType` config option.
    glob_pattern
        Optional glob pattern to use when watching a directory. If set, only
        files matching the pattern will be counted as being created/deleted
        within the watched directory.
    allow_nonexistent
        If True, allow the file or directory at the given path to be
        nonexistent.

    Returns
    -------
    bool
        True if the path is being watched, or False if we have no
        PathWatcher class.
    Nr   Fr
   T)r   r&   get_path_watcher_classr	   )r+   r,   r-   r   r   watcher_classr   r   r   _watch_pathU   s   "
r0   on_file_changedc                 C  s   t | ||S r   )r0   )r+   r1   r-   r   r   r   
watch_file   s   r2   on_dir_changedc                C  s    t j| d} t| ||||dS )Nr"   r
   )osr+   joinr0   )r+   r3   r-   r   r   r   r   r   	watch_dir   s   
r6   PathWatcherTypec                   C  s   t tdS )zsReturn the class to use for path changes notifications, based on the
    server.fileWatcherType config option.
    r   )r.   r   r&   r   r   r   r   get_default_path_watcher_class   s   r8   c                 C  s:   | dv rt  rddlm} |S | dkrtS | dkrtS tS )zReturn the PathWatcher class that corresponds to the given watcher_type
    string. Acceptable values are 'auto', 'watchdog', 'poll' and 'none'.
    >   autor   r   )EventBasedPathWatcherr9   r    )r   *streamlit.watcher.event_based_path_watcherr:   r   r	   )r-   r:   r   r   r   r.      s   r.   )r   r   r   )r+   r   r,   r   r-   r   r   r   r   r   r   r   )r+   r   r1   r   r-   r   r   r   )r+   r   r3   r   r-   r   r   r   r   r   r   r   )r   r7   )r-   r   r   r7   )
__future__r   r4   typingr   r   streamlit.watcher	streamlitr   r   r   &streamlit.watcher.polling_path_watcherr   r	   typer7   r   r*   r0   r2   r6   r8   r.   r   r   r   r   <module>   s:   

5
