
    sj%                         d 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a	d Z
dej                  dfdZd Zd	 ZddZej                  dd
dfdZedk(  r e        yy)a  server is a module that enables using python through a web-server.

This module can be used as the entry point to the application. In that case, it
sets up a web-server.
web-pages are determines by the command line arguments passed in.
Use "--help" to list the supported arguments.

    N)backends)	websocketc                 "   | j                  ddd       | j                  ddd       | j                  dt        dd	
       | j                  ddt        dd
       | j                  dt        dd
       | j                  ddd       | j                  ddd       | j                  dt        ddd       | j                  dddd        | j                  d!dd"d#$       | j                  d%d&d'(       | j                  d)t        dd*d+       | S ),zb
    Add arguments known to this module. parser must be
    argparse.ArgumentParser instance.
    z--debugz log debugging messages to stdout
store_true)helpactionz--nosignalhandlerszQPrevent installation of signal handlers so server can be started inside a thread.z--host	localhostz@the interface for the web-server to listen on (default: 0.0.0.0))typedefaultr   z-pz--porti  z;port number for the web-server to listen on (default: 8080)z	--timeouti,  zLtimeout for reaping process on idle in seconds (default: 300s, 0 to disable)z	--content z+root for web-pages to serve (default: none))r   r   z	--authKeyzwslink-secretz;Authentication key for clients to connect to the WebSocket.z--ws-endpointwsz:Specify WebSocket endpoint. (e.g. foo/bar/ws, Default: ws))r
   r   destr   z--no-ws-endpointnowsz,If provided, disables the websocket endpoint)r   r   r   z--fs-endpointsfsEndpointsziadd another fs location to a specific endpoint (i.e: data=/Users/seb/Download|images=/Users/seb/Pictures))r   r   r   z--reverse-urlreverse_urlz8Make the server act as a client to connect to a ws relay)r   r   z--sslsslzadd a tuple file [certificate, key] (i.e: --ssl 'certificate,key') or adhoc string to generate temporary certificate (i.e: --ssl 'adhoc'))add_argumentstrint)parsers    :/DATA/.local/lib/python3.12/site-packages/wslink/server.pyadd_argumentsr   !   s    :<   `  
 O	   J   [	   :  
 J  
 I   ;	   x	   G  
  Y   M    zwslink web-serverc                     t        j                  |      }t        |       |j                  |       }t	        j
                  t              5  |j                  |       ddd       t        ||       y# 1 sw Y   xY w)z
    Sets up the web-server using with __name__ == '__main__'. This can also be
    called directly. Pass the optional protocol to override the protocol used.
    Default is ServerProtocol.
    )descriptionN)optionsprotocol)	argparseArgumentParserr   
parse_args
contextlibsuppressAttributeError	configurestart_webserver)argvr   r   r   argss        r   startr(   t   sb     $$=F&T"D			^	,4  
- D84 
-	,s   A44A=c                  ~    t         r7t        j                         } | j                  t         j	                               S y N)	ws_serverasyncioget_event_loopcreate_taskstop)loops    r   stop_webserverr1      s.    %%'	 011r   c                  8    t         rt         j                         S y)N)r+   get_port r   r   r4   r4      s    !!##r   aiohttpc                 0    t        j                  | |      S )Nbackend)r   create_webserver)server_configr9   s     r   r:   r:      s    $$]GDDr   Fmainc                     |       }|rd}n-| j                   rt        j                  }nt        j                  }| j                  r| j                  ||d}n| j
                  | j                  | j                  |d}| j                  si |d<   ||d   | j                  <   t        | j                        dkD  ri |d<   | j                  |d   d<   t        | j                        dkD  rHd|vri |d<   | j                  j                  d	      D ]!  }	|	j                  d
      }
|
d   |d   |
d   <   # t        | j                        dkD  rddlm}m} | j                  dk(  r ||d         | _        n=| j                  j                  d      }t        |      dk7  rd}t#        |      || _        | j                  \  }}|j%                  |j&                        }|j)                  ||       ||d<   | j*                   |d<   t-        ||      a	 t1        j2                         dt;        |d      r|j<                  t;        |d      r|j?                  t.               fdfd}fd}||d}||vrd| }t#        |       ||          S # t4        $ r, t1        j6                         t1        j8                         Y w xY w)az  
    Starts the web-server with the given protocol. Options must be an object
    with the following members:
        options.host : the interface for the web-server to listen on
        options.port : port number for the web-server to listen on
        options.timeout : timeout for reaping process on idle in seconds
        options.content : root for web-pages to serve.
    N)r   ws_protocollogging_level)hostporttimeoutr?   r   r   static/   |=   )generate_ssl_pairr   adhocr@   ,   z<ssl configure must be "adhoc" or a tuple of files "cert,key"r   handle_signalsr8   port_callback
set_serverc                  .    t         j                         S r*   )r+   r(   )rN   s   r   create_coroutinez)start_webserver.<locals>.create_coroutine  s    }--r   c                      t        j                  t              5  j                                  d d d        y # 1 sw Y   y xY wr*   )r!   r"   
SystemExitrun_until_completerQ   r0   s   r   	main_execz"start_webserver.<locals>.main_exec  s/      ,##$4$67 -,,s	   ;Ac                  0    j                                 S r*   )r.   rU   s   r   	task_execz"start_webserver.<locals>.task_exec  s     0 233r   )r<   task	coroutinezUnknown exec_mode: ) debugloggingDEBUGERRORr   r@   rA   rB   r   r   lencontentr   splitr   ssl_contextrI   	Exception
SSLContextPROTOCOL_TLS_SERVERload_cert_chainnosignalhandlersr:   r+   r,   r-   RuntimeErrornew_event_loopset_event_loophasattrrN   rO   )r   r   disableLoggingr9   	exec_mode_wslinkServerr?   r;   fsResourceInfo	infoSplitrI   r   tokensmsgcertkeycontextrV   rX   
exec_modesrQ   r0   rN   s                        @@@r   r%   r%      s   & :L	"..'*
 LLLL*	
 ||"$M$.:M$

+ w!#&(M(#+2??M(#C( w""#a'},*,h'")"5"5";";C"@*005	8A!h'	!5 #A
 w{{a;{{g%/f0EF **3/v;!#XC#C.($ID#nnS%<%<=G##D#.#*M% .5.F.F*F&' !@I%%%'
 M|_-$22|\*	*.84 %J 
"#I;/n :i ""C  %%%'t$%s   J 2KK__main__)r6   )__doc__r   r,   r!   r\   wslinkr   r   wslr+   r   ServerProtocolr(   r1   r4   r:   r%   __name__r5   r   r   <module>r~      s~         #	Kf c00>Q 5&,E {#| z	G r   