
    sj                         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mZ  G d d      Z	 G d de      Z
 G d d	e      Zd
 Zd Zy)    N)Path)AbstractWebAppWslinkHandlerc                   L    e Zd Zd Zd Zd Zd Zed        Zd Z	d Z
d Zd	 Zy
)WsConnectionc                     t        t        j                               j                  dd      | _        d | _        d | _        d| _        y )N- T)struuiduuid4replace_id_ws_on_message_fnclosedselfs    I/DATA/.local/lib/python3.12/site-packages/wslink/backends/generic/core.py__init__zWsConnection.__init__   s7    tzz|$,,S"5"    c                     || _         y Nr   )r   callbacks     r   
on_messagezWsConnection.on_message   s
    &r   c                 n   K   | j                   j                  ||| j                         d {    y 7 wr   )r   	onMessage	client_id)r   	is_binarymsgs      r   sendzWsConnection.send   s&     hh  C@@@s   +535c                 V   K   | j                  | j                         d {    y 7 wr   )on_closer   r   s    r   closezWsConnection.close   s     mmDHH%%%s   )')c                     | j                   S r   )r   r   s    r   r   zWsConnection.client_id"   s    xxr   c                    K   d| _         || _        | j                  j                  d| d| j                         d {    y 7 w)NFgeneric)type
connection)r   r   	onConnectr   r   wss     r   
on_connectzWsConnection.on_connect&   s>     hh  d3T^^
 	
 	
s   ;AAAc                    K   d| _         | j                  |k(  r+|j                  | j                         d {    d | _        y y 7 wNT)r   r   
disconnectr   r,   s     r   r$   zWsConnection.on_close-   s=     88r>--///DH /s   5AAAc                 D   K   | j                  d|       d {    y 7 w)NFr   r   values     r   send_strzWsConnection.send_str3   s     !!%///     c                 D   K   | j                  d|       d {    y 7 wr0   r   r3   s     r   
send_byteszWsConnection.send_bytes6   s     !!$...r6   N)__name__
__module____qualname__r   r   r"   r%   propertyr   r.   r$   r5   r8    r   r   r   r   
   s?    'A&  
0/r   r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )
WsEndpointc                 &    t         |   ||       y r   )superr   )r   protocolweb_app	__class__s      r   r   zWsEndpoint.__init__;   s    7+r   c                    K   t               }|| j                  |j                  <   |j                  |        d {    |S 7 wr   )r   connectionsr   r.   )r   conns     r   connectzWsEndpoint.connect>   s=     ~+/(ood### 	$s   8AAAc                    K   t        |t              r|n|j                  }|| j                  v r5| j                  j	                  |      }|j                  |       d {    y y 7 wr   )
isinstancer   r   rF   popr$   )r   client_or_idclients      r   r1   zWsEndpoint.disconnectD   s_     &|S9L|?U?U 	 4+++%%)),7F//,/// ,/s   AA'A%A'r   )r9   r:   r;   r   rH   r1   __classcell__)rD   s   @r   r?   r?   :   s    ,0r   r?   c                   @    e Zd Zd Zd Zd Zd Zed        Zd Z	d Z
y)	GenericServerc                     t        j                  | |       i | _        t        j                         | _        d|v r7|d   j                         D ]   \  }}t        ||       }|| j                  |<   " y y )Nr-   )r   r   _websocketsasyncioEvent_stop_eventitemsr?   )r   server_configrouteserver_protocolprotocol_handlers        r   r   zGenericServer.__init__N   sp    m4"==?= *7*=*C*C*E&#-ot#D *:  ' +F !r   c                    t        |      }|j                  dd       d| j                  v r| j                  d   }t        |j	                               D ]  }||   }|dk(  rxt        |      }|j                         D ]Y  }|j                         r$t        j                  |||j                  z         7t        j                  |||j                  z         [ t        j                  |||z          y y )NT)exist_okparentsstatic/)r   mkdir_configsortedkeysiterdiris_dirshutilcopytreenamecopy2)r   dest_directorydeststatic_routesrX   server_pathsrcchilds           r   write_static_contentz"GenericServer.write_static_contentX   s    N#

D$
/t||# LL2M 2 2 45+E2C<{+C!$ <<>"OOE4%**3DE"LLuzz0AB	 "/ OOK> 6 $r   c                 :    | j                   j                  |d       S r   rR   get)r   attrs     r   __getattr__zGenericServer.__getattr__i       ##D$//r   c                 :    | j                   j                  |d       S r   rr   )r   rh   s     r   __getitem__zGenericServer.__getitem__l   rv   r   c                 H    t        | j                  j                               S r   )listrR   rc   r   s    r   ws_endpointszGenericServer.ws_endpointso   s    D$$))+,,r   c                    K   | || j                                | j                  j                          | j                  j                          d {    y 7 wr   )get_portrU   clearwait)r   port_callbacks     r   startzGenericServer.starts   sD     $$--/* ##%%%s   AAAAc                 @   K   | j                   j                          y wr   )rU   setr   s    r   stopzGenericServer.stopz   s     s   N)r9   r:   r;   r   rp   ru   rx   r<   r{   r   r   r=   r   r   rP   rP   M   s4    ;?"00 - -&r   rP   c                      d}t        |      )Nz+Generic backend does not provide a launcher)NotImplementedError)argskwargsr!   s      r   startWebServerr   ~   s    
7C
c
""r   c                     | j                  d      r't        j                  d      j                  | d          d| v rd}t	        |      t        |       S )Nlogging_levelwslinkreverse_urlz,Generic backend does not support reverse_url)rs   logging	getLoggersetLevelr   rP   )rW   r!   s     r   create_webserverr      sS    )(#,,]?-KL %<!#&&''r   )rS   r   rf   r   pathlibr   wslink.protocolr   r   r   r?   rP   r   r   r=   r   r   <module>r      sE         9-/ -/`0 0&.N .b#
	(r   