
    +jo
                        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 ddlmZmZ dZ ej        d	          ZddZddZdS )z^
Defines helper methods useful for setting up ports, launching servers, and
creating tunnels.
    )annotationsN)Path)ShareCertificateWriteError)App)CERTIFICATE_PATHTunnelz(https://api.gradio.app/v3/tunnel-requestGRADIO_SHARE_SERVER_ADDRESS
local_hoststr
local_portintshare_tokenshare_server_address
str | Noneshare_server_tls_certificatereturnc                   |t           n|}|	 t          j        t          d          }|                                d         }|d         t          |d                   }}|d         }	n"# t          $ r}
t          d          |
d }
~
ww xY w	 t          t                    j
                            dd	           t          t          d
          5 }|                    |	           d d d            n# 1 swxY w Y   n%# t          $ r}
t          |
 d          |
d }
~
ww xY wt          }n'|                    d          \  }}t          |          }t!          ||| |||          }|                                }|S )N   )timeoutr   hostportroot_caz0Could not get share link from Gradio API Server.T)parentsexist_okwzB. This can happen when the current working directory is read-only.:)r	   httpxgetGRADIO_API_SERVERjsonr   	ExceptionRuntimeErrorr   r   parentmkdiropenwriter   splitr   start_tunnel)r
   r   r   r   r   responsepayloadremote_hostremote_portcertificateeftunneladdresss                 U/home/wildlama/visual-decline/.venv/lib/python3.11/site-packages/gradio/networking.pysetup_tunnelr3      s     ' 	$#! 
 #	y!2B???Hmmooa(G'.vGFO8L8LK!),KK 	 	 	B 		!"")//t/LLL&,, %$$$% % % % % % % % % % % % % % % 	 	 	,XXX 	 (8$$ $8#=#=c#B#B [+&&$ F !!##GNsU   AA+ +
B
5BB
AC? C3'C? 3C77C? :C7;C? ?
D!	DD!urlboolc                j   	 t          d          D ]x}t          j                    5  t          j        d           t	          j        | dd          }d d d            n# 1 swxY w Y   |j        dv r dS t          j        d           yn(# t          t          j
        t          j        f$ r Y dS w xY wdS )	N   ignore   F)r   verify)   i  i-  i.  i/  i3  i4  Tg      ?)rangewarningscatch_warningsfilterwarningsr   headstatus_codetimesleepConnectionErrorConnectErrorTimeoutException)r4   _rs      r2   url_okrI   F   s   q 	 	A(** = ='111JsAe<<<= = = = = = = = = = = = = = = !DDDttJu	 U/1GH   uu5s:   $B ,AB A"	"B %A"	&B 5B !B0/B0)r
   r   r   r   r   r   r   r   r   r   r   r   )r4   r   r   r5   )__doc__
__future__r   osrB   r=   pathlibr   r   gradio.exceptionsr   gradio.routesr   gradio.tunnelingr   r   r   getenvr	   r3   rI        r2   <module>rT      s    
 # " " " " " 				          8 8 8 8 8 8       5 5 5 5 5 5 5 5> 'bi(EFF , , , ,^     rS   