
    wg\jN                         S r SSKrSSKJrJr  SSKJrJrJr   " S S\5      r	 " S S5      r
 " S	 S
\
\5      r " S S\5      rg)z
Python WebSocket server base
Copyright 2011 Joel Martin
Copyright 2016-2018 Pierre Ossman
Licensed under LGPL version 3 (see docs/LICENSE.LGPL-3)
    N)BaseHTTPRequestHandler
HTTPServer)	WebSocketWebSocketWantReadErrorWebSocketWantWriteErrorc                   B   ^  \ rS rSrSrU 4S jrSS jrS rS rSr	U =r
$ )	HttpWebSocket   z?Class to glue websocket and http request functionality togetherc                 .   > [         TU ]  5         Xl        g N)super__init__request_handler)selfr   	__class__s     U/home/edenadmin/noVNC/venv/lib/python3.13/site-packages/websockify/websocketserver.pyr   HttpWebSocket.__init__   s    .    c                 :    U R                   R                  X5        g r   )r   send_response)r   codemessages      r   r   HttpWebSocket.send_response   s    **49r   c                 :    U R                   R                  X5        g r   )r   send_header)r   keywordvalues      r   r   HttpWebSocket.send_header   s    ((8r   c                 8    U R                   R                  5         g r   )r   end_headersr   s    r   r    HttpWebSocket.end_headers   s    ((*r   )r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r    __static_attributes____classcell__r   s   @r   r	   r	      s    I/
:9+ +r   r	   c                   B   ^  \ rS rSrSr\rU 4S jrS rS r	S r
SrU =r$ )WebSocketRequestHandlerMixIn    a  WebSocket request handler mix-in class

This class modifies and existing request handler to handle
WebSocket requests. The request handler will continue to function
as before, except that WebSocket requests are intercepted and the
methods handle_upgrade() and handle_websocket() are called. The
standard do_GET() will be called for normal requests.

The class instance SocketClass can be overridden with the class to
use for the WebSocket connection.
c                    > U R                   U l        U R                  U l          [        TU ]  5         U R                  U l         g! U R                  U l         f = f)zExtended request handler

This is where WebSocketRequestHandler redirects requests to the
new methods. Any sub-classes must call this method in order for
the calls to function.
N)do_GET_real_do_GET_websocket_do_GETr   handle_one_request)r   r   s    r   r2   /WebSocketRequestHandlerMixIn.handle_one_request/   sI     !KK,,	,G&(++DK$++DKs   A Ac                    U R                   U l        U R                  R                  S5      (       a>  U R                  R                  S5      R	                  5       S:X  a  U R                  5         g U R                  5         g )Nupgrade	websocket)r0   r/   headersgetlowerhandle_upgrader!   s    r   r1   .WebSocketRequestHandlerMixIn._websocket_do_GET=   sY    ''LLY''LLY'--/;>!KKMr   c                 4   U R                  U 5      n UR                  U R                  U R                  5        Xl        SU l	        U R                  5         g! [         a6    [
        R                  " 5       S   nU R                  S[        U5      5         gf = f)a	  Initial handler for a WebSocket request

This method is called when a WebSocket is requested. By default
it will create a WebSocket object and perform the negotiation.
The WebSocket object will then replace the request object and
handle_websocket() will be called.
   i  NT)SocketClassacceptrequestr7   	Exceptionsysexc_info
send_errorstrclose_connectionhandle_websocket)r   r6   excs      r   r:   +WebSocketRequestHandlerMixIn.handle_upgradeG   s     $$T*		T\\4<<8 ! !%  	,,.#COOCS*	s   &A =BBc                     g)zHandle a WebSocket connection.

This is called when the WebSocket is ready to be used. A
sub-class should perform the necessary communication here and
return once done.
N r!   s    r   rG   -WebSocketRequestHandlerMixIn.handle_websocket^   s     	r   )r0   rF   r/   r@   )r#   r$   r%   r&   r'   r	   r>   r2   r1   r:   rG   r(   r)   r*   s   @r   r,   r,       s(    
  K, . r   r,   c                       \ rS rSrSrg)WebSocketRequestHandleri   rK   Nr#   r$   r%   r&   r(   rK   r   r   rN   rN   i   s    r   rN   c                       \ rS rSrSrg)WebSocketServerm   rK   NrP   rK   r   r   rR   rR   m   s    r   rR   )r'   rB   http.serverr   r   websockify.websocketr   r   r   r	   r,   rN   rR   rK   r   r   <module>rV      sM     : [ [+I +"E ER	:4		j 	r   