
    &th1                       d dl mZ d dlZd dlZd dlZd dlmZmZmZ ddl	m
Z
mZ dZdZdZddZ ej        d          Z ej        d          Zej         G d d                      Zej         G d d                      ZddZddZdS )    )annotationsN)Callable	GeneratorOptional   )datastructures
exceptions   i    i   valuebytesreturnstrc                .    |                      d          S )zG
    Decode a bytestring for interpolating into an error message.

    backslashreplace)errors)decode)r   s    e/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/websockets/http11.pydr      s    
 <<1<222    s   [-!#$%&\'*+.^_`|~0-9a-zA-Z]+s   [\x09\x20-\x7e\x80-\xff]*c                  n    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
dS )Requestz
    WebSocket handshake request.

    Attributes:
        path: Request path, including optional query.
        headers: Request headers.
    r   pathdatastructures.HeadersheadersNOptional[Exception]
_exceptionr   c                D    t          j        dt                     | j        S )NzKRequest.exception is deprecated; use ServerConnection.handshake_exc insteadwarningswarnDeprecationWarningr   selfs    r   	exceptionzRequest.exceptionC   (    9	
 	
 	

 r   	read_line-Callable[[int], Generator[None, None, bytes]]Generator[None, None, Request]c              #  Z  K   	 t          |          E d{V }n"# t          $ r}t          d          |d}~ww xY w	 |                    dd          \  }}}n.# t          $ r! t          dt	          |                     dw xY w|dk    rt          dt	          |                     |dk    rt          d	t	          |                     |                    d
d          }t          |          E d{V }d|v rt          d          d|v rt          d           | ||          S )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: s   GETzunsupported HTTP method:    HTTP/1.1unsupported HTTP version: asciisurrogateescapeTransfer-Encoding!transfer codings aren't supportedContent-Lengthzunsupported request body)
parse_lineEOFErrorsplit
ValueErrorr   r   parse_headersNotImplementedError)	clsr&   request_lineexcmethodraw_pathversionr   r   s	            r   parsezRequest.parseL   s     F	Y&0&;&;;;;;;;LL 	Y 	Y 	YNOOUXX	Y	X(4(:(:4(C(C%FHgg 	X 	X 	XL1\??LLMMSWW	X VD6DDEEEk!!F!G**FFGGGw(9::*955555555 '))%&IJJJw&&7888s4!!!s    
949A +Br   c                x    d| j          d                                }|| j                                        z  }|S )z;
        Serialize a WebSocket handshake request.

        zGET z HTTP/1.1
)r   encoder   	serialize)r#   requests     r   rB   zRequest.serialize   s?     211188::4<))+++r   r   r   )r&   r'   r   r(   r   r   )__name__
__module____qualname____doc____annotations__r   propertyr$   classmethodr?   rB    r   r   r   r   3   s           III#### '+J****   X <" <" <" [<"|	 	 	 	 	 	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            Z
ddZdS )Responsez
    WebSocket handshake response.

    Attributes:
        status_code: Response code.
        reason_phrase: Response reason.
        headers: Response headers.
        body: Response body, if any.

    intstatus_coder   reason_phraser   r   NzOptional[bytes]bodyr   r   r   c                D    t          j        dt                     | j        S )NzLResponse.exception is deprecated; use ClientConnection.handshake_exc insteadr   r"   s    r   r$   zResponse.exception   r%   r   r&   r'   
read_exactread_to_eofGenerator[None, None, Response]c              #    K   	 t          |          E d{V }n"# t          $ r}t          d          |d}~ww xY w	 |                    dd          \  }}}n.# t          $ r! t          dt	          |                     dw xY w|dk    rt          dt	          |                     	 t          |          }	n.# t          $ r! t          dt	          |                     dw xY wd	|	cxk    rd
k     s!n t          dt	          |                     t                              |          st          dt	          |                     |                                }
t          |          E d{V }d|v rt          d          d	|	cxk    rdk     sn |	dk    s|	dk    rd}n	 |d         }t          |          }n# t          $ r d}Y nw xY w|C	  |t                    E d{V }n_# t          $ r t          j        dt           d          w xY w|t          k    rt          j        d| d           ||          E d{V } | |	|
||          S )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: r,   r-   zinvalid HTTP status code: d   i  zunsupported HTTP status code: zinvalid HTTP reason phrase: r0   r1         i0  r2   zbody too large: over z byteszbody too large: )r3   r4   r5   r6   r   rP   	_value_re	fullmatchr   r7   r8   KeyErrorMAX_BODYRuntimeErrorr	   SecurityError)r9   r&   rU   rV   status_liner;   r>   raw_status_code
raw_reasonrQ   reasonr   rS   raw_content_lengthcontent_lengths                  r   r?   zResponse.parse   se     @	X%/	%:%:::::::KK 	X 	X 	XMNNTWW	X	V3>3D3DT13M3M0G_jj 	V 	V 	VJ!K..JJKKQUU	V k!!F!G**FFGGG	o..KK 	 	 	AQ-?-?AA 	 k((((D((((Ra>P>PRRSSS"":.. 	MKAjMMKKLLL""$$*955555555 '))%&IJJJ +########{c'9'9[C=O=ODD9 &--=%>" "%%7!8!8  & & &!%&
 %&1k(&;&;;;;;;;DD#   $2@@@@    (** .=~===   #-*^"<"<<<<<<<s;666sE    
949A +B,B< <+C',G GGG0 0(Hr   c                    d| j          d| j         d                                }|| j                                        z  }| j        
|| j        z  }|S )z<
        Serialize a WebSocket handshake response.

        z	HTTP/1.1  z
)rQ   rR   rA   r   rB   rS   )r#   responses     r   rB   zResponse.serialize  s`     Kt/JJ$2DJJJQQSSDL**,,,9 	!Hr   rD   )r&   r'   rU   r'   rV   r'   r   rW   rE   )rF   rG   rH   rI   rJ   rS   r   rK   r$   rL   r?   rB   rM   r   r   rO   rO      s         	 	 #### D    &*J****   X \7 \7 \7 [\7|     r   rO   r&   r'   -Generator[None, None, datastructures.Headers]c              #    K   t          j                    }t          t          dz             D ]E}	 t	          |           E d{V }n"# t
          $ r}t          d          |d}~ww xY w|dk    r n	 |                    dd          \  }}n.# t          $ r! t          dt          |                     dw xY wt          
                    |          st          dt          |                     |                    d          }t          
                    |          st          d	t          |                     |                    d
          }|                    d
d          }|||<   Gt          j        d          |S )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: r.   r/   ztoo many HTTP headers)r   HeadersrangeMAX_HEADERSr3   r4   r5   r6   r   	_token_rer]   stripr\   r   r	   ra   )	r&   r   _liner;   raw_name	raw_valuenamer   s	            r   r7   r7   !  s     , $&&G;?## @ @	T(33333333DD 	T 	T 	TIJJPSS	T3;;E	O"&**T1"5"5Hii 	O 	O 	OC!D''CCDD$N	O""8,, 	IG!H++GGHHHOOF++	""9-- 	KI1Y<<IIJJJw''  *;<< &'>???Ns#   A
A&A!!A&3B+B8Generator[None, None, bytes]c              #     K   	  | t                     E d{V }n"# t          $ r t          j        d          w xY w|                    d          st          d          |dd         S )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 longs   
zline without CRLF)MAX_LINEr`   r	   ra   endswithr4   )r&   rt   s     r   r3   r3   T  s      "8#)H-------- 8 8 8&7778 ==!! ,*+++9s    :)r   r   r   r   )r&   r'   r   rk   )r&   r'   r   rx   )
__future__r   dataclassesrer   typingr   r   r    r   r	   rp   r{   r_   r   compilerq   r\   	dataclassr   rO   r7   r3   rM   r   r   <module>r      sq   " " " " " "     				  0 0 0 0 0 0 0 0 0 0 ( ( ( ( ( ( ( (   3 3 3 3 BJ788	 BJ455	 ` ` ` ` ` ` ` `F F F F F F F F FR0 0 0 0f     r   