o
    
¨Ýjü:  ã                   @  sŒ  U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZ	d dl
mZ d dlmZ ddlmZ eejejhƒZh e£ej’ej’ZeedƒrRe ej¡ eeƒZ[h d£Zd6dd„Zd7dd„Zd8dd„Zd8dd„Zd9dd„Zd:dd„Z G dd„ dƒZ!G d d!„ d!e!ƒZ"G d"d#„ d#e!ƒZ#e"e#d$œZ$d%e%d&< ze&d'ƒ W n e'y®   e$d( e$d)< Y nw e$d* e$d)< d;d+d,„Z(				)d<d=d4d5„Z)dS )>é    )ÚannotationsN)Úchain)ÚPurePathé   )Ú_logÚreal_prefix>   z.mypy_cachez.hgz.pytest_cachez.noxz.toxz.gitÚ__pycache__Úreturnút.Iterator[str]c                  c  sr   � t tj ¡ ƒD ].} t| ddƒ}|du s| t¡rqtj 	|¡s3|}tj 
|¡}||kr-n	tj 	|¡r |V  qdS )z;Find the filesystem paths associated with imported modules.Ú__file__N)ÚlistÚsysÚmodulesÚvaluesÚgetattrÚ
startswithÚ_ignore_alwaysÚosÚpathÚisfileÚdirname)ÚmoduleÚnameÚold© r   úM/var/www/html/chatgpt/venv/lib/python3.10/site-packages/werkzeug/_reloader.pyÚ_iter_module_paths+   s   €ú€òr   Úpathsúset[str]Úexclude_patternsÚNonec                 C  s    |D ]}|   t | |¡¡ qd S ©N)Údifference_updateÚfnmatchÚfilter)r   r   Úpatternr   r   r   Ú_remove_by_pattern?   s   ÿr&   Úextra_filesút.Iterable[str]c           
   	   C  sú   t ƒ }tttjƒ| ƒD ]d}tj |¡}tj |¡r| |¡ qtj 	|¡di}t 
|¡D ]B\}}}| t¡s>tj |¡tv rC| ¡  q,d}|D ]}	|	 d¡rZd}| tj ||	¡¡ qG|sj|tj 	|¡ sj| ¡  q,|||< q,q| tƒ ¡ t||ƒ |S )ax  Find paths for the stat reloader to watch. Returns imported
    module files, Python files under non-system paths. Extra files and
    Python files under extra directories can also be scanned.

    System paths have to be excluded for efficiency. Non-system paths,
    such as a project root or ``sys.path.insert``, should be the paths
    of interest to the user anyway.
    TF)z.pyz.pyc)Úsetr   r   r   r   r   Úabspathr   Úaddr   Úwalkr   Ú_stat_ignore_scanÚbasenameÚ_ignore_common_dirsÚclearÚendswithÚjoinÚupdater   r&   )
r'   r   r   r   Zparent_has_pyÚrootÚdirsÚfilesZhas_pyr   r   r   r   Ú_find_stat_pathsD   s6   
ÿ
€
ë
r7   c                 C  sz   t ƒ }tttjƒ| ƒD ]}tj |¡}tj |¡rtj |¡}| 	|¡ qt
ƒ D ]}| 	tj |¡¡ q(t||ƒ t|ƒS )z­Find paths for the stat reloader to watch. Looks at the same
    sources as the stat reloader, but watches everything under
    directories instead of individual files.
    )r)   r   r   r   r   r   r*   r   r   r+   r   r&   Ú_find_common_roots)r'   r   r5   r   r   r   r   Ú_find_watchdog_pathsw   s   

r9   c                   sh   i }t dd„ | D ƒtdd�D ]}|}|D ]}| |i ¡}q| ¡  qtƒ ‰d‡ ‡fdd„‰ ˆ |dƒ ˆS )Nc                 s  s   � | ]}t |ƒjV  qd S r!   )r   Úparts©Ú.0Úxr   r   r   Ú	<genexpr>’   s   € z%_find_common_roots.<locals>.<genexpr>T)ÚkeyÚreverseÚnodeú t.Mapping[str, dict[str, t.Any]]r   útuple[str, ...]r	   r    c                   sH   |   ¡ D ]\}}ˆ |||f ƒ q| s |r"ˆ tjj|Ž ¡ d S d S d S r!   )Úitemsr+   r   r   r2   )rA   r   ÚprefixÚchild©Ú_walkÚrvr   r   rH   œ   s
   ÿz!_find_common_roots.<locals>._walkr   )rA   rB   r   rC   r	   r    )ÚsortedÚlenÚ
setdefaultr0   r)   )r   r4   ÚchunksrA   Úchunkr   rG   r   r8   �   s   

	r8   ú	list[str]c                  C  sx  t jdkrt jgt jdd… ¢S t jg} t jd }t jdd… }t jd }t|ddƒdu sFtjdkr„|j	dkr„tj
 |¡s„tj
 |› d	�¡r„tj
 |¡}tjdkr~tj
 |¡sdtj
 |› d	�¡rd|d	7 }tj
 t j¡d d	kr~tj
 |¡d d	kr~|  d¡ |  |¡ n1tj
 |¡r©t t|j	¡}tj
 tj
 |¡¡d }|dkr¨|d
|› �7 }n|}|  d| d
¡f¡ |  |¡ | S )zpDetermine how the script was executed, and return the args needed
    to execute it again in a new process.
    )é   é
   r   Nr   Ú__main__Ú__package__ÚntÚ z.exeÚ.z-m)r   Úversion_infoÚ
executableÚ	orig_argvÚargvr   r   r   r   rS   r   Úexistsr*   ÚsplitextÚpopÚappendr   ÚtÚcastÚstrr.   ÚextendÚlstrip)rI   Z	py_scriptÚargsrR   Z	py_moduler   r   r   r   Ú_get_args_for_reloading©   s>   





ÿþ

€
re   c                   @  sf   e Zd ZdZ			dd dd„Zd!dd„Zdd„ Zd"dd„Zd"dd„Zd#dd„Z	d$dd„Z
d%dd„ZdS )&ÚReloaderLooprU   Nr   r'   út.Iterable[str] | Noner   Úintervalúint | floatr	   r    c                 C  s,   dd„ |pdD ƒ| _ t|pdƒ| _|| _d S )Nc                 S  s   h | ]}t j |¡’qS r   )r   r   r*   r;   r   r   r   Ú	<setcomp>í   ó    z(ReloaderLoop.__init__.<locals>.<setcomp>r   )r'   r)   r   rh   )Úselfr'   r   rh   r   r   r   Ú__init__ç   s   
zReloaderLoop.__init__c                 C  s   |   ¡  | S )zgDo any setup, then run one step of the watch to populate the
        initial filesystem state.
        )Úrun_step©rl   r   r   r   Ú	__enter__ñ   s   zReloaderLoop.__enter__c                 C  ó   dS )z4Clean up any resources associated with the reloader.Nr   ©rl   Úexc_typeÚexc_valÚexc_tbr   r   r   Ú__exit__ø   s   zReloaderLoop.__exit__c                 C  s   	 |   ¡  t | j¡ q)zfContinually run the watch step, sleeping for the configured
        interval after each step.
        )rn   ÚtimeÚsleeprh   ro   r   r   r   Úrunü   s   þzReloaderLoop.runc                 C  rq   )z}Run one step for watching the filesystem. Called once to set
        up initial state, then repeatedly to update it.
        Nr   ro   r   r   r   rn     s   zReloaderLoop.run_stepÚintc                 C  sJ   	 t dd| j› �ƒ tƒ }tj ¡ }d|d< tj||dd�}|dkr$|S q)	z|Spawn a new Python interpreter with the same arguments as the
        current one, but running the reloader thread.
        TÚinfoz * Restarting with ÚtrueÚWERKZEUG_RUN_MAINF)ÚenvÚ	close_fdsrP   )r   r   re   r   ÚenvironÚcopyÚ
subprocessÚcall)rl   rd   Znew_environÚ	exit_coder   r   r   Úrestart_with_reloader
  s   
øz"ReloaderLoop.restart_with_reloaderÚfilenamera   c                 C  s   |   |¡ t d¡ d S )NrP   )Ú
log_reloadr   Úexit©rl   r†   r   r   r   Útrigger_reload  ó   
zReloaderLoop.trigger_reloadústr | bytesc                 C  s"   t j |¡}tdd|›d�ƒ d S )Nr{   z * Detected change in z, reloading)r   r   r*   r   r‰   r   r   r   r‡     s   zReloaderLoop.log_reload)NNr   )r'   rg   r   rg   rh   ri   r	   r    ©r	   rf   ©r	   r    )r	   rz   )r†   ra   r	   r    ©r†   rŒ   r	   r    )Ú__name__Ú
__module__Ú__qualname__r   rm   rp   rv   ry   rn   r…   rŠ   r‡   r   r   r   r   rf   ä   s    ü





rf   c                      s,   e Zd ZdZd	‡ fdd„Zd
dd„Z‡  ZS )ÚStatReloaderLoopÚstatr	   rf   c                   s   i | _ tƒ  ¡ S r!   )ÚmtimesÚsuperrp   ro   ©Ú	__class__r   r   rp   $  s   
zStatReloaderLoop.__enter__r    c              	   C  sn   t | j| jƒD ]-}zt |¡j}W n	 ty   Y qw | j |¡}|d u r+|| j|< q||kr4|  	|¡ qd S r!   )
r7   r'   r   r   r”   Úst_mtimeÚOSErrorr•   ÚgetrŠ   )rl   r   ÚmtimeZold_timer   r   r   rn   (  s   ÿ

€ózStatReloaderLoop.run_stepr�   rŽ   )r�   r‘   r’   r   rp   rn   Ú__classcell__r   r   r—   r   r“   !  s    r“   c                      sR   e Zd Zd‡ fdd„Zdd
d„Zd‡ fdd„Zdd„ Zddd„Zddd„Z‡  Z	S )ÚWatchdogReloaderLooprd   út.AnyÚkwargsr	   r    c           	        s  ddl m‰  ddl m‰ ddl m‰ ddl m‰ ddl m‰ ddl m} ddl m} dd	lm	} t
ƒ j|i |¤Ž | j‰G ‡ ‡‡‡‡‡fd
d„d|ƒ}|j ¡ }| d¡r[|d d… }d|› d�| _|ƒ | _dd„ | jD ƒ}|dddg|¢g dd„ tD ƒ¢| j¢d�| _t ¡ | _d S )Nr   )ÚEVENT_TYPE_CLOSED)ÚEVENT_TYPE_CREATED)ÚEVENT_TYPE_DELETED)ÚEVENT_TYPE_MODIFIED)ÚEVENT_TYPE_MOVED)ÚFileModifiedEvent)ÚPatternMatchingEventHandler)ÚObserverc                      s$   e Zd Zd‡ ‡‡‡‡‡fdd„ZdS )	z3WatchdogReloaderLoop.__init__.<locals>.EventHandlerÚeventr¦   r	   r    c                   s&   |j ˆ ˆˆˆˆhvrd S ˆ|jƒ d S r!   )Z
event_typeZsrc_path)rl   r©   ©r¡   r¢   r£   r¤   r¥   rŠ   r   r   Úon_any_eventH  s   ûz@WatchdogReloaderLoop.__init__.<locals>.EventHandler.on_any_eventN)r©   r¦   r	   r    )r�   r‘   r’   r«   r   rª   r   r   ÚEventHandlerG  s    r¬   Úobserveriøÿÿÿz
watchdog (ú)c                 s  s    � | ]}t j |¡s|V  qd S r!   )r   r   Úisdir)r<   Úpr   r   r   r>   \  s   € z0WatchdogReloaderLoop.__init__.<locals>.<genexpr>z*.pyz*.pycz*.zipc                 S  s   g | ]}d |› d�‘qS )z*/z/*r   )r<   Údr   r   r   Ú
<listcomp>`  rk   z1WatchdogReloaderLoop.__init__.<locals>.<listcomp>)ÚpatternsÚignore_patterns)Zwatchdog.eventsr¡   r¢   r£   r¤   r¥   r¦   r§   Zwatchdog.observersr¨   r–   rm   rŠ   r�   Úlowerr1   r   r­   r'   r/   r   Úevent_handlerÚ	threadingÚEventÚshould_reload)	rl   rd   r    r¦   r§   r¨   r¬   Zreloader_nameZextra_patternsr—   rª   r   rm   :  s4   

ÿþþzWatchdogReloaderLoop.__init__r†   rŒ   c                 C  s   | j  ¡  |  |¡ d S r!   )r¹   r)   r‡   r‰   r   r   r   rŠ   f  s   
z#WatchdogReloaderLoop.trigger_reloadrf   c                   s   i | _ | j ¡  tƒ  ¡ S r!   )Úwatchesr­   Ústartr–   rp   ro   r—   r   r   rp   m  s   

zWatchdogReloaderLoop.__enter__c                 C  s   | j  ¡  | j  ¡  d S r!   )r­   Ústopr2   rr   r   r   r   rv   r  r‹   zWatchdogReloaderLoop.__exit__c                 C  s6   | j j| jd�s|  ¡  | j j| jd�rt d¡ d S )N)ÚtimeoutrP   )r¹   Úwaitrh   rn   r   rˆ   ro   r   r   r   ry   v  s   ÿzWatchdogReloaderLoop.runc              	   C  sž   t | jƒ}t| j| jƒD ]*}|| jvr1z| jj| j|dd�| j|< W n ty0   d | j|< Y nw | 	|¡ q|D ]}| j 
|d ¡}|d urL| j |¡ q9d S )NT)Ú	recursive)r)   rº   r9   r'   r   r­   Zscheduler¶   rš   Údiscardr]   Z
unschedule)rl   Z	to_deleter   Úwatchr   r   r   rn   |  s"   

ÿü€üzWatchdogReloaderLoop.run_step)rd   rŸ   r    rŸ   r	   r    r�   r�   rŽ   )
r�   r‘   r’   rm   rŠ   rp   rv   ry   rn   r�   r   r   r—   r   rž   9  s    
,
rž   )r”   Úwatchdogzdict[str, type[ReloaderLoop]]Úreloader_loopszwatchdog.observersr”   ÚautorÂ   c                  C  s€   t jdu s
t j ¡ sdS zddl} W n
 ty   Y dS w |  t j¡}|d | j@ s>|d  | jO  < |  t j| j|¡ dS dS )zuEnsure that echo mode is enabled. Some tools such as PDB disable
    it which causes usability issues after a reload.Nr   rP   )	r   ÚstdinÚisattyÚtermiosÚImportErrorÚ	tcgetattrÚECHOÚ	tcsetattrÚTCSANOW)rÇ   Ú
attributesr   r   r   Úensure_echo_on¡  s   ÿþrÎ   Ú	main_funcút.Callable[[], None]rg   rh   ri   Úreloader_typera   c                 C  s¾   ddl }|  |jdd„ ¡ t| |||d�}z>tj d¡dkrKtƒ  tj| dd	�}d
|_	|� | 
¡  | ¡  W d  ƒ W dS 1 sCw   Y  W dS t | ¡ ¡ W dS  ty^   Y dS w )z<Run the given function in an independent Python interpreter.r   Nc                  W  s
   t  d¡S )Nr   )r   rˆ   )rd   r   r   r   Ú<lambda>¾  s   
 z#run_with_reloader.<locals>.<lambda>)r'   r   rh   r}   r|   r   )Útargetrd   T)ÚsignalÚSIGTERMrÃ   r   r€   r›   rÎ   r·   ÚThreadÚdaemonr»   ry   r   rˆ   r…   ÚKeyboardInterrupt)rÏ   r'   r   rh   rÑ   rÔ   Zreloaderr_   r   r   r   Úrun_with_reloader´  s$   ÿ
&þÿrÙ   )r	   r
   )r   r   r   r   r	   r    )r'   r   r   r   r	   r(   )r   r(   r	   r(   )r	   rO   rŽ   )NNr   rÄ   )rÏ   rÐ   r'   rg   r   rg   rh   ri   rÑ   ra   r	   r    )*Ú
__future__r   r#   r   r‚   r   r·   rw   Útypingr_   Ú	itertoolsr   Úpathlibr   Ú	_internalr   ÚtupleÚbase_prefixÚbase_exec_prefixr   rE   Úexec_prefixÚhasattrr+   r   r-   r/   r   r&   r7   r9   r8   re   rf   r“   rž   rÃ   Ú__annotations__Ú
__import__rÈ   rÎ   rÙ   r   r   r   r   Ú<module>   sT    




3

;=\þÿ
û