ML i{.|UdZddlmZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z ejdk(rCddlZddlZeZej&j(Zej*Zded<ej.Zded <nddlZej0ZGd d eZGd d ZGddeZGddeZy)zCross platform abstractions for inter-process communication On Unix, this uses AF_UNIX sockets. On Windows, this uses NamedPipes. ) annotationsN) TracebackType)CallableFinalwin32zCallable[[_IPCHandle], int]DisconnectNamedPipeFlushFileBuffersceZdZdZy) IPCExceptionzException for IPC issues.N)__name__ __module__ __qualname____doc__N/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/ipc.pyr r "s#rr cFeZdZUdZded<d dZd dZd d dZddZddZ y )IPCBaseaBase class for communication between the dmypy client and server. This contains logic shared between the client and server, such as reading and writing. We want to be able to send multiple "messages" over a single connection and to be able to separate the messages. We do this by encoding the messages in an alphabet that does not contain spaces, then adding a space for separation. The last framed message is also followed by a space. _IPCHandle connectionc>||_||_t|_yN)nametimeout bytearraybuffer)selfrrs r__init__zIPCBase.__init__3s  k rc|jjd}|dk(ry|jd|}|j|dzd|_|S)z9Return a full frame from the bytes we have in the buffer. N)rfind)r space_posbdatas rframe_from_bufferzIPCBase.frame_from_buffer8sKKK$$T* ? JY'kk)a-/2  rc t}tjdk(rR |j}|nt j |j |d\}} |tjk(ru|jrt|jdzntj}t j|j|}|tjk7rtd||j#d\}}|j%}|r.|j&j)||j}|n|dk(rn|tj*k(r2|tj,k(r tdQ |j}|n:|j j/|}|sn|j&j)|M|syt1j2|d j3d S#t$r|j!wxYw) z=Read bytes from an IPC connection until we have a full frame.rT overlappedBad result from I/O wait: rzReadFile operation aborted.base64utf8)rsysplatformr&_winapiReadFilerERROR_IO_PENDINGrintINFINITEWaitForSingleObjectevent WAIT_OBJECT_0r BaseExceptioncancelGetOverlappedResult getbufferrextendERROR_MORE_DATAERROR_OPERATION_ABORTEDrecvcodecsdecode) rsizer%overrrres_mores rreadz IPCBase.readBs"++ <<7 "..0$"**4??DTRCg666>Bll#dllT&9":PWP`P`%99"((GL'"7"77".1KC5/Q"RR//53||~KK&&t, 224E(!8G333G;;;&'DEEAD..0$++D1 ""4(}}UH-44V<Bll#dllT&9":PWP`P`%99"((GL'"7"77".1KC5/Q"RR*-PQTPU+VWW&(%;%;D%A" sax$$x$L(9999 OO # #L 1%IIK  W"%A!**#NOUVV Ws0%E)#BE >0E) E&&E)) F2F  Fctjdk(r>|jtjk7r tj |jyy|jj yNr)r/r0rr1NULL CloseHandleclosers rrZz IPCBase.closesG <<7 "',,.##DOO4/ OO ! ! #rNrstrrz float | NonereturnNone)r^zbytearray | None)i)rCr4r^r])rQr]r^r_r^r_) r r rr__annotations__rr&rIrUrZrrrrr&s)" 8=t28$rrcJeZdZdZdfd ZddZ d ddZxZS) IPCClientz%The client side of an IPC connection.c Rt|||tjdk(r|jrt |jdznt j} t j|j| t j|jt j t j"zdt j$t j&t j(t j$|_t j.|j*t j0ddyt3j2t2j4|_|j*j7||j*j9|y#t$r}td|jd|d}~wt$r/}|jt jk(r td|d}~wwxYw#t$r/}|jt j,k(r td|d}~wwxYw)Nrr*zThe NamedPipe at z was not found.z!Timed out waiting for connection.rzThe connection is busy.)superrr/r0rr4r1NMPWAIT_WAIT_FOREVER WaitNamedPiperFileNotFoundErrorr rNrOERROR_SEM_TIMEOUT CreateFile GENERIC_READ GENERIC_WRITErX OPEN_EXISTINGFILE_FLAG_OVERLAPPEDrERROR_PIPE_BUSYSetNamedPipeHandleStatePIPE_READMODE_MESSAGEsocketAF_UNIX settimeoutconnect)rrrrT __class__s rrzIPCClient.__init__s w' <<7 "26,,c$,,-.GD`D`G %%dii9 ")"4"4II((7+@+@@LL))00LL#  + +!>!>d %mmFNN;DO OO & &w / OO # #D )9% Z"%6tyyk#QRXYY ::!:!::&'JKQRR   ::!8!88&'@AqH  s= F jA||j>jCd||j>jE|yy) Nrz\\.\pipe\{}-{}.pipez.sockr"rr!zInvalid handle to pipe: )#r/r0formatr-urlsafe_b64encodeosurandomrBrerr1CreateNamedPiperPIPE_ACCESS_DUPLEXFILE_FLAG_FIRST_PIPE_INSTANCErnrqPIPE_TYPE_MESSAGE PIPE_WAITrrfr GetLastErrorr tempfilemkdtempsock_directorypathjoinrrrssockbindlistenrt)rrrrEsockfilervs rrzIPCServer.__init__s <<7 ")00f..rzz!}=DDFDV5>D w' <<7 "%55 **778../--++,##$    ,,DO"$**,"%=cU#CDD%#+"2"2"4D ww||D$7$7CH fnn5DI IINN8 $ II  Q " $$W-#rctjdk(r tj|jd} |j rt |j dzntj}tj|j|}|tjk(sJ |jd\}}|dk(sJ|S |j&j)\|_}|S#t$r1|jtj|jwxYw#t$r8}|j tj"tj$fvrYd}~|Sd}~wwxYw#t*j $r}t-d|d}~wwxYw)NrTr(r*rzThe socket timed out)r/r0r1ConnectNamedPiperrr4r5r6r7r8r9r:rYr;rNrOERROR_PIPE_CONNECTED ERROR_NO_DATAracceptrrr )rrDrrFrGrErTs rrxzIPCServer.__enter__sY <<7 " --doo$O :>,,c$,,"56GL\L\G!55bhhHC'"7"7777 //53axx   B%)YY%5%5%7" %IIK''8 ::g&B&BGDYDY%ZZ[$ ) $>> B"#9:A Bs;!D A)C#?"E$#:D E!)-EE!$F7 FFctjdk(r8 t|js t d t |jy|j y#t |jwxYw)Nrz;Failed to flush NamedPipe buffer, maybe the client hung up?)r/r0r rr rrZrzs rr~zIPCServer.__exit__s] <<7 " 5'8&U9 $DOO4 JJL$DOO4s AA4ctjdk(r|jytj|j yrW)r/r0rZshutilrmtreerr[s rcleanupzIPCServer.cleanup(s) <<7 " JJL MM$-- .rc*tjdk(r |jStjdk(r4tjj |j |jS|jj}t|tsJ|S)Nrgnu0) r/r0rrrrrr getsockname isinstancer])rrs rconnection_namezIPCServer.connection_name.sl <<7 "99  \\V #77<< 3 3TYY? ?99((*DdC( ((Krrr\)r^rrrr`)r^r]) r r rrrarrxr~rpropertyrrrs@rrrsgK".H<.2(,'+ *&%   $/   rr)r __future__rr-rArrr/rtypesrtypingrrr0r1ctypesr4rwindllkernel32rrar rr Exceptionr rrcrrrrrs # "<<7J}}%%H7?7S7S4S4<4M4M1MJ$9$w$w$t00fffr