
    vKg                        S SK Jr  S SKrS SKrSSKJrJr  SSKJrJ	r	J
r
  SSKJrJr  SSKJrJr  SSKJrJr  / S	QrSS
 jrSS jrSS jrSS jrg)    )annotationsN   )HeadersMultipleValuesError)InvalidHeaderInvalidHeaderValueInvalidUpgrade)parse_connectionparse_upgrade)ConnectionOptionUpgradeProtocol)
accept_keygenerate_key)build_requestcheck_requestbuild_responsecheck_responsec                @    [        5       nSU S'   SU S'   XS'   SU S'   U$ )z
Build a handshake request to send to the server.

Update request headers passed in argument.

Args:
    headers: Handshake request headers.

Returns:
    ``key`` that must be passed to :func:`check_response`.

	websocketUpgrade
ConnectionSec-WebSocket-Key13Sec-WebSocket-Version)r   headerskeys     [/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/websockets/legacy/handshake.pyr   r      s8     .C$GI%GL#& '+G#$J    c                   [        U R                  S5       Vs/ sH  n[        U5      PM     sn/ 5      n[        S U 5       5      (       d  [	        SSR                  U5      5      e[        U R                  S5       Vs/ sH  n[        U5      PM     sn/ 5      n[        U5      S:X  a  US   R                  5       S:X  d  [	        SSR                  U5      5      e U S   n [        R                  " UR                  5       SS9n[        U5      S:w  a  [#        SU5      e U S   nUS:w  a  [#        SU5      eU$ s  snf s  snf ! [         a  n[        S5      UeS	nAf[         a  n[        SS
5      UeS	nAff = f! [        R                    a  n[#        SU5      UeS	nAff = f! [         a  n[        S5      UeS	nAf[         a  n[        SS
5      UeS	nAff = f)a.  
Check a handshake request received from the client.

This function doesn't verify that the request is an HTTP/1.1 or higher GET
request and doesn't perform ``Host`` and ``Origin`` checks. These controls
are usually performed earlier in the HTTP request handling code. They're
the responsibility of the caller.

Args:
    headers: Handshake request headers.

Returns:
    ``key`` that must be passed to :func:`build_response`.

Raises:
    InvalidHandshake: If the handshake request is invalid.
        Then, the server must return a 400 Bad Request error.

r   c              3  D   #    U H  oR                  5       S :H  v   M     g7fupgradeNlower.0values     r   	<genexpr> check_request.<locals>.<genexpr>=        Bze{{}	)z    , r      r   r   r   Nmultiple valuesT)validate   r   r   )sumget_allr
   anyr	   joinr   lenr%   KeyErrorr   r   base64	b64decodeencodebinasciiErrorr   )r   r(   
connectionr#   s_w_keyexcraw_keys_w_versions           r   r   r   %   s   ( *-.5ool.KL.KU	%	 .KLb*J BzBBB\499Z+@AA%(+2??9+EF+E%u	+EF&G LA'!*"2"2"4"CY		'(:;;M-.H""7>>#3dC 7|r !4g>>Q56 d !8+FFNQ 	M 	G  :/0c9 M/1BCLM
 >> H !4g>CGH  >34#= Q35FGSPQsk   D;?E E ##E= "F& 
E:EE:(E55E:=F#FF#&
G0F<<G	GGc                4    SU S'   SU S'   [        U5      U S'   g)z
Build a handshake response to send to the client.

Update response headers passed in argument.

Args:
    headers: Handshake response headers.
    key: Returned by :func:`check_request`.

r   r   r   Sec-WebSocket-AcceptN)acceptr   s     r   r   r   e   s'     %GI%GL&,SkG"#r   c                   [        U R                  S5       Vs/ sH  n[        U5      PM     sn/ 5      n[        S U 5       5      (       d  [	        SSR                  U5      5      e[        U R                  S5       Vs/ sH  n[        U5      PM     sn/ 5      n[        U5      S:X  a  US   R                  5       S:X  d  [	        SSR                  U5      5      e U S	   nU[        U5      :w  a  [        S	U5      eg
s  snf s  snf ! [         a  n[        S	5      UeS
nAf[         a  n[        S	S5      UeS
nAff = f)aw  
Check a handshake response received from the server.

This function doesn't verify that the response is an HTTP/1.1 or higher
response with a 101 status code. These controls are the responsibility of
the caller.

Args:
    headers: Handshake response headers.
    key: Returned by :func:`build_request`.

Raises:
    InvalidHandshake: If the handshake response is invalid.

r   c              3  D   #    U H  oR                  5       S :H  v   M     g7fr"   r$   r&   s     r   r)   !check_response.<locals>.<genexpr>   r+   r,    r   r.   r   r   r-   rC   Nr/   )r2   r3   r
   r4   r	   r5   r   r6   r%   r7   r   r   rD   r   )r   r   r(   r=   r#   
s_w_acceptr?   s          r   r   r   u   s<     *-.5ool.KL.KU	%	 .KLb*J BzBBB\388J+?@@%(+2??9+EF+E%u	+EF&G LA'!*"2"2"4"CY		'(:;;P34
 VC[  !7DD !/ 	M 	G  =23< P24EFCOPs/   C>?DD 
D=DD=+D88D=)r   r   returnstr)r   r   r   rK   rJ   None)
__future__r   r8   r;   datastructuresr   r   
exceptionsr   r   r	   r   r
   r   typingr   r   utilsr   rD   r   __all__r   r   r   r    r   r   <module>rT      s>    "   9 J J 5 6 6 Q*=@2 )Er   