o
    Ð­j=  ã                   @  sV  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 dde› de› �¡Zej dde› de› �¡Zeej dd¡ƒZeej dd¡ƒZeej dd¡ƒZd1dd„Ze d¡Ze d¡Z ej!G dd„ dƒƒZ"ej!G dd „ d ƒƒZ#d2d$d%„Z$d3d'd(„Z%d4d/d0„Z&dS )5é    )Ú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_576Úvalueúbytes | bytearrayÚreturnÚstrc                 C  s   | j dd�S )zG
    Decode a bytestring for interpolating into an error message.

    Úbackslashreplace©Úerrors)Údecode)r   © r   úN/var/www/html/CropPilot/venv/lib/python3.10/site-packages/websockets/http11.pyÚd2   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 )r   z�
    WebSocket handshake request.

    Attributes:
        path: Request path, including optional query.
        headers: Request headers.
    r   Úpathr   ÚheadersNúException | NoneÚ
_exceptionr   c                 C  ó   t  dt¡ | jS )NzIRequest.exception is deprecated; use ServerProtocol.handshake_exc instead©ÚwarningsÚwarnÚDeprecationWarningr#   ©Úselfr   r   r   Ú	exception^   s
   þzRequest.exceptionÚ	read_lineú9Callable[[int], Generator[None, None, bytes | bytearray]]ú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 rxt|d ƒdkrxt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: ó   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-Lengthr   zunsupported request body)	Ú
parse_lineÚEOFErrorÚsplitÚ
ValueErrorr   r   Úparse_headersÚNotImplementedErrorÚint)	Úclsr,   Úrequest_lineÚexcÚmethodÚraw_pathÚprotocolr    r!   r   r   r   Úparsef   s4   €#
€ÿÿÿ
zRequest.parseÚbytesc                 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   rG   ©   s   zRequest.serialize©r   r"   )r,   r-   r   r.   ©r   rE   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r#   Úpropertyr+   ÚclassmethodrD   rG   r   r   r   r   r   N   s   
 Br   c                   @  sl   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d„ƒZ
d!dd„ZdS )"r   zÅ
    WebSocket handshake response.

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

    r=   Ústatus_coder   Úreason_phraser   r!   ó    r   ÚbodyNr"   r#   r   c                 C  r$   )NzJResponse.exception is deprecated; use ClientProtocol.handshake_exc insteadr%   r)   r   r   r   r+   É   s
   ýzResponse.exceptionFr,   r-   Ú
read_exactÚread_to_eofÚproxyÚboolúGenerator[None, None, Response]c              
   c  sh  � 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 |rI|dvrHtdt|ƒ› �ƒ‚n|dkrVtd	t|ƒ› �ƒ‚zt|ƒ}
W n tym   td
t|ƒ› �ƒd‚w d|
  krxdk s‚n tdt|ƒ› �ƒ‚t |	¡s�tdt|	ƒ› �ƒ‚|	 dd¡}t	|ƒE dH }|r¢d}nt
|
||||ƒ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/   r0   zinvalid HTTP status line: )r1   s   HTTP/1.0z5unsupported protocol; expected HTTP/1.1 or HTTP/1.0: r1   r2   z+invalid status code; expected integer; got éd   iX  u-   invalid status code; expected 100â€“599; got zinvalid HTTP reason phrase: r3   r4   rT   )r7   r8   r9   r:   r   r=   Ú	_value_reÚ	fullmatchr   r;   Ú	read_body)r>   r,   rV   rW   rX   Ústatus_liner@   rC   Úraw_status_codeÚ
raw_reasonrR   Úreasonr!   rU   r   r   r   rD   Ò   s^   €!
€ÿÿÿÿÿÿÿþÿÿ


ÿzResponse.parserE   c                 C  s6   d| j › d| j› d� ¡ }|| j ¡ 7 }|| j7 }|S )z<
        Serialize a WebSocket handshake response.

        z	HTTP/1.1 ú z
)rR   rS   rF   r!   rG   rU   )r*   Úresponser   r   r   rG   !  s   
zResponse.serializerI   )F)
r,   r-   rV   r-   rW   r-   rX   rY   r   rZ   rJ   )rK   rL   rM   rN   rO   rU   r#   rP   r+   rQ   rD   rG   r   r   r   r   r   µ   s   
 ûNr   r,   r-   ú(Generator[None, None, bytes | bytearray]c                 c  sJ   � 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 longó   
zline without CRLFéþÿÿÿ)ÚMAX_LINE_LENGTHÚRuntimeErrorr   Úendswithr8   )r,   Úliner   r   r   r7   .  s   €ÿ
r7   úGenerator[None, None, 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yI   tdt|ƒ› �ƒd‚w t 	|¡sXtdt|ƒ› �ƒ‚| 
d¡}t 	|¡skt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 headersrT   ó   :zinvalid HTTP header line: zinvalid HTTP header name: s    	zinvalid HTTP header value: r3   r4   ztoo many HTTP headers)r   ÚrangeÚMAX_NUM_HEADERSr7   r8   r9   r:   r   Ú	_token_rer]   Ústripr\   r   r   )	r,   r!   Ú_rk   r@   Úraw_nameÚ	raw_valueÚnamer   r   r   r   r;   I  s4   €
€ÿïÿ




r;   rR   r=   r!   r   rV   rW   c                 c  s¬  � d|   krdk sn | dks| dkrdS |  d¡ }d ur�|dkr+td|› d	�ƒ‚d}	 t|ƒE d H }| dd¡d }t|ƒdkrQ|jdd�}	td|	› d�ƒ‚t|dƒ}
|
dkr[n,t|ƒ|
 tkrptd|
› dt|ƒ› d�ƒ‚|||
ƒE d H 7 }|dƒE d H dkr†t	dƒ‚q.t
|ƒE d H  |S |  d¡ }d ur¾t|ƒdkr§td|› d�ƒ‚t|ƒ}|tkr·td|› d�ƒ‚||ƒE d H S z|tƒE d H W S  tyÕ   tdt› d�ƒ‚w )Nr[   éÈ   éÌ   i0  rT   r5   Úchunkedztransfer coding z isn't supportedTó   ;r   r   é   r   r   zchunk too large: 0xz bytesé   zchunk too large: z bytes after r0   rf   zchunk without CRLFr6   é   zbody too large: zbody too large: over )Úgetr<   r7   r9   Úlenr   r   r=   ÚMAX_BODY_SIZEr:   r;   ri   )rR   r!   r,   rV   rW   ÚcodingrU   Úchunk_size_lineÚraw_chunk_sizeÚstr_chunk_sizeÚ
chunk_sizeÚraw_content_lengthÚcontent_lengthr   r   r   r^   |  sL   €&
ÿðÿr^   )r   r   r   r   )r,   r-   r   re   )r,   r-   r   rl   )rR   r=   r!   r   r,   r-   rV   r-   rW   r-   r   re   )'Ú
__future__r   ÚdataclassesÚosÚreÚsysr&   Úcollections.abcr   Útypingr   Údatastructuresr   Ú
exceptionsr   r   Úwebsockets_versionÚ__all__ÚformatÚversion_infoÚPYTHON_VERSIONÚenvironr}   r
   r	   r=   ro   rh   r   r   Úcompilerp   r\   Ú	dataclassr   r   r7   r;   r^   r   r   r   r   Ú<module>   sD    þþ


f
x
3