
    ;3hB	                        d Z ddlmZ ddlZddlZddlZddlmZ ddlZddl	m
Z
 ddlmZmZ dZ ej                  d      Z	 	 	 	 	 	 	 	 	 	 	 	 dd	Zdd
Zy)z^
Defines helper methods useful for setting up ports, launching servers, and
creating tunnels.
    )annotationsN)Path)App)CERTIFICATE_PATHTunnelz(https://api.gradio.app/v3/tunnel-requestGRADIO_SHARE_SERVER_ADDRESSc                2   |t         n|}|	 t        j                  t        d      }|j	                         d   }|d   t        |d         }}|d   }	t        t              j                  j                  dd       t        t        d	      5 }
|
j                  |	       d d d        t        }n|j                  d      \  }}t        |      }t        ||| |||      }|j!                         }|S # 1 sw Y   QxY w# t        $ r}t        d
      |d }~ww xY w)N   )timeoutr   hostportroot_caT)parentsexist_okwz0Could not get share link from Gradio API Server.:)r   httpxgetGRADIO_API_SERVERjsonintr   r   parentmkdiropenwrite	ExceptionRuntimeErrorsplitr   start_tunnel)
local_host
local_portshare_tokenshare_server_addressshare_server_tls_certificateresponsepayloadremote_hostremote_portcertificatefetunneladdresss                 Q/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/networking.pysetup_tunnelr/      s.     ' 	$! 
 #	yy!2B?Hmmoa(G'.vGFO8LK!),K!"))//t/L&, %$%+;( $8#=#=c#B [+&$F !!#GN'% %  	B	s0   B C< C0 C< 0C95C< <	DDDc                z   	 t        d      D ]q  }t        j                         5  t        j                  d       t	        j
                  | dd      }d d d        j                  dv r yt        j                  d       s 	 y# 1 sw Y   2xY w# t        t        j                  t        j                  f$ r Y yw xY w)	N   ignore   F)r   verify)   i  i.  i/  i3  Tg      ?)rangewarningscatch_warningsfilterwarningsr   headstatus_codetimesleepConnectionErrorConnectErrorTimeoutException)url_rs      r.   url_okrD   ?   s    q 	A((* =''1JJsAe<= !::JJu	 = = U//1G1GH s.   "B .BB *B B	B (B:9B:)r    strr!   r   r"   rE   r#   
str | Noner$   rF   returnrE   )rA   rE   rG   bool)__doc__
__future__r   osr<   r7   pathlibr   r   gradio.routesr   gradio.tunnelingr   r   r   getenvr   r/   rD        r.   <module>rR      s   
 # 	      5> 'bii(EF &&& & %	&
 #-& 	&RrQ   