
    ,h                    @   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                  j                  dd	            Z e
ej                  j                  d
d            ZddZ ej                   d      Z ej                   d      ZddZddZddZddZy)    )annotationsN   )Headers)SecurityErrorread_requestread_responseWEBSOCKETS_MAX_NUM_HEADERS128WEBSOCKETS_MAX_LINE_LENGTH8192c                &    | j                  d      S )zG
    Decode a bytestring for interpolating into an error message.

    backslashreplace)errors)decode)values    X/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/websockets/legacy/http.pydr      s    
 <<1<22    s   [-!#$%&\'*+.^_`|~0-9a-zA-Z]+s   [\x09\x20-\x7e\x80-\xff]*c                  K   	 t        |        d{   }	 |j                  dd      \  }}}|dk7  rt        dt	        |             |dk7  rt        d	t	        |             |j                  d
d      }t        |        d{   }||fS 7 |# t        $ r}t        d      |d}~ww xY w# t        $ r t        dt	        |             dw xY w7 Lw)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)streamrequest_lineexcmethodraw_pathversionpathheaderss           r   r   r   -   s     8U&v..T$0$6$6tQ$?!' 4QvYK@AA+5aj\BCC??7$56D ((G=# / UJKQTTU
  T6q6GHItST )sU   CB BB B. ACCCB 	B+B&&B++C."CCc                v  K   	 t        |        d{   }	 |j                  dd      \  }}}|dk7  rt        dt	        |             	 t        |      }d	|cxk  rd
k  sn t        dt	        |             t        j                  |      st        dt	        |             |j                         }t        |        d{   }|||fS 7 # t        $ r}t        d      |d}~ww xY w# t        $ r t        dt	        |             dw xY w# t        $ r t        dt	        |             dw xY w7 rw)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'   s	            r   r   r   ^   sc    2T%f--R/:/@/@q/I,* +5aj\BCCV/* +$$9!O:L9MNOOz*7*GHH F ((G''/ . TIJPSST
  R5an5EFGTQR  V5a6H5IJKQUUV )sm   D9C CC C- D9D A.D9D7	D9C 	C*C%%C**D9-"DD9"D44D9c                p  K   t               }t        t        dz         D ]  }	 t        |        d{   }|dk(  r |S 	 |j                  dd      \  }}t        j                  |      st        dt        |             |j                  d      }t        j                  |      st        d	t        |             |j                  d
      }|j                  d
d      }|||<    t        d      7 # t        $ r}t	        d      |d}~ww xY w# t        $ r t        dt        |             dw xY ww)zo
    Read HTTP headers from ``stream``.

    Non-ASCII characters are represented with surrogate escapes.

       Nz,connection closed while reading HTTP headersr      :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   s	            r   r   r      sK     iG?Q&' 5	T"6**D 3;& N#	O"&**T1"5Hi ""8,9!H+GHHOOF+	""9-:1Y<.IJJw'  *;<)5. 344+ + 	TIJPSS	T  	O9!D'CD$N	OsO    D6C4C2C4D6DBD62C44	D=D		DD6"D33D6c                   K   | j                          d{   }t        |      t        kD  rt        d      |j	                  d      st        d      |dd S 7 Bw)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:   s     r   r   r      sW      ""D
4y?"O,,==!*++9 #s   AAAA)r   bytesreturnstr)r    asyncio.StreamReaderrE   ztuple[str, Headers])r    rG   rE   ztuple[int, str, Headers])r    rG   rE   r   )r    rG   rE   rD   )
__future__r   asyncioosredatastructuresr   
exceptionsr   __all__r*   environgetr6   rB   r   compiler7   r+   r   r   r   r    r   r   <module>rS      s    "  	 	 $ & ?
+bjjnn%A5IJbjjnn%A6JK3 BJJ78	 BJJ45	.b1(h%Pr   