
    MhP3                        U d Z ddlZddlZedk    r1ej        d         ej                            e          k    rej        d= 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ZddlZddlmZ ddlmZ ddlmZ 	 ddlZn# e$ r dZY nw xY wddlmZmZmZmZmZ ej        dk    Z e            Zg Z d	a! ej"                    Z#d
e$d<   d	a%da&eee'                  e$d<   da(dde)ddfdZ*ddZ+de'ddfdZ,deg df         ddfdZ-dee'e.f         ddfdZ/dee'e.f         de'ddfdZ0ddZ1dZ2ddZ3edk    r e3             dS dS )a7  Automatically restart the server when a source file is modified.

Most applications should not access this module directly.  Instead,
pass the keyword argument ``autoreload=True`` to the
`tornado.web.Application` constructor (or ``debug=True``, which
enables this setting and several others).  This will enable autoreload
mode as well as checking for changes to templates and static
resources.  Note that restarting is a destructive operation and any
requests in progress will be aborted when the process restarts.  (If
you want to disable autoreload while using other debug-mode features,
pass both ``debug=True`` and ``autoreload=False``).

This module can also be used as a command-line wrapper around scripts
such as unit test runners.  See the `main` method for details.

The command-line wrapper and Application debug modes can be used together.
This combination is encouraged as the wrapper catches syntax errors and
other import-time failures, while debug mode catches changes once
the server has started.

This module will not work correctly when `.HTTPServer`'s multi-process
mode is used.

Reloading loses any Python interpreter command-line arguments (e.g. ``-u``)
because it re-executes Python using ``sys.executable`` and ``sys.argv``.
Additionally, modifying these variables will cause reloading to behave
incorrectly.

    N__main__)ioloop)gen_log)process)CallableDictOptionalListUnionwin32Fz.weakref.WeakKeyDictionary[ioloop.IOLoop, bool]	_io_loops_original_argv  
check_timereturnc                 N   t           j                                        }|t          v rdS dt          |<   t	          t                    dk    rt          j        d           i }t          j        t          |          }t          j
        ||           }|                                 dS )zBegins watching source files for changes.

    .. versionchanged:: 5.0
       The ``io_loop`` argument (deprecated since version 4.1) has been removed.
    NT   z=tornado.autoreload started more than once in the same process)r   IOLoopcurrentr   lenr   warning	functoolspartial_reload_on_updatePeriodicCallbackstart)r   io_loopmodify_timescallback	schedulers        R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tornado/autoreload.pyr   r   r   s     m##%%G)Ig
9~~WXXX%'L !2LAAH'*==IOO    c                      t          j                    } |                     t                     |                                  dS )zWait for a watched file to change, then restart the process.

    Intended to be used at the end of scripts like unit test runners,
    to run the tests again after any source file changes (but see also
    the command-line interface in `main`)
    N)r   r   add_callbackr   )r   s    r!   waitr%      s4     mooGMMOOOOOr"   filenamec                 :    t                               |            dS )zTAdd a file to the watch list.

    All imported modules are watched by default.
    N)_watched_filesadd)r&   s    r!   watchr*      s    
 x     r"   fnc                 :    t                               |            dS )a  Add a function to be called before reloading the process.

    Note that for open file and socket handles it is generally
    preferable to set the ``FD_CLOEXEC`` flag (using `fcntl` or
    `os.set_inheritable`) instead of using a reload hook to close them.
    N)_reload_hooksappend)r+   s    r!   add_reload_hookr/      s     r"   r   c                    t           rd S t          j                    d S t          t          j                                                  D ]u}t          |t          j	                  st          |dd           }|s1|                    d          s|                    d          r
|d d         }t          | |           vt          D ]}t          | |           d S )N__file__z.pycz.pyo)_reload_attemptedr   task_idlistsysmodulesvalues
isinstancetypes
ModuleTypegetattrendswith_check_filer(   )r   modulepaths      r!   r   r      s     $ 	s{))++,, ( (
 &%"233 	vz400 	==   	DMM&$9$9 	9DL$'''' ( (L$''''( (r"   r@   c                     	 t          j        |          j        }n# t          $ r Y d S w xY w|| vr|| |<   d S | |         |k    r%t	          j        d|           t                       d S d S )Nz%s modified; restarting server)osstatst_mtime	Exceptionr   info_reload)r   r@   modifieds      r!   r>   r>      s    74==)   <%TDX%%5t<<<					 &%s    
**c                  D   da t          D ]}  |              t          j        dk    r t	          j        t          j        dd           t          rt          J t          }t          }n-t          t          j        d         dd           }t          j        }|r|j        dk    rd|j        g|dd          z   }t          s8t          j        t          j        g|z              t%          j        d           d S t%          j        t          j        t          j        g|z              d S )NTr   r   r   __spec__-mr   )r3   r-   r6   platformsignal	setitimerITIMER_REAL_autoreload_is_mainr   _original_specr<   r7   argvname
_has_execv
subprocessPopen
executablerB   _exitexecv)r+   specrR   s      r!   rG   rG      s     

|w 	+Q222
  )))s{:.
DAAx 	,	Z'' di 48+ :#.)D0111

#.!1D!899999r"   zv
  python -m tornado.autoreload -m module.to.run [args...]
  python -m tornado.autoreload path/to/script.py [args...]
c                  $   ddl } ddl}dx|j        _        at          j        }|x|j        _        at          t          j        d         dd          }|x|j        _	        a	| 
                    dt          d          }|                                 |                    d	d
d
d           |                    ddd           |                                \  }}|j        N|s/t!          dt          j                   t	          j        d           |d         }|dd         t          _        n"d}t          j        d         g|z   t          _        d}	 ddl}	|j        |	                    |j        dd           n|J |	                    |d           d}t-          j        d           n# t0          $ r+}
|
j        }t-          j        d|
j                   Y d}
~
nd}
~
wt4          $ r}
t-          j        dd           t9          j        t	          j                    d                   D ]\  }}}}t?          |           tA          |
tB                    r|
j"        t?          |
j"                   Y d}
~
nd}
~
ww xY w|t          _        |j        d|j        J tG          j$        |j                  }|@tA          |tJ          j&        j'                  r!t?          |(                                           |j)        r|sdS tU                       dS )a  Command-line wrapper to re-run a script whenever its source changes.

    Scripts may be specified by filename or module name::

        python -m tornado.autoreload -m tornado.test.runtests
        python -m tornado.autoreload tornado/test/runtests.py

    Running a script with this wrapper is similar to calling
    `tornado.autoreload.wait` at the end of the script, but this wrapper
    can catch import-time problems like syntax errors that would otherwise
    prevent the script from reaching its call to `wait`.
    r   NTr   rJ   zpython -m tornado.autoreloadz3Either -m or a path must be specified, but not both)progusageepilogrK   r?   zmodule to run)destmetavarhelpz--until-success
store_truezCstop reloading after the program exist successfully (status code 0))actionra   z%Either -m or a path must be specified)filer   )run_name	alter_sys)re   zScript exited normallyzScript exited with status %sz%Script exited with uncaught exception)exc_info   )+optparsetornado.autoreload
autoreloadrP   r6   rR   r   r<   r7   rQ   OptionParser_USAGEdisable_interspersed_args
add_option
parse_argsr?   printstderrexitrunpy
run_modulerun_pathr   rF   
SystemExitcoderE   r   	traceback
extract_tbrg   r*   r9   SyntaxErrorr&   pkgutil
get_loader	importlibabc
FileLoaderget_filenameuntil_successr%   )ri   tornadooriginal_argvoriginal_specparseroptsrestr@   exit_statusrt   er&   linenorS   lineloaders                   r!   mainr      sP   * OOO DHGG*-@HM9FFG%CK
3ZFFM9FFG%""+D #  F
 $$&&&
d8/RRR
R    
 ""$$JD${ 	9
KKKKHQKKKAw7HQK=4' *+K/;"T[:NNNN###NN4*N555& -....'  = = =f3QV<<<<<<<< " " "?$OOOO
 -6,@PQAR,S,S 	 	(HfdD(OOOOa%% 	" z%aj!!!"$ CH{{&&& #DK00*VY]5M"N"N&%%''((( + FFFFFs&   AF. .
I=8!GI=+BI88I=)r   )r   N)4__doc__rB   r6   __name__r@   dirnamer1   r   importlib.abcr~   r|   ry   r:   rU   weakrefr   r   tornado.logr   r   rM   ImportErrortypingr   r   r	   r
   r   rL   rT   setr(   r-   r3   WeakKeyDictionaryr   __annotations__rP   r   strrQ   intr   r%   r*   r/   floatr   r>   rG   rm   r    r"   r!   <module>r      s     < 
			 



( z x{bgooh////HQK         				  



                            MMMM   FFF 9 8 8 8 8 8 8 8 8 8 8 8 8 8
 \W$
 G 
;     &*c# * * * c D    $	 	 	 	!C !D ! ! ! !T* t    (De$4 ( ( ( ( (4
d3:. 
c 
d 
 
 
 
$: $: $: $:N
b b b bJ z 	DFFFFF s   :A? ?B	B	