o
    :ÊÆh1  ã                   @  s²   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d„Ze d¡Ze d¡ZejG dd„ dƒƒZejG dd„ dƒƒZddd„Zddd„ZdS ) é    )ÚannotationsN)ÚCallableÚ	GeneratorÚOptionalé   )ÚdatastructuresÚ
exceptionsé€   i    i   ÚvalueÚbytesÚreturnÚstrc                 C  s   | j dd�S )zG
    Decode a bytestring for interpolating into an error message.

    Úbackslashreplace)Úerrors)Údecode)r
   © r   ú^/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/websockets/http11.pyÚd   s   r   s   [-!#$%&\'*+.^_`|~0-9a-zA-Z]+s   [\x09\x20-\x7e\x80-\xff]*c                   @  sT   e Zd ZU dZded< ded< dZded< edd
d„ƒZeddd„ƒZ	d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                 C  ó   t  dt¡ | jS )NzIRequest.exception is deprecated; use ServerProtocol.handshake_exc instead©ÚwarningsÚwarnÚDeprecationWarningr   ©Úselfr   r   r   Ú	exceptionC   ó
   ýzRequest.exceptionÚ	read_lineú-Callable[[int], Generator[None, None, bytes]]úGenerator[None, None, Request]c           	   
   c  sê   � z	t |ƒE dH }W n ty } ztdƒ|‚d}~ww z| dd¡\}}}W n ty8   tdt|ƒ› �ƒd‚w |dkrFtdt|ƒ› �ƒ‚|dkrStd	t|ƒ› �ƒ‚| d
d¡}t|ƒE dH }d|v rhtdƒ‚d|v rpt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   r   r   r   ÚparseL   s.   €#
€ÿÿ
zRequest.parser   c                 C  s$   d| j › d� ¡ }|| j ¡ 7 }|S )z;
        Serialize a WebSocket handshake request.

        zGET z HTTP/1.1
)r   Úencoder   Ú	serialize)r    Úrequestr   r   r   r=   ‹   s   zRequest.serialize©r   r   )r#   r$   r   r%   ©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   Úpropertyr!   Úclassmethodr;   r=   r   r   r   r   r   3   s   
 >r   c                   @  sh   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d„ƒZe	ddd„ƒZ
d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                 C  r   )NzJResponse.exception is deprecated; use ClientProtocol.handshake_exc insteadr   r   r   r   r   r!   «   r"   zResponse.exceptionr#   r$   Ú
read_exactÚread_to_eofúGenerator[None, None, Response]c              
   c  sð  � z	t |ƒE dH }W n ty } ztdƒ|‚d}~ww z| dd¡\}}}W n ty8   tdt|ƒ› �ƒd‚w |dkrFtdt|ƒ› �ƒ‚zt|ƒ}	W n ty]   tdt|ƒ› �ƒd‚w d	|	  krhd
k srn tdt|ƒ› �ƒ‚t |¡s€tdt|ƒ› �ƒ‚| ¡ }
t	|ƒE dH }d|v r“t
dƒ‚d	|	  kr�dk s¦n |	dks¦|	dkr©d}nHz|d }W n tyº   d}Y nw t|ƒ}|du rÝz	|tƒE dH }W n$ tyÜ   t dt› d�¡‚w |tkrêt d|› d�¡‚||ƒE dH }| |	|
||ƒ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: r,   r-   éÈ   éÌ   i0  r.   zbody too large: over z byteszbody too large: )r/   r0   r1   r2   r   rI   Ú	_value_reÚ	fullmatchr   r3   r4   ÚKeyErrorÚMAX_BODYÚRuntimeErrorr   ÚSecurityError)r5   r#   rM   rN   Ústatus_liner7   r:   Úraw_status_codeÚ
raw_reasonrJ   Úreasonr   rL   Úraw_content_lengthÚcontent_lengthr   r   r   r;   ´   sj   € 
€ÿÿÿþÿ
&ÿ
ÿÿ
ÿzResponse.parser   c                 C  s@   d| j › d| j› d� ¡ }|| j ¡ 7 }| jdur|| j7 }|S )z<
        Serialize a WebSocket handshake response.

        z	HTTP/1.1 Ú z
N)rJ   rK   r<   r   r=   rL   )r    Úresponser   r   r   r=     s
   

zResponse.serializer?   )r#   r$   rM   r$   rN   r$   r   rO   r@   )rA   rB   rC   rD   rE   rL   r   rF   r!   rG   r;   r=   r   r   r   r   rH   —   s   
 ^rH   r#   r$   ú-Generator[None, None, datastructures.Headers]c           	      c  s  � t  ¡ }ttd ƒD ]p}z	t| ƒE dH }W n ty' } ztdƒ|‚d}~ww |dkr/ |S z
| dd¡\}}W n tyJ   tdt|ƒ› �ƒd‚w t	 
|¡sYtdt|ƒ› �ƒ‚| d¡}t 
|¡sltd	t|ƒ› �ƒ‚| d
¡}| d
d¡}|||< qt d¡‚)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 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   ÚHeadersÚrangeÚMAX_HEADERSr/   r0   r1   r2   r   Ú	_token_rerT   ÚstriprS   r   r   rX   )	r#   r   Ú_Úliner7   Úraw_nameÚ	raw_valueÚnamer
   r   r   r   r3   !  s4   €
€ÿïÿ





r3   úGenerator[None, None, bytes]c                 c  sL   � z	| t ƒE dH }W n ty   t d¡‚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_LINErW   r   rX   Úendswithr0   )r#   rj   r   r   r   r/   T  s   €
ÿ
r/   )r
   r   r   r   )r#   r$   r   ra   )r#   r$   r   rn   )Ú
__future__r   ÚdataclassesÚrer   Útypingr   r   r   Ú r   r   rf   rp   rV   r   Úcompilerg   rS   Ú	dataclassr   rH   r3   r/   r   r   r   r   Ú<module>   s&    


c 

3