o
    <ºi•  ã                   @  s²   d dl m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gZ	e
ej dd	¡ƒZe
ej d
d¡ƒZddd„Ze d¡Ze d¡Zd dd„Zd!dd„Zd"dd„Zd#dd„ZdS )$é    )ÚannotationsNé   )ÚHeaders)ÚSecurityErrorÚread_requestÚread_responseÚWEBSOCKETS_MAX_NUM_HEADERSÚ128ÚWEBSOCKETS_MAX_LINE_LENGTHÚ8192ÚvalueÚbytesÚreturnÚstrc                 C  s   | j ddS )zG
    Decode a bytestring for interpolating into an error message.

    Úbackslashreplace)Úerrors)Údecode)r   © r   úS/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/websockets/legacy/http.pyÚd   s   r   s   [-!#$%&\'*+.^_`|~0-9a-zA-Z]+s   [\x09\x20-\x7e\x80-\xff]*Ústreamúasyncio.StreamReaderútuple[str, Headers]c              
   Ã  sÈ   z	t | ƒI dH }W n ty } ztdƒ|‚d}~ww z| dd¡\}}}W n ty8   tdt|ƒ› ƒd‚w |dkrFtdt|ƒ› ƒ‚|dkrStd	t|ƒ› ƒ‚| d
d¡}t| ƒI dH }||fS )aó  
    Read an HTTP/1.1 GET request and return ``(path, headers)``.

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

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

    :func:`read_request` 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 ``stream`` after this coroutine returns.

    Args:
        stream: Input to read the request from.

    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ó    r   zinvalid HTTP request line: s   GETzunsupported HTTP method: ó   HTTP/1.1úunsupported HTTP version: ÚasciiÚsurrogateescape)Ú	read_lineÚEOFErrorÚsplitÚ
ValueErrorr   r   Úread_headers)r   Úrequest_lineÚexcÚmethodÚraw_pathÚversionÚpathÚheadersr   r   r   r   -   s&   €
€ÿÿútuple[int, str, Headers]c           	   
   Ã  s   z	t | ƒI dH }W n ty } ztdƒ|‚d}~ww z| dd¡\}}}W n ty8   tdt|ƒ› ƒd‚w |dkrFtdt|ƒ› ƒ‚zt|ƒ}W n ty]   tdt|ƒ› ƒd‚w d	|  krhd
k srn tdt|ƒ› ƒ‚t |¡s€tdt|ƒ› ƒ‚| ¡ }t	| ƒI dH }|||fS )aÏ  
    Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.

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

    :func:`read_request` doesn't attempt to read the response body because
    WebSocket handshake responses don't have one. If the response contains a
    body, it may be read from ``stream`` after this coroutine returns.

    Args:
        stream: Input to read the response from.

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

    Nz0connection closed while reading HTTP status liner   r   zinvalid HTTP status line: r   r   zinvalid HTTP status code: éd   iè  zunsupported HTTP status code: zinvalid HTTP reason phrase: )
r   r   r    r!   r   ÚintÚ	_value_reÚ	fullmatchr   r"   )	r   Ústatus_liner$   r'   Úraw_status_codeÚ
raw_reasonÚstatus_codeÚreasonr)   r   r   r   r   ^   s4   €
€ÿÿÿ

r   c           	      Ã  sþ   t ƒ }ttd ƒD ]p}z	t| ƒI dH }W n ty& } ztdƒ|‚d}~ww |dkr. |S z
| dd¡\}}W n tyI   tdt|ƒ› ƒd‚w t 	|¡sXtdt|ƒ› ƒ‚| 
d¡}t 	|¡sktd	t|ƒ› ƒ‚| d
¡}| d
d¡}|||< q
tdƒ‚)zo
    Read HTTP headers from ``stream``.

    Non-ASCII characters are represented with surrogate escapes.

    é   Nz,connection closed while reading HTTP headersó    ó   :zinvalid HTTP header line: zinvalid HTTP header name: s    	zinvalid HTTP header value: r   r   ztoo many HTTP headers)r   ÚrangeÚMAX_NUM_HEADERSr   r   r    r!   r   Ú	_token_rer.   Ústripr-   r   r   )	r   r)   Ú_Úliner$   Úraw_nameÚ	raw_valueÚnamer   r   r   r   r"   ’   s4   €
€ÿïÿ




r"   c                 Ã  sB   |   ¡ I dH }t|ƒtkrtdƒ‚| d¡stdƒ‚|dd… S )z[
    Read a single line from ``stream``.

    CRLF is stripped from the return value.

    Nzline too longs   
zline without CRLFéþÿÿÿ)ÚreadlineÚlenÚMAX_LINE_LENGTHr   Úendswithr   )r   r<   r   r   r   r   º   s   €
r   )r   r   r   r   )r   r   r   r   )r   r   r   r*   )r   r   r   r   )r   r   r   r   )Ú
__future__r   ÚasyncioÚosÚreÚdatastructuresr   Ú
exceptionsr   Ú__all__r,   ÚenvironÚgetr8   rC   r   Úcompiler9   r-   r   r   r"   r   r   r   r   r   Ú<module>   s     




1
4(