
    ,hM:                       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*                  j-                  dde de       Zej*                  j-                  dde de       Z eej*                  j-                  dd            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 ejB                   G d d             Z"ejB                   G d d             Z#	 	 	 	 d dZ$	 	 	 	 d!dZ%	 	 	 	 	 	 	 	 	 	 	 	 d"dZ&y)#    )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_576c                &    | j                  d      S )zG
    Decode a bytestring for interpolating into an error message.

    backslashreplaceerrors)decode)values    S/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/websockets/http11.pydr   2   s    
 <<1<22    s   [-!#$%&\'*+.^_`|~0-9a-zA-Z]+s   [\x09\x20-\x7e\x80-\xff]*c                  h    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
y)r   z
    WebSocket handshake request.

    Attributes:
        path: Request path, including optional query.
        headers: Request headers.
    strpathr   headersNException | None
_exceptionc                N    t        j                  dt               | j                  S )NzIRequest.exception is deprecated; use ServerProtocol.handshake_exc insteadwarningswarnDeprecationWarningr$   selfs    r   	exceptionzRequest.exception^   s     W	
 r   c              #    K   	 t        |      E d{   }	 |j                  dd      \  }}}|dk7  rt        dt	        |             |dk7  rt        d	t	        |             |j                  d
d      }t        |      E d{   }d|v rt        d      d|v rt        d       | ||      S 7 # t        $ r}t        d      |d}~ww xY w# t        $ r t        dt	        |             dw xY w7 ow)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-Encodingz!transfer codings aren't supportedContent-Lengthzunsupported request body)
parse_lineEOFErrorsplit
ValueErrorr   r   parse_headersNotImplementedError)	cls	read_linerequest_lineexcmethodraw_pathprotocolr!   r"   s	            r   parsezRequest.parsef   s-    F	Y&0&;;L	X)5););D!)D&FHh {";AlO;LM  VJ1V9+VWWw(9:*955 ')%&IJJw&7884!!5 < 	YNOUXX	Y
  	X:1\?:KLMSWW	X 6sU   C8B4 B2B4 C AC8C6+C82B4 4	C=C		CC8"C33C8c                |    d| j                    dj                         }|| j                  j                         z  }|S )z;
        Serialize a WebSocket handshake request.

        zGET z HTTP/1.1
)r!   encoder"   	serialize)r+   requests     r   rF   zRequest.serialize   s;     =188:4<<))++r   returnr#   )r=   -Callable[[int], Generator[None, None, bytes]]rI   zGenerator[None, None, Request]rI   bytes)__name__
__module____qualname____doc____annotations__r$   propertyr,   classmethodrC   rF    r   r   r   r   N   s_     I $(J '  ="@=" 
(=" ="~	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d       Z
ddZy)r   z
    WebSocket handshake response.

    Attributes:
        status_code: Response code.
        reason_phrase: Response reason.
        headers: Response headers.
        body: Response body.

    intstatus_coder    reason_phraser   r"   r   rL   bodyNr#   r$   c                N    t        j                  dt               | j                  S )NzJResponse.exception is deprecated; use ClientProtocol.handshake_exc insteadr&   r*   s    r   r,   zResponse.exception   s"    7	

 r   c              #    K   	 t        |      E 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                  dd      }t        |      E d{   }|rt        |
||||      E d{   }nd} | |
|||      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 7 }w)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 liner.   r/   zinvalid HTTP status line: r0   r1   z+invalid status code; expected integer; got d   iX  u-   invalid status code; expected 100–599; got zinvalid HTTP reason phrase: r2   r3   r   )r6   r7   r8   r9   r   rV   	_value_re	fullmatchr   r:   	read_body)r<   r=   
read_exactread_to_eofinclude_bodystatus_liner?   rB   raw_status_code
raw_reasonrW   reasonr"   rY   s                 r   rC   zResponse.parse   s    B	X%/	%::K	V4?4E4EdA4N1Hoz {";AkN;KL 	o.K
 k'C'?/@R?ST  "":.;AjM?KLL""7,=>*955'Wi[ D D;66G ; 	XMNTWW	X
  	V9!K.9IJKQUU	V  	=a>P=QR	 6s   EC4 C2C4 D ED6 A0EEEE E2C4 4	D=D		DE"D33E6"EEEc                    d| j                    d| j                   dj                         }|| j                  j	                         z  }|| j
                  z  }|S )z<
        Serialize a WebSocket handshake response.

        z	HTTP/1.1  z
)rW   rX   rE   r"   rF   rY   )r+   responses     r   rF   zResponse.serialize  sY     t//0$2D2D1ETJQQSDLL**,,DIIr   rH   )T)
r=   rJ   r`   rJ   ra   rJ   rb   boolrI   zGenerator[None, None, Response]rK   )rM   rN   rO   rP   rQ   rY   r$   rR   r,   rS   rC   rF   rT   r   r   r   r      s    	 D%#'J '   "D7@D7 BD7 C	D7
 D7 
)D7 D7L
r   r   c              #     K   	  | t               E d{   }|j                  d      st	        d      |dd S 7 %# t        $ r t        d      w xY ww)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 long   
zline without CRLF)MAX_LINE_LENGTHRuntimeErrorr   endswithr7   )r=   lines     r   r6   r6   #  s\     "-#O44 ==!*++9 5 -O,,-s%   A; 9; !A; AAc              #  p  K   t               }t        t        dz         D ]  }	 t        |       E 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)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: r2   r3   ztoo many HTTP headers)r   rangeMAX_NUM_HEADERSr6   r7   r8   r9   r   	_token_rer^   stripr]   r   r   )	r=   r"   _rq   r?   raw_name	raw_valuenamer   s	            r   r:   r:   >  sK    , iG?Q&' 5	T(33D 3;& N#	O"&**T1"5Hi ""8,9!H+GHHOOF+	""9-:1Y<.IJJw'  *;<)5. 34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   d| cxk  rdk  sn | dk(  s| dk(  ry|j                  d      x}|dk7  rt        d| d	      d}	 t        |      E d {   }|j                  d
d      d   }t	        |      dkD  r!|j                  d      }	t        d|	 d      t        |d      }
|
dk(  rnbt	        |      |
z   t        kD  rt        d|
 dt	        |       d      | ||
      E d {   z  } |d      E d {   dk7  rt        d      t        |      E d {    |S |j                  d      x}Pt	        |      dkD  rt        d| d      t        |      }|t        kD  rt        d| d       ||      E d {   S 	  |t              E d {   S 7 J7 7 7 7 "7 # t        $ r t        dt         d      w xY ww)Nr\         i0  r   r4   chunkedztransfer coding z isn't supported   ;r   r      r   r   zchunk too large: 0xz bytes   zchunk too large: z bytes after r/   rl   zchunk without CRLFr5      zbody too large: zbody too large: over )getr;   r6   r8   lenr   r   rV   MAX_BODY_SIZEr9   r:   ro   )rW   r"   r=   r`   ra   codingrY   chunk_size_lineraw_chunk_sizestr_chunk_size
chunk_sizeraw_content_lengthcontent_lengths                r   r_   r_   q  s     kC;##59K KK 34
4&	AY%(8@P&QRR)3I)>>O,224;A>N>"R'!/!6!6>P!6!Q#&9.9I$PQQ^R0JQ4y:%5#'
|=T6R  z*555D%a=(W4 !566! $ !+++ ',< =
=
	J!"R'"23E2Ff MNN/0M)"2>2B& IJJ%n556	O*=99:? ? 6( 	, 6 : 	O"7f MNN	Os   AG
FBG
*F +G
<F"=!G
F$A$G
F&G
	F* F(F* G
 G
"G
$G
&G
(F* *GG
)r   rL   rI   r    )r=   rJ   rI   Generator[None, None, bytes])r=   rJ   rI   zGenerator[None, None, Headers])rW   rV   r"   r   r=   rJ   r`   rJ   ra   rJ   rI   r   )'
__future__r   dataclassesosresysr'   collections.abcr   typingr   datastructuresr   
exceptionsr   r	   websockets_version__all__formatversion_infoPYTHON_VERSIONenvironr   r   r
   rV   ru   rn   r   r   compilerv   r]   	dataclassr   r   r6   r:   r_   rT   r   r   <module>r      s   "  	 	 
  %  # % 2  !1!12 ZZ^^n\*<)=>
 
n\*<)=>
 bjjnn%A5IJ bjjnn%A6JK BJJNN#={KL3 BJJ78	 BJJ45	 ` ` `F m m m`<!60<0#0f:O:O:O =:O >	:O
 ?:O ":Or   