
    Fg                        S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
  S SKJr  S SKJr  S SKJr  \(       a   \" \R$                  " SS5      5      r\" \R$                  " S	S
5      5      r\R$                  " S\R$                  " SS5      5      r   S       SS jjr\R$                  " S5      SLr\" \5      R2                  R5                  SSS5      r        SS jrSS jrSSS jjrSS jrg)    )annotationsN)TimeoutError)closing)Path)TYPE_CHECKINGGRADIO_SERVER_PORT7860GRADIO_NODE_NUM_PORTS100GRADIO_NODE_SERVER_NAMEGRADIO_SERVER_NAMEz	127.0.0.1c                2   U =(       d    [         n U R                  S5      (       a  U R                  S5      (       a  U SS nOU nUb  U/O [        [        S-   [        S-   [
        -   5      n[        U=(       d    [        R                  " S5      UUS9u  pVXU4$ )a  Launches a local server running the provided Interface
Parameters:
    server_name: to make app accessible on local network, set this to "0.0.0.0". Can be set by environment variable GRADIO_SERVER_NAME.
    server_port: will start gradio app on this port (if available). Can be set by environment variable GRADIO_SERVER_PORT.
    node_path: the path to the node executable. Can be set by environment variable GRADIO_NODE_PATH.
    ssr_mode: If False, will not start the node server and will serve the SPA from the Python server

Returns:
    server_name: the name of the server (default is "localhost")
    node_process: the node process that is running the SSR app
    node_port: the port the node server is running on
[]   GRADIO_NODE_PATH)	node_pathserver_nameserver_ports)	LOCALHOST_NAME
startswithendswithrangeINITIAL_PORT_VALUETRY_NUM_PORTSstart_node_processosgetenv)r   server_portr   hostr   node_process	node_ports          c/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/gradio/node_server.pystart_node_serverr%      s    $ /K
 c""{';';C'@'@1R  " 
%)+=+AM+QR  1<ryy);<!L i//    GRADIO_LOCAL_DEV_MODE	templatesnodebuildc                  ^	 [         (       a  gU (       d  gS m	U GH  n [        R                  " 5       nUR                  [        R                  [        R                  S5        UR                  X45        UR                  5         [        R                  n[        U5      US'   XS'   [         (       a  SUS'   [        [        [        5      R                  R                  SS	5      5      n[        R                  S
:X  a  SU-   n[         R"                  " U SU[$        /[         R&                  US9m	[)        XSS9nU(       aX  [*        R*                  " [*        R,                  U	4S j5        [*        R*                  " [*        R.                  U	4S j5        T	U4s  $ T	R1                  5         T	R3                  SS9  S m	GM     [=        SUS    SUS    S35        [=        S5        [=        S5        g! [4         a     GM  [6         a?  n[8        R:                  " SU S35        T	(       a  T	R1                  5         S m	 S nAGM#  S nAff = f)N)Ni&  )NNr   PORTHOST1r'   r(   zregister.mjswin32zfile://z--import)stdoutenv   timeoutc                   > [        T5      $ Nhandle_sigterm___r"   s     r$   <lambda>$start_node_process.<locals>.<lambda>y   s
    .2Nr&   c                   > [        T5      $ r6   r7   r9   s     r$   r<   r=   {   s
    >,;Wr&      z-Unexpected error while starting Node server: z. Trying next port...z2Cannot start Node server on any port in the range r   -r   .zwPlease install Node 20 or higher and set the environment variable GRADIO_NODE_PATH to the path of your Node executable.zWYou can explicitly specify a port by setting the environment variable GRADIO_NODE_PORT.)r'   socket
setsockopt
SOL_SOCKETSO_REUSEADDRbindcloser   environstrr   __file__parentjoinpathsysplatform
subprocessPopenSSR_APP_PATHDEVNULLverify_server_startupsignalSIGTERMSIGINT	terminatewaitOSError	Exceptionwarningswarnprint)
r   r   r   portsr1   register_file
is_workinger"   s
            @r$   r   r   J   s   
 L7	 ALL**F,?,?C FFK&'GGI **Cd)CK%K$$/2+,X%%..{NKM ||w& )M 9%++J|D!))L /{!LJNN$N fmm-WX#T)) &&(!!!!,#[ v 

<\!_<MQ|\^O_N``ab 
 	B 
a -  	 	MM?sBWX &&(#	s$   E5G,!G,,
I:	I3H==Ic                     [        [        R                  " X4SS95          SSS5        g! , (       d  f       g= f! [        [        4 a     g[
         a     gf = f)z+Attempts a single connection to the server.r   r3   NTF)r   rB   create_connectionr   ConnectionRefusedErrorrZ   )r!   r^   s     r$   attempt_connectionrf      sP    V--tlAFG HGG01  s)   = ,= 
:= = A	AAc                b   [         R                   " 5       n[         R                   " 5       U-
  U:  a"   [        R                  " X4SS9    SSS5        gg! , (       d  f       O/= f! [        [        4 a    [         R
                  " S5         Of = f[         R                   " 5       U-
  U:  a  M~  N])z@Verifies if a server is up and running by attempting to connect.r   r3   NTg?F)timerB   rd   r   rY   sleep)r!   r^   r4   
start_times       r$   rS   rS      s    J
))+

"W
,	))4,B CB 	 CBg& 	JJsO		 ))+

"W
,s/   A& 	AA& 
A#A& #A& &&BBc                    U bB  [        S5        U R                  5         U R                  5         [        R                  " S5        g g )Nz
Stopping Node.js server...r   )r]   rW   rX   rM   exit)r"   s    r$   r8   r8      s9    ,- 	  r&   )NNN)r   
str | Noner    z
int | Noner   rm   returnz=tuple[str | None, subprocess.Popen[bytes] | None, int | None])r   rm   r   rI   r   zlist[int] | rangern   z1tuple[subprocess.Popen[bytes] | None, int | None])r!   rI   r^   intrn   bool)g      @)r!   rI   r^   ro   r4   floatrn   rp   )r"   zsubprocess.Popen[bytes] | None) 
__future__r   r   rT   rB   rO   rM   rh   r[   concurrent.futuresr   
contextlibr   pathlibr   typingr   ro   r   r   r   r   r%   r'   rJ   rK   rL   rQ   r   rf   rS   r8    r&   r$   <module>rx      s&   " 	    
   +     #7@A BII5u=>ryy)={K #" (0(0(0 (0 C	(0V 		"9:$F H~$$--k67KQQQ $Q 7	Qh	r&   