
    )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             dS dS )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                    |                      ddd           |                      ddd           |                      dt          dd	
           |                      ddt          dd
           |                      dt          dd
           |                      ddd           |                      ddd           |                      dt          ddd           |                      dddd            |                      d!dd"d#$           |                      d%d&d'(           |                      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    G/DATA/AppData/hermes/venv/lib/python3.11/site-packages/wslink/server.pyadd_argumentsr   !   s	    :<     `    
 O	     J     [	     :    
 J    
 I     ;	     x	     G    
  Y     M    zwslink web-serverc                 &   t          j        |          }t          |           |                    |           }t	          j        t                    5  |                    |           ddd           n# 1 swxY w Y   t          ||           dS )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   s     $===F&T""D		^	,	, ! !4   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! D8444444s   A55A9<A9c                      t           r?t          j                    } |                     t                                                     S d S N)	ws_serverasyncioget_event_loopcreate_taskstop)loops    r   stop_webserverr1      s;     2%''	 0 01114r   c                  F    t           rt                                           S dS )N)r+   get_port r   r   r4   r4      s!     $!!###2r   aiohttpc                 .    t          j        | |          S )Nbackend)r   create_webserver)server_configr9   s     r   r:   r:      s    $]GDD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k    ri |d<   | j        |d         d<   t          | j                  dk    rRd|vri |d<   | j                            d	          D ].}	|	                    d
          }
|
d         |d         |
d         <   /t          | j                  dk    rddlm}m} | j        dk    r ||d                   | _        nE| j                            d          }t          |          dk    rd}t#          |          || _        | j        \  }}|                    |j                  }|                    ||           ||d<   | j         |d<   t-          ||          a	 t1          j                    n7# t4          $ r* t1          j                    t1          j                   Y nw xY wdt;          |d          r|j        t;          |d          r|                    t.                     fdfd}fd}||d}||vrd| }t#          |           ||                     S )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                  8    t                                          S r*   )r+   r(   )rN   s   r   create_coroutinez)start_webserver.<locals>.create_coroutine  s    }---r   c                      t          j        t                    5                                               d d d            d S # 1 swxY w Y   d S r*   )r!   r"   
SystemExitrun_until_completerQ   r0   s   r   	main_execz"start_webserver.<locals>.main_exec  s     ,, 	8 	8##$4$4$6$6777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   AA
A
c                  >                                                 S r*   )r.   rU   s   r   	task_execz"start_webserver.<locals>.task_exec  s!     0 0 2 23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   & 8::L &	 & 3G".'*
 
 LL*	
 
 | 	;"$M$.:M$
+ w!##&(M(#+2?M(#C( w"##a''},,*,h'")"5";";C"@"@ E E*0055	8A!h'	!55 w{a;;;;;;;;{g%%//f0EFF **3//v;;!##XC#C..($ID#nnS%<==G##D#...#*M% .5.F*F&' !@@@I%%'' % % %%''t$$$$$% M|_-- 3$2|\** +	***. . . . .8 8 8 8 8 84 4 4 4 4 4 % J 
""/I//nn :i """s   3H 1H;:H;__main__)r6   )__doc__r   r,   r!   r\   wslinkr   r   wslr+   r   ServerProtocolr(   r1   r4   r:   r%   __name__r5   r   r   <module>r~      s                 # # # # # #	K K Kf c0>Q 5 5 5 5&    ,E E E E {# {# {# {#| z	EGGGGG r   