a
    ñ»j^  ã                   @  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œ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é   )ÚHeaders)ÚSecurityErrorÚread_requestÚread_responseZWEBSOCKETS_MAX_NUM_HEADERSZ128ZWEBSOCKETS_MAX_LINE_LENGTHZ8192Ú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   ú<E:\soccer\ml_env\Lib\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rštdt|ƒ› �ƒ‚|dkr´t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rštdt|ƒ› �ƒ‚zt|ƒ}W n& tyÌ   tdt|ƒ› �ƒd‚Y n0 d	|  krâd
k sön 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   Z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 	|¡s¾tdt|ƒ› �ƒ‚| 
d¡}t 	|¡sät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_NUM_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_LINE_LENGTHr   Úendswithr   )r   r1   r   r   r   r   º   s    
r   )Ú
__future__r   ZasyncioÚosÚreZdatastructuresr   Ú
exceptionsr   Ú__all__r$   ÚenvironÚgetr-   r7   r   Úcompiler.   r%   r   r   r   r   r   r   r   r   Ú<module>   s   

14(