
    tni=                       d dl mZ d dl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dlmZ ddlmZ ddlmZ g d	Z d
j        ej         Zej                            dde de           Zej                            dde de           Z eej                            dd                    Z eej                            dd                    Z eej                            dd                    Zd-dZ ej        d          Z ej        d          Z ej!         G d d                      Z"ej!         G d d                      Z#d.d#Z$d/d%Z%d0d,Z&dS )1    )annotationsN)	Generator)Callable   )Headers)SecurityError)version)SERVER
USER_AGENTRequestResponsez{}.{}WEBSOCKETS_USER_AGENTzPython/z websockets/WEBSOCKETS_SERVERWEBSOCKETS_MAX_NUM_HEADERS128WEBSOCKETS_MAX_LINE_LENGTH8192WEBSOCKETS_MAX_BODY_SIZE	1_048_576valuebytes | bytearrayreturnstrc                .    |                      d          S )zG
    Decode a bytestring for interpolating into an error message.

    backslashreplaceerrors)decode)r   s    N/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/websockets/http11.pydr    2   s    
 <<1<222    s   [-!#$%&\'*+.^_`|~0-9a-zA-Z]+s   [\x09\x20-\x7e\x80-\xff]*c                  n    e Zd ZU dZded<   ded<   dZded<   edd
            Zedd            Z	ddZ
dS )r   z
    WebSocket handshake request.

    Attributes:
        path: Request path, including optional query.
        headers: Request headers.
    r   pathr   headersNException | None
_exceptionr   c                D    t          j        dt                     | j        S )NzIRequest.exception is deprecated; use ServerProtocol.handshake_exc insteadwarningswarnDeprecationWarningr&   selfs    r   	exceptionzRequest.exception^   s&    W	
 	
 	
 r!   	read_line9Callable[[int], Generator[None, None, bytes | bytearray]]Generator[None, None, Request]c              #    K   	 t          |          E d{V }n"# t          $ r}t          d          |d}~ww xY w	 |                    dd          \  }}}n.# t          $ r! t          dt	          |                     dw xY w|dk    rt          dt	          |                     |dk    rt          d	t	          |                     |                    d
d          }t          |          E d{V }d|v rt          d          d|v r(t          |d                   dk    rt          d           | ||          S )a  
        Parse a WebSocket handshake request.

        This is a generator-based coroutine.

        The request path isn't URL-decoded or validated in any way.

        The request path and headers are expected to contain only ASCII
        characters. Other characters are represented with surrogate escapes.

        :meth:`parse` doesn't attempt to read the request body because
        WebSocket handshake requests don't have one. If the request contains a
        body, it may be read from the data stream after :meth:`parse` returns.

        Args:
            read_line: Generator-based coroutine that reads a LF-terminated
                line or raises an exception if there isn't enough data

        Raises:
            EOFError: If the connection is closed without a full HTTP request.
            SecurityError: If the request exceeds a security limit.
            ValueError: If the request isn't well formatted.

        Nz1connection closed while reading HTTP request line       zinvalid HTTP request line:    HTTP/1.1)unsupported protocol; expected HTTP/1.1: s   GETz+unsupported HTTP method; expected GET; got asciisurrogateescapeTransfer-Encodingz!transfer codings aren't supportedContent-Lengthr   zunsupported request body)	
parse_lineEOFErrorsplit
ValueErrorr    r   parse_headersNotImplementedErrorint)	clsr/   request_lineexcmethodraw_pathprotocolr#   r$   s	            r   parsezRequest.parsef   s     F	Y&0&;&;;;;;;;LL 	Y 	Y 	YNOOUXX	Y	X)5););D!)D)D&FHhh 	X 	X 	XL1\??LLMMSWW	X{""MAlOOMM   VV1V99VVWWWw(9::*955555555 '))%&IJJJw&& 7+,--22 !;<<<s4!!!s    
949A +Bbytesc                x    d| j          d                                }|| j                                        z  }|S )z;
        Serialize a WebSocket handshake request.

        zGET z HTTP/1.1
)r#   encoder$   	serialize)r-   requests     r   rL   zRequest.serialize   s?     211188::4<))+++r!   r   r%   )r/   r0   r   r1   r   rI   )__name__
__module____qualname____doc____annotations__r&   propertyr.   classmethodrH   rL    r!   r   r   r   N   s           III $(J''''   X @" @" @" [@"D	 	 	 	 	 	r!   r   c                      e Zd ZU dZded<   ded<   ded<   dZd	ed
<   dZded<   edd            Ze		 ddd            Z
ddZdS )r   z
    WebSocket handshake response.

    Attributes:
        status_code: Response code.
        reason_phrase: Response reason.
        headers: Response headers.
        body: Response body.

    rA   status_coder   reason_phraser   r$   r!   r   bodyNr%   r&   r   c                D    t          j        dt                     | j        S )NzJResponse.exception is deprecated; use ClientProtocol.handshake_exc insteadr(   r,   s    r   r.   zResponse.exception   s(    7	
 	
 	

 r!   Fr/   r0   
read_exactread_to_eofproxyboolGenerator[None, None, Response]c              #    K   	 t          |          E d{V }n"# t          $ r}t          d          |d}~ww xY w	 |                    dd          \  }}}	n.# t          $ r! t          dt	          |                     dw xY w|r$|dvrt          dt	          |                     n%|dk    rt          d	t	          |                     	 t          |          }
n.# t          $ r! t          d
t	          |                     dw xY wd|
cxk    rdk     s!n t          dt	          |                     t                              |	          st          dt	          |	                     |	                    dd          }t          |          E d{V }|rd}nt          |
||||          E d{V } | |
|||          S )a  
        Parse a WebSocket handshake response.

        This is a generator-based coroutine.

        The reason phrase and headers are expected to contain only ASCII
        characters. Other characters are represented with surrogate escapes.

        Args:
            read_line: Generator-based coroutine that reads a LF-terminated
                line or raises an exception if there isn't enough data.
            read_exact: Generator-based coroutine that reads the requested
                bytes or raises an exception if there isn't enough data.
            read_to_eof: Generator-based coroutine that reads until the end
                of the stream.

        Raises:
            EOFError: If the connection is closed without a full HTTP response.
            SecurityError: If the response exceeds a security limit.
            LookupError: If the response isn't well formatted.
            ValueError: If the response isn't well formatted.

        Nz0connection closed while reading HTTP status liner3   r4   zinvalid HTTP status line: )r5   s   HTTP/1.0z5unsupported protocol; expected HTTP/1.1 or HTTP/1.0: r5   r6   z+invalid status code; expected integer; got d   iX  u-   invalid status code; expected 100–599; got zinvalid HTTP reason phrase: r7   r8   r!   )r;   r<   r=   r>   r    rA   	_value_re	fullmatchr   r?   	read_body)rB   r/   r]   r^   r_   status_linerD   rG   raw_status_code
raw_reasonrY   reasonr$   r[   s                 r   rH   zResponse.parse   s     B	X%/	%:%:::::::KK 	X 	X 	XMNNTWW	X	V4?4E4EdA4N4N1Hozz 	V 	V 	VJ!K..JJKKQUU	V 
	999 (~~( (   : ;&& P+PP  	o..KK 	 	 	Ra>P>PRR 	 k''''C''''T/@R@RTT   "":.. 	MKAjMMKKLLL""7,=>>*955555555  	DD'Wi[       D s;666s'    
949A +BC" "+DrI   c                    d| j          d| j         d                                }|| j                                        z  }|| j        z  }|S )z<
        Serialize a WebSocket handshake response.

        z	HTTP/1.1  z
)rY   rZ   rK   r$   rL   r[   )r-   responses     r   rL   zResponse.serialize!  sX     Kt/JJ$2DJJJQQSSDL**,,,DIr!   rN   )F)
r/   r0   r]   r0   r^   r0   r_   r`   r   ra   rO   )rP   rQ   rR   rS   rT   r[   r&   rU   r.   rV   rH   rL   rW   r!   r   r   r      s         	 	 !D!!!!#'J''''   X  L7 L7 L7 L7 [L7\
 
 
 
 
 
r!   r   r/   r0   (Generator[None, None, bytes | bytearray]c              #     K   	  | t                     E d{V }n# t          $ r t          d          w xY w|                    d          st	          d          |dd         S )ao  
    Parse a single line.

    CRLF is stripped from the return value.

    Args:
        read_line: Generator-based coroutine that reads a LF-terminated line
            or raises an exception if there isn't enough data.

    Raises:
        EOFError: If the connection is closed without a CRLF.
        SecurityError: If the response exceeds a security limit.

    Nzline too long   
zline without CRLF)MAX_LINE_LENGTHRuntimeErrorr   endswithr<   )r/   lines     r   r;   r;   .  s      "-#)O44444444 - - -O,,,- ==!! ,*+++9s    5Generator[None, None, Headers]c              #     K   t                      }t          t          dz             D ]E}	 t          |           E d{V }n"# t          $ r}t	          d          |d}~ww xY w|dk    r n	 |                    dd          \  }}n.# t          $ r! t          dt          |                     dw xY wt          	                    |          st          dt          |                     |
                    d          }t          	                    |          st          d	t          |                     |                    d
          }|                    d
d          }|||<   Gt          d          |S )a  
    Parse HTTP headers.

    Non-ASCII characters are represented with surrogate escapes.

    Args:
        read_line: Generator-based coroutine that reads a LF-terminated line
            or raises an exception if there isn't enough data.

    Raises:
        EOFError: If the connection is closed without complete headers.
        SecurityError: If the request exceeds a security limit.
        ValueError: If the request isn't well formatted.

    r   Nz,connection closed while reading HTTP headersr!      :zinvalid HTTP header line: zinvalid HTTP header name: s    	zinvalid HTTP header value: r7   r8   ztoo many HTTP headers)r   rangeMAX_NUM_HEADERSr;   r<   r=   r>   r    	_token_rere   striprd   r   r   )	r/   r$   _ru   rD   raw_name	raw_valuenamer   s	            r   r?   r?   I  s     , iiG?Q&'' 5 5	T(33333333DD 	T 	T 	TIJJPSS	T3;;E	O"&**T1"5"5Hii 	O 	O 	OC!D''CCDD$N	O""8,, 	IG!H++GGHHHOOF++	""9-- 	KI1Y<<IIJJJw''  *;<< 3444Ns#   A
A!AA!.B+B3rY   rA   r$   r   r]   r^   c              #  <  K   d| cxk    rdk     sn | dk    s| dk    rdS |                     d          x}.|dk    rt          d| d	          d}	 t          |          E d {V }|                    dd          d         }t	          |          dk    r)|                    d          }	t          d|	 d          t          |d          }
|
dk    rnwt	          |          |
z   t          k    r#t          d|
 dt	          |           d          | ||
          E d {V z  } |d          E d {V dk    rt          d          t          |          E d {V  |S |                     d          x}dt	          |          dk    rt          d| d          t          |          }|t          k    rt          d| d           ||          E d {V S 	  |t                    E d {V S # t          $ r t          dt           d          w xY w)Nrc         i0  r!   r9   chunkedztransfer coding z isn't supportedT   ;r   r      r   r   zchunk too large: 0xz bytes   zchunk too large: z bytes after r4   rp   zchunk without CRLFr:      zbody too large: zbody too large: over )getr@   r;   r=   lenr   r   rA   MAX_BODY_SIZEr>   r?   rs   )rY   r$   r/   r]   r^   codingr[   chunk_size_lineraw_chunk_sizestr_chunk_size
chunk_sizeraw_content_lengthcontent_lengths                r   rf   rf   |  s      kC;##5#59K9Ks KK 344
4&	AY%&Q&Q&Q&QRRR	7)3I)>)>>>>>>>O,224;;A>N>""R''!/!6!6>P!6!Q!Q#$P.$P$P$PQQQ^R00JQ4yy:%55#R
RRTRRR   zz*555555555D%:a==((((((W44 !5666!	7$ !+++++++++ ',< = =
=
	J!""R'' M3E M M MNNN/00M)) I> I I IJJJ%:n555555556	O*{=99999999: 	O 	O 	O M M M MNNN	Os   "G8 8#H)r   r   r   r   )r/   r0   r   rn   )r/   r0   r   rv   )rY   rA   r$   r   r/   r0   r]   r0   r^   r0   r   rn   )'
__future__r   dataclassesosresysr)   collections.abcr   typingr   datastructuresr   
exceptionsr   r	   websockets_version__all__formatversion_infoPYTHON_VERSIONenvironr   r   r
   rA   rz   rr   r   r    compiler{   rd   	dataclassr   r   r;   r?   rf   rW   r!   r   <module>r      s   " " " " " "     				 				 



  % % % % % %       # # # # # # % % % % % % 2 2 2 2 2 2    !12 Z^^>n>>*<>> 
 
>n>>*<>>
 
 #bjnn%A5IIJJ #bjnn%A6JJKK BJNN#={KKLL3 3 3 3 BJ788	 BJ455	 c c c c c c c cL u u u u u u u up   60 0 0 0f:O :O :O :O :O :Or!   