
    vg[4                       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%dS ))    )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returnstrc                .    |                      d          S )zG
    Decode a bytestring for interpolating into an error message.

    backslashreplace)errors)decode)r   s    N/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/websockets/http11.pydr   -   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.exceptionY   (    7	
 	
 	

 r    	read_line-Callable[[int], Generator[None, None, bytes]]Generator[None, None, Request]c              #  Z  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           | ||          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-Encoding!transfer codings aren't supportedContent-Lengthzunsupported request body)
parse_lineEOFErrorsplit
ValueErrorr   r   parse_headersNotImplementedError)	clsr/   request_lineexcmethodraw_pathprotocolr"   r#   s	            r   parsezRequest.parseb   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888s4!!!s    
949A +Br   c                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   rK   zRequest.serialize   s?     211188::4<))+++r    r   r$   )r/   r0   r   r1   r   r   )__name__
__module____qualname____doc____annotations__r%   propertyr-   classmethodrH   rK    r    r   r   r   I   s           III $(J''''   X =" =" =" [="~	 	 	 	 	 	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            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, if any.

    intstatus_coder   reason_phraser   r#   Nzbytes | Nonebodyr$   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   r.   r    r/   r0   
read_exactread_to_eof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|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 }d|v rt          d          d	|	cxk    rdk     sn |	dk    s|	dk    rd}n	 |d         }t          |          }n# t          $ r d}Y nw xY w|>	  |t                    E d{V }nU# t          $ r t          dt           d          w xY w|t          k    rt          d| d           ||          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   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   r9   r:         i0  r;   zbody too large: over z byteszbody too large: )r<   r=   r>   r?   r   rX   	_value_re	fullmatchr   r@   rA   KeyErrorMAX_BODY_SIZERuntimeErrorr   )rB   r/   r]   r^   status_linerD   rG   raw_status_code
raw_reasonrY   reasonr#   r[   raw_content_lengthcontent_lengths                  r   rH   zResponse.parse   se     @	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{""LAkNNLL  	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 '))%&IJJJ +########{c'9'9[C=O=ODD9 &--=%>" "%%7!8!8  & & &!%&
 %W&1k-&@&@@@@@@@DD# W W W'(U(U(U(UVVVW-//#$M~$M$M$MNNN",*^"<"<<<<<<<s;666sE    
949A +B,B< <+C'.G GGG2 2#Hr   c                    d| j          d| j         d                                }|| j                                        z  }| j        
|| j        z  }|S )z<
        Serialize a WebSocket handshake response.

        z	HTTP/1.1  z
)rY   rZ   rJ   r#   rK   r[   )r,   responses     r   rK   zResponse.serialize)  s`     Kt/JJ$2DJJJQQSSDL**,,,9 	!Hr    rM   )r/   r0   r]   r0   r^   r0   r   r_   rN   )rO   rP   rQ   rR   rS   r[   r%   rT   r-   rU   rH   rK   rV   r    r   r   r      s         	 	 D#'J''''   X [7 [7 [7 [[7z     r    r   r/   r0   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#   _linerD   raw_name	raw_valuenamer   s	            r   r@   r@   7  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Generator[None, None, bytes]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 longs   
zline without CRLF)MAX_LINE_LENGTHrh   r   endswithr=   )r/   rz   s     r   r<   r<   j  s      "-#)O44444444 - - -O,,,- ==!! ,*+++9s    5)r   r   r   r   )r/   r0   r   rr   )r/   r0   r   r~   )&
__future__r   dataclassesosresysr(   collections.abcr   typingr   datastructuresr   
exceptionsr   r	   websockets_version__all__formatversion_infoPYTHON_VERSIONenvirongetr   r
   rX   rv   r   rg   r   compilerw   rd   	dataclassr   r   r@   r<   rV   r    r   <module>r      st   " " " " " "     				 				 



  % % % % % %       # # # # # # % % % % % % 2 2 2 2 2 2 :
9
9  !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	 a a a a a a a aH E E E E E E E EP0 0 0 0f     r    