a
    یxd                     @  s   d dl m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gZ
d	Zd
ZdddddZedZedZdddddZdddddZdddddZdddddZdS )    )annotationsN)Tuple   )Headers)SecurityErrorread_requestread_response   i    bytesstr)valuereturnc                 C  s   | j ddS )zG
    Decode a bytestring for interpolating into an error message.

    backslashreplace)errors)decode)r    r   N/var/www/html/Ranjet/env/lib/python3.9/site-packages/websockets/legacy/http.pyd   s    r   s   [-!#$%&\'*+.^_`|~0-9a-zA-Z]+s   [\x09\x20-\x7e\x80-\xff]*zasyncio.StreamReaderzTuple[str, Headers])streamr   c              
     s   zt | I dH }W n. ty@ } ztd|W Y d}~n
d}~0 0 z|dd\}}}W n& ty~   tdt| dY n0 |dkrtdt| |dkrt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   Zrequest_lineexcmethodraw_pathversionpathheadersr   r   r   r   -   s     zTuple[int, str, Headers]c           	   
     s4  zt | I dH }W n. ty@ } ztd|W Y d}~n
d}~0 0 z|dd\}}}W n& ty~   tdt| dY n0 |dkrtdt| zt|}W n& ty   tdt| dY n0 d	|  krd
k sn 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"   Zraw_status_codeZ
raw_reasonstatus_codereasonr$   r   r   r   r   ^   s*     r   c           	        s  t  }ttd D ]}zt| I dH }W n. tyV } ztd|W Y d}~n
d}~0 0 |dkrf qz|dd\}}W n& ty   tdt| dY n0 t	|stdt| |
d}t	|std	t| |d
}|d
d}|||< qtd|S )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_HEADERSr   r   r   r   r   	_token_rer(   stripr'   r   r   )	r   r$   _liner   raw_nameZ	raw_valuenamer   r   r   r   r      s,     




r   c                   s@   |   I dH }t|tkr"td|ds4t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_LINEr   endswithr   )r   r4   r   r   r   r      s    
r   )
__future__r   asyncioretypingr   Zdatastructuresr   
exceptionsr   __all__r0   r:   r   compiler1   r'   r   r   r   r   r   r   r   r   <module>   s   

14(