K iddlmZddlZddlZddlmZmZddlmZm Z m Z ddl m Z m Z ddlmZmZddlmZmZgd Zdd Zdd Zdd Zdd Zy)) annotationsN)HeadersMultipleValuesError) InvalidHeaderInvalidHeaderValueInvalidUpgrade)parse_connection parse_upgrade)ConnectionOptionUpgradeProtocol) accept_key generate_key) build_request check_requestbuild_responsecheck_responsecBt}d|d<d|d<||d<d|d<|S)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`. websocketUpgrade ConnectionSec-WebSocket-Key13Sec-WebSocket-Version)rheaderskeys a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/websockets/legacy/handshake.pyrrs: .C$GI%GL#&G  '+G #$ Jct|jdDcgc] }t|c}g}td|Dst ddj |t|jdDcgc] }t |c}g}t|dk(r|djdk(st ddj | |d} tj|jd }t|d k7r t#d| |d}|dk7r t#d||Scc}wcc}w#t$r}td|d }~wt$r}tdd |d }~wwxYw#tj $r}t#d||d }~wwxYw#t$r}td|d }~wt$r}tdd |d }~wwxYw)ab 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. rc3BK|]}|jdk(ywupgradeNlower.0values r z check_request..=Beu{{} )B, rrrrNmultiple valuesT)validaterr)sumget_allr anyr joinr lenr%KeyErrorrrbase64 b64decodeencodebinasciiErrorr)rr( connectionr#s_w_keyexcraw_key s_w_versions rrr%s(*-.5ool.KLU % Lb*J BzB B\499Z+@AA%(+2??9+EF%u F&G LA '!*"2"2"4 "CY '(:;;M-. H""7>>#3dC 7|r !4g>>Q56 d !8+FF NQ M G :/0c9 M/1BCLM >>H !4g>CGH >34#= Q35FGSPQskD08D5D:%E0F: E- E E- E((E-0F FF G ! F-- G 9 GG c4d|d<d|d<t||d<y)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`. rrrSec-WebSocket-AcceptN)acceptrs rrres'%GI%GL&,SkG "#rcdt|jdDcgc] }t|c}g}td|Dst ddj |t|jdDcgc] }t |c}g}t|dk(r|djdk(st ddj | |d }|t|k7r td |y cc}wcc}w#t$r}td |d }~wt$r}td d |d }~wwxYw) a 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. rc3BK|]}|jdk(ywr"r$r&s rr)z!check_response..r*r+ rr-rrr,rBNr.)r1r2r r3r r4r r5r%r6rrrCr)rrr(r<r# s_w_acceptr>s rrrus- *-.5ool.KLU % Lb*J BzB B\388J+?@@%(+2??9+EF%u F&G LA '!*"2"2"4 "CY '(:;;P34 VC[  !7DD!/ M G =23< P24EFCOPs/C28C7C<< D/ D D/ D**D/)rrreturnstr)rrrrIrHNone) __future__rr7r:datastructuresrr exceptionsrrr rr r typingr r utilsrrCr__all__rrrrrrrRs>" 9JJ566 Q*=@ 2 )Er