K iM:ddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZddlmZgd Zd j$ej&Zej*j-d d ed eZej*j-dd ed eZeej*j-ddZeej*j-ddZeej*j-ddZddZej<dZej<dZ ejBGddZ"ejBGddZ# d dZ$ d!dZ% d"dZ&y)#) annotationsN) Generator)Callable)Headers) SecurityError)version)SERVER USER_AGENTRequestResponsez{}.{}WEBSOCKETS_USER_AGENTzPython/z websockets/WEBSOCKETS_SERVERWEBSOCKETS_MAX_NUM_HEADERS128WEBSOCKETS_MAX_LINE_LENGTH8192WEBSOCKETS_MAX_BODY_SIZE 1_048_576c&|jdS)zG Decode a bytestring for interpolating into an error message. backslashreplaceerrors)decode)values W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/websockets/http11.pydr2s <<1< 22s[-!#$%&\'*+.^_`|~0-9a-zA-Z]+s[\x09\x20-\x7e\x80-\xff]*cheZdZUdZded<ded<dZded<ed d Ze d d Z dd Z y)r z WebSocket handshake request. Attributes: path: Request path, including optional query. headers: Request headers. strpathrheadersNException | None _exceptioncNtjdt|jS)NzIRequest.exception is deprecated; use ServerProtocol.handshake_exc insteadwarningswarnDeprecationWarningr$selfs r exceptionzRequest.exception^s  W  rc#K t|Ed{} |jdd\}}}|dk7rtdt ||dk7rtd t ||j d d }t |Ed{}d |vr td d|vr td|||S7#t$r}td|d}~wwxYw#t$rtdt |dwxYw7ow)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 zinvalid HTTP request line: HTTP/1.1)unsupported protocol; expected HTTP/1.1: sGETz+unsupported HTTP method; expected GET; got asciisurrogateescapeTransfer-Encodingz!transfer codings aren't supportedContent-Lengthzunsupported request body) parse_lineEOFErrorsplit ValueErrorrr parse_headersNotImplementedError) cls read_line request_lineexcmethodraw_pathprotocolr!r"s rparsez Request.parsefs-F Y&0&;;L X)5););D!)D &FHh { ";AlO;LM  V J1V9+VW Ww(9:*955 ' )%&IJ J w &78 84!!5< YNOUX X Y  X:1\?:KLMSW W X6sUC8B4B2B4CAC8C6+C82B44 C= C  CC8"C33C8c|d|jdj}||jjz }|S)z; Serialize a WebSocket handshake request. zGET z HTTP/1.1 )r!encoder" serialize)r+requests rrFzRequest.serializes; =188:4<<))++rreturnr#)r=-Callable[[int], Generator[None, None, bytes]]rIzGenerator[None, None, Request]rIbytes) __name__ __module__ __qualname____doc____annotations__r$propertyr, classmethodrCrFrrr r Ns_ I $(J ' ="@=" (="="~ rr ceZdZUdZded<ded<ded<dZd ed <d Zd ed <eddZe d ddZ ddZ y )r z WebSocket handshake response. Attributes: status_code: Response code. reason_phrase: Response reason. headers: Response headers. body: Response body. int status_coder reason_phraserr"rrLbodyNr#r$cNtjdt|jS)NzJResponse.exception is deprecated; use ClientProtocol.handshake_exc insteadr&r*s rr,zResponse.exceptions"  7  rc#K t|Ed{} |jdd\}}} |dk7rtdt | t |} d | cxkrd ksntd t |t j| std t | | jd d} t|Ed{} |rt| | |||Ed{} nd} || | | | S7#t$r}td|d}~wwxYw#t$rtdt |dwxYw#t$rtdt |dwxYw77}w)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/zinvalid HTTP status line: r0r1z+invalid status code; expected integer; got diXu-invalid status code; expected 100–599; got zinvalid HTTP reason phrase: r2r3r) r6r7r8r9rrV _value_re fullmatchrr: read_body)r<r= read_exact read_to_eof include_body status_liner?rBraw_status_code raw_reasonrWreasonr"rYs rrCzResponse.parsesB X%/ %::K V4?4E4EdA4N 1Hoz { ";AkN;KL  o.K k'C'?/@R?ST "":.;AjM?KL L""7,=>*955 'Wi[DD;66G; XMNTW W X  V9!K.9IJKQU U V =a>P=QR  6sEC4C2C4DE D6A0EEEE E2C44 D= D  DE"D33E6"EEEcd|jd|jdj}||jj z }||j z }|S)z< Serialize a WebSocket handshake response. z HTTP/1.1  z )rWrXrEr"rFrY)r+responses rrFzResponse.serializesYt//0$2D2D1ETJQQSDLL**,,DIIrrH)T) r=rJr`rJrarJrbboolrIzGenerator[None, None, Response]rK) rMrNrOrPrQrYr$rRr,rSrCrFrTrrr r s  D%#'J '  " D7@D7BD7C D7  D7 ) D7D7L rr c#K |tEd{}|jds t d|ddS7%#t$r tdwxYww)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 zline without CRLF)MAX_LINE_LENGTH RuntimeErrorrendswithr7)r=lines rr6r6#s\"-#O44 == !*++ 9 5 -O,,-s%A;9;!A;AAc#pKt}ttdzD]} t|Ed{}|dk(r|S |j dd\}}tj|st dt||jd}tj|st d t||jd }|jd d }|||<td 7#t$r}t d|d}~wwxYw#t $rt dt|dwxYww) 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. rNz,connection closed while reading HTTP headersr:zinvalid HTTP header line: zinvalid HTTP header name: s zinvalid HTTP header value: r2r3ztoo many HTTP headers)rrangeMAX_NUM_HEADERSr6r7r8r9r _token_rer^stripr]rr) r=r"_rqr?raw_name raw_valuenamers rr:r:>sK,iG ?Q& '5 T(33D 3; & N# O"&**T1"5 Hi""8,9!H+GH HOOF+ ""9-:1Y<.IJ Jw'  *;< )5.344+4 TIJPS S T O9!D'CD$ N OsO D6C4C2C4D6DBD62C44 D= D  DD6"D33D6c#Kd|cxkrdks n|dk(s|dk(ry|jdx}|dk7rtd|d d} t|Ed{}|jd d d }t |d kDr!|j d} t d| dt|d} | d k(rnbt || ztkDrt d| dt |d||| Ed{z }|dEd{dk7r tdt|Ed{|S|jdx} Pt | dkDrt d| dt| } | tkDrt d| d|| Ed{S |tEd{S7J7777"7#t$rt dtdwxYww)Nr\i0rr4chunkedztransfer coding z isn't supported;rrrrzchunk too large: 0xz byteszchunk too large: z bytes after r/rlzchunk without CRLFr5zbody too large: zbody too large: over ) getr;r6r8lenrrrV MAX_BODY_SIZEr9r:ro) rWr"r=r`racodingrYchunk_size_lineraw_chunk_sizestr_chunk_size chunk_sizeraw_content_lengthcontent_lengths rr_r_qs kC;##59KKK 34 4& A Y %(8@P&QR R)3I)>>O,224;A>N>"R'!/!6!6>P!6!Q#&9.9I$PQQ^R0JQ4y:% 5#' |=T 6R z*55 5D%a=(W4 !566!$!+++ ' ,< = =  J ! "R '"23E2Ff MN N/0 M )"2>2B& IJ J%n556 O*=99 :??6( ,6: O"7 f MN N OsAG FBG *F +G <F"=!G F$A$G F&G  F*F(F*G  G "G $G &G (F**GG )rrLrIr )r=rJrIGenerator[None, None, bytes])r=rJrIzGenerator[None, None, Headers]) rWrVr"rr=rJr`rJrarJrIr)' __future__r dataclassesosresysr'collections.abcrtypingrdatastructuresr exceptionsrr websockets_version__all__format version_infoPYTHON_VERSIONenvironrr r rVrurnrrcompilervr] dataclassr r r6r:r_rTrrrs" %#%2  !1!12ZZ^^ n \*<)=>  n \*<)=>  bjjnn%A5IJbjjnn%A6JKBJJNN#={KL 3 BJJ7 8  BJJ4 5  ```F mmm`<!60<0#0f:O:O :O=:O> :O ? :O " :Or