o
    沪g                     @  s6  U d dl mZ d dlZd dlZd dlmZ d dlmZmZ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 eeZd
ed< eZded< eZded< eZded< eZded< G dd de	Zd1ddZedZ d2ddZ!d3dd Z"e# Z$da%d!ed"< ed#d$Z&d4d&d'Z'd5d*d+Z(d6d/d0Z)dS )7    )annotationsN)Path)CallableFinal	TypedDict)Signal)NotRequired	TypeAlias)
get_logger)extract_leading_emoji)calc_md5r   _LOGGERr	   PageHashPageName
ScriptPathIconc                   @  s6   e Zd ZU ded< ded< ded< ded< d	ed
< dS )PageInfor   script_pathr   page_script_hashzNotRequired[Icon]iconzNotRequired[PageName]	page_namezNotRequired[str]url_pathnameN)__name__
__module____qualname____annotations__ r   r   Q/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/source_util.pyr   %   s   
 r   filenamestrc                 C  s(   ddl }t|dr|| S t| ddS )a8  Open a read-only Python file taking proper care of its encoding.

    In Python 3, we would like all files to be opened with utf-8 encoding.
    However, some author like to specify PEP263 headers in their source files
    with their own encodings. In that case, we should respect the author's
    encoding.
    r   Nopenzutf-8)encoding)tokenizehasattrr    )r   r"   r   r   r   open_python_file-   s   

r$   z([0-9]*)[_ -]*(.*)\.pyr   r   returntuple[float, str]c                 C  sZ   t t| j}t|dksJ |  d|\\}}| }|dkr'td|fS t||fS )Nr   z is not a Python file inf)refindallPAGE_FILENAME_REGEXnamelenlowerfloat)r   matchesnumberlabelr   r   r   page_sort_keyB   s   
r3   tuple[str, str]c                 C  sD   t t| j}|du rdS t dd|d p|d}t|S )a  Compute the icon and name of a page from its script path.

    This is *almost* the page name displayed in the nav UI, but it has
    underscores instead of spaces. The reason we do this is because having
    spaces in URLs both looks bad and is hard to deal with due to the need to
    URL-encode them. To solve this, we only swap the underscores for spaces
    right before we render page names.
    N)r'   r'   z[_ ]+_      )r)   searchr+   r,   subgroupstripr   )r   
extractionicon_and_namer   r   r   page_icon_and_nameR   s   	r>   zdict[PageHash, PageInfo] | None_cached_pagesz+Emitted when the pages directory is changed)docNonec                   C  s>   t d t
 d aW d    n1 sw   Y  t  d S )NzPages directory changed)r   debug_pages_cache_lockr?   _on_pages_changedsendr   r   r   r   invalidate_pages_cachek   s
   
rF   main_script_path_strdict[PageHash, PageInfo]c                 C  s   t }|d ur|S te t d urt W  d    S t| }t|\}}t| }||||t| di}|jd }tdd |	dD t
d}|D ]}	t|	 }
t|	\}}t|
}||||
d||< qH|a |W  d    S 1 srw   Y  d S )N)r   r   r   r   pagesc                 S  s&   g | ]}|j d s|j dks|qS ).z__init__.py)r,   
startswith).0fr   r   r   
<listcomp>   s    

zget_pages.<locals>.<listcomp>z*.py)key)r?   rC   r   r>   r   r   resolveparentsortedglobr3   )rG   precached_pagesmain_script_pathmain_page_iconmain_page_namemain_script_hashrI   	pages_dirpage_scriptsr   script_path_strpipnpshr   r   r   	get_pagesu   sH   

		$r_   callbackCallable[[str], None]Callable[[], None]c                   s    fdd}t j dd |S )Nc                     s   t   d S )N)rD   
disconnectr   r`   r   r   rc      s   z3register_pages_changed_callback.<locals>.disconnectF)weak)rD   connect)r`   rc   r   rd   r   register_pages_changed_callback   s   rg   )r   r   )r   r   r%   r&   )r   r   r%   r4   )r%   rA   )rG   r   r%   rH   )r`   ra   r%   rb   )*
__future__r   r)   	threadingpathlibr   typingr   r   r   blinkerr   typing_extensionsr   r	   streamlit.loggerr
   streamlit.string_utilr   streamlit.utilr   r   r   r   r   r   r   r   r   r   r$   compiler+   r3   r>   RLockrC   r?   rD   rF   r_   rg   r   r   r   r   <module>   s4   







9