
    jEG                       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mZmZmZ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 d0dZ! ej"        d          Z# ej"        d          Z$ej%         G d d                      Z&ej%         G d d                      Z'efd1d%Z(d2d'Z)d3d/Z*dS )4    )annotationsN)	Generator)Callable   )Headers)HeaderLineTooLongRequestLineTooLongSecurityErrorStatusLineTooLongTooManyHeaders)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                .    |                      d          S )zG
    Decode a bytestring for interpolating into an error message.

    backslashreplaceerrors)decode)r   s    [/workspace/show-city-briefing-agent/.venv/lib/python3.11/site-packages/websockets/http11.pydr$   8   s    
 <<1<222    s   [-!#$%&\'*+.^_`|~0-9a-zA-Z]+s   [\x09\x20-\x7e\x80-\xff]*c                      e Zd ZU dZded<   ded<   dZ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 )r   a  
    WebSocket handshake request.

    ``method`` and ``path`` must contain only ASCII characters. ``headers``
    should contain only ASCII characters; however, non-ASCII header values are
    tolerated and encoded as ISO-8859-1.

    Attributes:
        path: Request path, including optional query.
        headers: Request headers.
        method: Request method; WebSocket handshake requests use GET.
        protocol: Request protocol; WebSocket handshake requests use HTTP/1.1.
    r   pathr   headersGETmethodzHTTP/1.1protocolNException | None
_exceptionr   c                D    t          j        dt                     | j        S )NzIRequest.exception is deprecated; use ServerProtocol.handshake_exc insteadwarningswarnDeprecationWarningr-   selfs    r#   	exceptionzRequest.exceptionn   s&    W	
 	
 	
 r%   	read_lineJCallable[[int, type[Exception]], Generator[None, None, bytes | bytearray]]Generator[None, None, Request]c              #    K   	 t          |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vrt	          dt          |                     |                    d          }|                    d          }|                    d          }	t          |          E d{V }
d	|
v rt          d
          d|
v r(t          |
d                   dk    rt	          d           | |	|
||          S )a  
        Parse a WebSocket handshake request.

        This is a generator-based coroutine.

        The request method and path must contain only ASCII characters. The
        request path isn't URL-decoded or validated in any way. Request headers
        should contain only ASCII characters; however, non-ASCII header values
        are tolerated and decoded with ISO-8859-1.

        :meth:`parse` doesn't 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.
            RequestLineTooLong: If the request line is too long.
            HeaderLineTooLong: If a header line is too long.
            TooManyHeaders: If there are too many headers.
            UnicodeDecodeError: If the request method or path isn't ASCII.
            ValueError: If the request isn't well formatted.

        Nz1connection closed while reading HTTP request line       zinvalid HTTP request line:    HTTP/1.1s   HTTP/1.05unsupported protocol; expected HTTP/1.1 or HTTP/1.0: asciiTransfer-Encodingz!transfer codings aren't supportedContent-Lengthr   zunsupported request body)

parse_liner	   EOFErrorsplit
ValueErrorr$   r"   parse_headersNotImplementedErrorint)clsr6   request_lineexc
raw_methodraw_pathraw_protocolr*   r+   r'   r(   s              r#   parsezRequest.parsev   s     P	Y&0<N&O&OOOOOOOLL 	Y 	Y 	YNOOUXX	Y	X1=1C1CD!1L1L.J,, 	X 	X 	XL1\??LLMMSWW	X999%\??% %   ""7++&&w// w''*955555555 '))%&IJJJw&& 7+,--22 !;<<<s4&(333s     
?:?A +B	bytesc                    | j          d| j         d| j         d}|                    d          }|| j                                        z  }|S )z;
        Serialize a WebSocket handshake request.

         
r?   )r*   r'   r+   encoder(   	serialize)r4   rJ   requests      r#   rU   zRequest.serialize   sX     +GG	GGDMGGG%%g..4<))+++r%   r   r,   )r6   r7   r   r8   r   rP   )__name__
__module____qualname____doc____annotations__r*   r+   r-   propertyr5   classmethodrO   rU    r%   r#   r   r   T   s           III FH $(J''''   X I4 I4 I4 [I4V
 
 
 
 
 
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dS ) r   aw  
    WebSocket handshake response.

    ``reason_phrase`` and ``headers`` should contain only ASCII characters;
    however, non-ASCII reason phrases and header values are tolerated and
    encoded as ISO-8859-1.

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

    rH   status_coder   reason_phraser   r(   r%   r   bodyNr,   r-   r   c                D    t          j        dt                     | j        S )NzJResponse.exception is deprecated; use ClientProtocol.handshake_exc insteadr/   r3   s    r#   r5   zResponse.exception   s(    7	
 	
 	

 r%   Fr6   r7   
read_exact9Callable[[int], Generator[None, None, bytes | bytearray]]read_to_eofproxyboolGenerator[None, None, Response]c              #    K   	 t          |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|r$|dvrt	          dt          |                     n%|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          |	                     |		                    d          }t          |          E d{V }|rd}nt          |
||||          E d{V } | |
|||          S )a  
        Parse a WebSocket handshake response.

        This is a generator-based coroutine.

        The reason phrase and headers should contain only ASCII characters;
        however, non-ASCII reason phrases and header values are tolerated and
        decoded as ISO-8859-1.

        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.
            StatusLineTooLong: If the status line is too long.
            HeaderLineTooLong: If a header line is too long.
            TooManyHeaders: If there are too many headers.
            SecurityError: If the response body 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>   r=   z)unsupported protocol; expected HTTP/1.1: z+invalid status code; expected integer; got d   iX  u-   invalid status code; expected 100–599; got zinvalid HTTP reason phrase: 
iso-8859-1r%   )rB   r   rC   rD   rE   r$   rH   	_value_re	fullmatchr"   rF   	read_body)rI   r6   rf   rh   ri   status_linerK   r+   raw_status_code
raw_reasonrb   reasonr(   rd   s                 r#   rO   zResponse.parse   s     R	X%/	;L%M%MMMMMMMKK 	X 	X 	XMNNTWW	X	V4?4E4EdA4N4N1Hozz 	V 	V 	VJ!K..JJKKQUU	V 
	999 (~~( (   : ;&& P+PP  	o..KK 	 	 	Ra>P>PRR 	 k''''C''''T/@R@RTT   "":.. 	MKAjMMKKLLL ""<00*955555555  	DD'Wi[       D s;666s(     
?:?A +B	C( (+DrP   c                    d| j          d| j         d}|                    d          }|| j                                        z  }|| j        z  }|S )z<
        Serialize a WebSocket handshake response.

        z	HTTP/1.1 rR   rS   rn   )rb   rc   rT   r(   rU   rd   )r4   rr   responses      r#   rU   zResponse.serializeJ  s_     N$"2MMT5GMMM%%l33DL**,,,DIr%   rW   )F)
r6   r7   rf   rg   rh   r7   ri   rj   r   rk   rX   )rY   rZ   r[   r\   r]   rd   r-   r^   r5   r_   rO   rU   r`   r%   r#   r   r      s           !D!!!!#'J''''   X  W7 W7 W7 W7 [W7r
 
 
 
 
 
r%   r   r6   r7   too_long_exc_typetype[Exception](Generator[None, None, bytes | bytearray]c              #     K    | t           |          E d{V }|                    d          st          d          |dd         S )a  
    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.
        too_long_exc_type: exception to raise if the line is too long;
            defaults to :exc:`SecurityError`.

    Raises:
        EOFError: If the connection is closed without a CRLF.
        SecurityError: If the response exceeds a security limit.

    N   
zline without CRLF)MAX_LINE_LENGTHendswithrC   )r6   rx   lines      r#   rB   rB   W  s]      ,  i1BCCCCCCCCD==!! ,*+++9r%   Generator[None, None, Headers]c              #  >  K   t                      }t          t          dz             D ][}	 t          | 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          }|                    ||           ]t          dt           d          |S )a-  
    Parse HTTP headers.

    Headers should contain only ASCII characters; however, non-ASCII values are
    tolerated and decoded as ISO-8859-1.

    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.
        HeaderLineTooLong: If a header line is too long.
        TooManyHeaders: If there are too many headers.
        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?   rn   zexpected no more than z headers)r   rangeMAX_NUM_HEADERSrB   r   rC   rD   rE   r$   	_token_rerp   stripro   r"   set_insecurer   )	r6   r(   _r   rK   raw_name	raw_valuenamer   s	            r#   rF   rF   t  s     4 iiG?Q&'' Q Q	T(4EFFFFFFFFDD 	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''   .. 	T5)))) OoOOOPPPNs#   A
A'A""A'4B+B9rb   rH   r(   r   rf   rg   rh   c              #    K   d| cxk    rdk     sn | dk    s| dk    rdS |                     d          x}5|dk    rt          d| d	          d}	 t          |t                    E d {V }|                    dd          d         }t          |          dk    r)|                    d          }	t          d|	 d          t          |d          }
|
dk    rnxt          |          |
z   t          k    r#t          d|
 dt          |           d          | ||
          E d {V z  } |d          E d {V dk    rt          d          t          |          E d {V  |S |                     d          x}dt          |          dk    rt          d| d          t          |          }|t          k    rt          d| d           ||          E d {V S  |t          t                    E d {V S )Nrm         i0  r%   r@   chunkedztransfer coding z isn't supportedT   ;r   r      r   r    zchunk too large: 0xz bytes   zchunk too large: z bytes after r;   r|   zchunk without CRLFrA      zbody too large: )getrG   rB   r
   rD   lenr"   rH   MAX_BODY_SIZErE   rF   )rb   r(   r6   rf   rh   codingrd   chunk_size_lineraw_chunk_sizestr_chunk_size
chunk_sizeraw_content_lengthcontent_lengths                r#   rq   rq     s      kC;##5#59K9Ks KK 344
4&	AY%&Q&Q&Q&QRRR	7)3I})M)MMMMMMMO,224;;A>N>""R''!/!6!6>P!6!Q!Q#$P.$P$P$PQQQ^R00JQ4yy:%55#R
RRTRRR   zz*555555555D%:a==((((((W44 !5666!	7$ !+++++++++ ',< = =
=
	J!""R'' M3E M M MNNN/00M)) I> I I IJJJ%:n555555556 ';}mDDDDDDDDEr%   )r   r   r   r   )r6   r7   rx   ry   r   rz   )r6   r7   r   r   )rb   rH   r(   r   r6   r7   rf   rg   rh   r7   r   rz   )+
__future__r   dataclassesosresysr0   collections.abcr   typingr   datastructuresr   
exceptionsr   r	   r
   r   r   r   websockets_version__all__formatversion_infoPYTHON_VERSIONenvironr   r   r   rH   r   r~   r   r$   compiler   ro   	dataclassr   r   rB   rF   rq   r`   r%   r#   <module>r      s   " " " " " "     				 				 



  % % % % % %       # # # # # #              3 2 2 2 2 2    !12 Z^^>n>>*<>> 
 
>n>>*<>>
 
 #bjnn%A5IIJJ #bjnn%A6JJKK BJNN#={KKLL3 3 3 3 BJ788	 BJ455	 w w w w w w w wt D D D D D D D DV *7	    :; ; ; ;|;F ;F ;F ;F ;F ;Fr%   