U &.ep|@s ddddgZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z m Z dd lmZejZz$ddlZdd lmZmZmZmZWn$ek rejd kr‚dZYnXd Zd ZdZeZdZdgZe edrdZedg7Zejd krdZedg7ZefddZ!ddZ"ddZ#ddZ$ddZ%GdddZ&ernGddde&Z'Gd d!d!e&Z(Gd"dde)Z*dPd#dZ+ejd krdQd%dZ,n dRd&dZ,Gd'd(d(e)Z-d)d*Z.ejd krGd+d,d,e)Z/d-d.Z0d/Z1d0Z2d1Z3d2Z4d3d4Z5d5d6Z6Gd7d8d8e)Z7d9d:Z8d;d<Z9Gd=d>d>e*Z:d?d@Z;ejd krzdAdBZhZ?dSdCdZ@n,ddlAZAe eAdDreAjBZCneAjDZCdTdEdZ@ejd krdFdGZEdHdIZFeGe(eEdJdKZHdLdMZIeGe'eHndNdGZEdOdIZFeGe(eEdS)UClientListenerPipewaitN)util)AuthenticationErrorBufferTooShort) reduction) WAIT_OBJECT_0WAIT_ABANDONED_0 WAIT_TIMEOUTINFINITEwin32i g4@Zsha256AF_INETAF_UNIXAF_PIPEcCs t|SNtime monotonic)timeoutr2/usr/lib64/python3.8/multiprocessing/connection.py _init_timeout?srcCs t|kSrr)trrr_check_timeoutBsrcCsX|dkr dS|dkr&tjdtdS|dkrLtjdtttfddStd d S) z? Return an arbitrary free address for the given family r)Z localhostrrz listener-)prefixdirrz\\.\pipe\pyc-%d-%d-zunrecognized familyN) tempfileZmktemprZ get_temp_dirosgetpidnext _mmap_counter ValueErrorfamilyrrrarbitrary_addressIsr(cCsJtjdkr|dkrtd|tjdkrF|dkrFtt|sFtd|dS)zD Checks if the family is valid for the current environment. rrzFamily %s is not recognized.rN)sysplatformr%hasattrsocketr&rrr_validate_familyWs   r-cCsTt|tkrdSt|tkr*|dr*dSt|tks@t|rDdStd|dS)z] Return the types of the address This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE' rz\\rrzaddress type of %r unrecognizedN)typetuplestr startswithris_abstract_socket_namespacer%)addressrrr address_typecs r4c@seZdZdZd+ddZddZddZd d Zd d Zd dZ e ddZ e ddZ e ddZ ddZddZd,ddZddZd-ddZd.d d!Zd"d#Zd/d%d&Zd'd(Zd)d*ZdS)0_ConnectionBaseNTcCs>|}|dkrtd|s(|s(td||_||_||_dS)Nrzinvalid handlez6at least one of `readable` and `writable` must be True) __index__r%_handle _readable _writable)selfhandlereadablewritablerrr__init__ysz_ConnectionBase.__init__cCs|jdk r|dSrr7_closer:rrr__del__s z_ConnectionBase.__del__cCs|jdkrtddS)Nzhandle is closed)r7OSErrorrArrr _check_closeds z_ConnectionBase._check_closedcCs|jstddS)Nzconnection is write-only)r8rCrArrr_check_readablesz_ConnectionBase._check_readablecCs|jstddS)Nzconnection is read-only)r9rCrArrr_check_writablesz_ConnectionBase._check_writablecCs"|jrd|_n|tddS)NFzbad message length)r9r8closerCrArrr_bad_message_lengthsz#_ConnectionBase._bad_message_lengthcCs |jdkS)z True if the connection is closedNr7rArrrclosedsz_ConnectionBase.closedcCs|jS)z"True if the connection is readable)r8rArrrr<sz_ConnectionBase.readablecCs|jS)z"True if the connection is writable)r9rArrrr=sz_ConnectionBase.writablecCs||jS)z+File descriptor or handle of the connection)rDr7rArrrfilenosz_ConnectionBase.filenocCs$|jdk r z |W5d|_XdS)zClose the connectionNr?rArrrrGs  z_ConnectionBase.closercCs||t|}|jdkr.tt|}t|}|dkrFtd||krVtd|dkrh||}n&|dkrztdn|||krtd|||||dS)z,Send the bytes data from a bytes-like objectrrzoffset is negativezbuffer length < offsetNzsize is negativezbuffer length < offset + size)rDrF memoryviewitemsizebyteslenr% _send_bytes)r:bufoffsetsizemnrrr send_bytess"     z_ConnectionBase.send_bytescCs$|||t|dS)zSend a (picklable) objectN)rDrFrP_ForkingPicklerdumpsr:objrrrsendsz_ConnectionBase.sendcCsJ|||dk r(|dkr(td||}|dkrB||S)z7 Receive bytes data as a bytes object. Nrznegative maxlength)rDrEr% _recv_bytesrHgetvalue)r:Z maxlengthrQrrr recv_bytess z_ConnectionBase.recv_bytesc Cs||t|}|j}|t|}|dkr>tdn||krNtd|}|}|||krvt| | d| |||||||W5QRSQRXdS)zq Receive bytes data into a writeable bytes-like object. Return the number of bytes read. rznegative offsetzoffset too largeN) rDrErLrMrOr%r\tellr r]seekreadinto)r:rQrRrTrMZbytesizeresultrSrrrrecv_bytes_intos$        z_ConnectionBase.recv_bytes_intocCs&|||}t|S)zReceive a (picklable) object)rDrEr\rWloads getbuffer)r:rQrrrrecvsz_ConnectionBase.recvcCs||||S)z/Whether there is any input available to be read)rDrE_pollr:rrrrpollsz_ConnectionBase.pollcCs|SrrrArrr __enter__sz_ConnectionBase.__enter__cCs |dSrrGr:exc_type exc_valueZexc_tbrrr__exit__ sz_ConnectionBase.__exit__)TT)rN)N)r)rg)__name__ __module__ __qualname__r7r>rBrDrErFrHpropertyrJr<r=rKrGrVr[r^rcrfrjrkrprrrrr5vs.       r5c@sDeZdZdZdZejfddZddZddd Z d d Z d d Z dS)PipeConnectionz Connection class based on a Windows named pipe. Overlapped I/O is used, so the handles must have been created with FILE_FLAG_OVERLAPPED. FcCs||jdSrrI)r:Z _CloseHandlerrrr@szPipeConnection._closec Cstj|j|dd\}}zHz,|tjkrBt|jgdt}|tksBt Wn| YnXW5|d\}}X|dks|t |t |kst dS)NT overlappedFr) _winapiZ WriteFiler7GetOverlappedResultERROR_IO_PENDINGWaitForMultipleObjectseventrr AssertionErrorcancelrO)r:rQoverrZnwrittenwaitresrrrrPs   zPipeConnection._send_bytesNc Cs2|jrd|_tS|dkr dnt|d}ztj|j|dd\}}dzHz,|tj krpt |jgdt}|tksptWn|YnXW5|d\}}|dkrt}|| |WS|tj kr| ||WSXWn:tk r$}z|jtjkrtnW5d}~XYnXtddS)NFTrvrz.shouldn't get here; expected KeyboardInterrupt)_got_empty_messageioBytesIOminrxReadFiler7rywritereZERROR_MORE_DATA_get_more_datarzr{r|rr r}r~rCwinerrorERROR_BROKEN_PIPEEOFError RuntimeError) r:maxsizeZbsizerrZnreadfrerrrr\*s>      zPipeConnection._recv_bytescCs.|jst|jddkrdStt|g|S)NrT)rrx PeekNamedPiper7boolrrirrrrhJs zPipeConnection._pollcCs|}t}||t|jd}|dks6t|dk rVt|||krV| tj |j|dd\}}| d\}}|dkst||kst|||S)NrrTrv) rerrrrxrr7r}rOrHrry)r:rrrQrleftrZrbytesrrrrPs    zPipeConnection._get_more_data)N) rqrrrs__doc__rrx CloseHandler@rPr\rhrrrrrrus ruc@s|eZdZdZer,ejfddZejZ ej Z ne j fddZe jZ e jZ e fddZe fddZd d Zdd d ZddZd S) Connectionzo Connection class based on an arbitrary file descriptor (Unix only), or a socket handle (Windows). cCs||jdSrrIr:r@rrrr@gszConnection._closecCs||jdSrrIrrrrr@lscCs8t|}||j|}||8}|dkr&q4||d}qdSNr)rOr7)r:rQr remainingrUrrr_sendqs  zConnection._sendcCsbt}|j}|}|dkr^|||}t|}|dkrJ||krBtntd||||8}q|S)Nrzgot end of file during message)rrr7rOrrCr)r:rSreadrQr;rchunkrUrrr_recvzs   zConnection._recvcCst|}|dkrHtdd}td|}||||||n8td|}|dkrr||||n|||dS)Ni!i!Qi@)rOstructZpackr)r:rQrUZ pre_headerheaderrrrrPs        zConnection._send_bytesNcCs^|d}td|\}|dkr@|d}td|\}|dk rT||krTdS||S)Nrrr)rrZunpackr])r:rrQrSrrrr\s  zConnection._recv_bytescCst|g|}t|Sr)rr)r:rrrrrrhs zConnection._poll)N)rqrrrsrrx_multiprocessingZ closesocketr@r[Z_writerfZ_readr!rGrrrrrPr\rhrrrrr`s  rc@sReZdZdZdddZddZdd Zed d Zed d Z ddZ ddZ dS)rz Returns a listener object. This is a wrapper for a bound socket which is 'listening' for connections, or for a Windows named pipe. NrcCsp|p|rt|pt}|pt|}t||dkr>t|||_nt||||_|dk rft|tsft d||_ dS)Nrauthkey should be a byte string) r4default_familyr(r- PipeListener _listenerSocketListener isinstancerN TypeError_authkey)r:r3r'backlogauthkeyrrrr>s zListener.__init__cCs>|jdkrtd|j}|jr:t||jt||j|S)zz Accept a connection on the bound socket or named pipe of `self`. Returns a `Connection` object. Nzlistener is closed)rrCacceptrdeliver_challengeanswer_challenge)r:crrrrs    zListener.acceptcCs |j}|dk rd|_|dS)zA Close the bound socket or named pipe of `self`. N)rrG)r:ZlistenerrrrrGszListener.closecCs|jjSr)r_addressrArrrr3szListener.addresscCs|jjSr)r_last_acceptedrArrr last_acceptedszListener.last_acceptedcCs|SrrrArrrrkszListener.__enter__cCs |dSrrlrmrrrrpszListener.__exit__)NNrN) rqrrrsrr>rrGrtr3rrkrprrrrrs    cCsh|p t|}t||dkr&t|}nt|}|dk rHt|tsHtd|dk rdt||t|||S)z= Returns a connection to the address of a `Listener` rNr) r4r- PipeClient SocketClientrrNrrr)r3r'rrrrrrs    TcCsj|r>t\}}|d|dt|}t|}n$t\}}t|dd}t|dd}||fS)L Returns pair of connection objects at either end of a pipe TFr=r<)r,Z socketpair setblockingrdetachr!pipe)duplexs1s2c1c2Zfd1Zfd2rrrrs       c Cstd}|r*tj}tjtjB}tt}}ntj}tj}dt}}t||tjBtj Btj tj Btj Bd||tj tj}t||dtjtjtjtj}t|tj ddtj|dd}|d\} } | dkstt||d} t||d} | | fS) rrrrNTrvrr)r(rxPIPE_ACCESS_DUPLEX GENERIC_READ GENERIC_WRITEBUFSIZEZPIPE_ACCESS_INBOUNDCreateNamedPipeFILE_FLAG_OVERLAPPEDFILE_FLAG_FIRST_PIPE_INSTANCEPIPE_TYPE_MESSAGEPIPE_READMODE_MESSAGE PIPE_WAITNMPWAIT_WAIT_FOREVERNULL CreateFile OPEN_EXISTINGSetNamedPipeHandleStateConnectNamedPiperyr}ru) rr3ZopenmodeaccessZobsizeZibsizeZh1Zh2rw_rrrrrrrsV        c@s*eZdZdZd ddZddZddZd S) rzO Representation of a socket which is bound to an address and listening rcCsttt||_zRtjdkr2|jtjtjd|jd|j ||j ||j |_ Wn t k r|jYnX||_d|_|dkrt|stj|tj|fdd|_nd|_dS)NposixrTrrargsZ exitpriority)r,getattr_socketr!nameZ setsockoptZ SOL_SOCKETZ SO_REUSEADDRrZbindZlistenZ getsocknamerrCrGZ_familyrrr2Finalizeunlink_unlink)r:r3r'rrrrr>Ks0       zSocketListener.__init__cCs&|j\}|_|dt|S)NT)rrrrrrr:srrrrds zSocketListener.acceptcCs0z|jW5|j}|dk r*d|_|XdSr)rrrG)r:rrrrrGis zSocketListener.closeN)r)rqrrrsrr>rrGrrrrrGs rc CsPt|}ttt|.}|d||t|W5QRSQRXdS)zO Return a connection object connected to the socket given by `address` TN)r4r,rrZconnectrr)r3r'rrrrrss   rc@s8eZdZdZd ddZd ddZdd Zed d ZdS)rz0 Representation of a named pipe NcCsL||_|jddg|_d|_td|jtj|tj|j|jfdd|_ dS)NT)firstz listener created with address=%rrr) r _new_handle _handle_queuerr sub_debugrr_finalize_pipe_listenerrG)r:r3rrrrr>s zPipeListener.__init__Fc CsHtjtjB}|r|tjO}t|j|tjtjBtjBtj t t tj tj Sr) rxrrrrrrrrZPIPE_UNLIMITED_INSTANCESrrr)r:rflagsrrrrs   zPipeListener._new_handlec Cs|j||jd}ztj|dd}Wn0tk r^}z|jtjkrNW5d}~XYn\Xzrr staticmethodrrrrrrs  rc Cst}z6t|dt|tjtjBdtjtjtjtj}Wqt k rz}z |j tj tj fksht |rjW5d}~XYqXqqt|tjddt|S)zU Return a connection object connected to the pipe given by `address` rN)rrxZ WaitNamedPiperrrrrrrCrZERROR_SEM_TIMEOUTZERROR_PIPE_BUSYrrrru)r3rhrrrrrs8  rs #CHALLENGE#s #WELCOME#s #FAILURE#cCsddl}t|ts$tdt|tt}| t || ||t  }|d}||krl| tn| ttddS)Nr Authkey must be bytes, not {0!s}zdigest received was wrong)hmacrrNr%formatr.r!urandomMESSAGE_LENGTHrV CHALLENGEnewHMAC_DIGEST_NAMEdigestr^WELCOMEFAILURErZ connectionrrmessagerZresponserrrrs      rcCsddl}t|ts$tdt||d}|dtttksNt d||ttd}| ||t  }| ||d}|tkrtddS)Nrrrz message = %rzdigest sent was rejected)rrrNr%rr.r^rOrr}rrrrVrrrrrrrs      rc@s$eZdZddZddZddZdS)ConnectionWrappercCs6||_||_||_dD]}t||}t|||qdS)N)rKrGrjr^rV)_conn_dumps_loadsrsetattr)r:connrXrdattrrZrrrr>s  zConnectionWrapper.__init__cCs||}|j|dSr)rrrV)r:rZrrrrr[ s zConnectionWrapper.sendcCs|j}||Sr)rr^rrrrrrf s zConnectionWrapper.recvN)rqrrrsr>r[rfrrrrrsrcCst|fdddddS)Nrutf-8) xmlrpclibrXencode)rZrrr _xml_dumpssrcCst|d\\}}|S)Nr)rrddecode)rrZmethodrrr _xml_loadssr c@seZdZddZdS) XmlListenercCs"ddlmat|}t|ttSr) xmlrpc.clientclientrrrrrr rYrrrrs  zXmlListener.acceptN)rqrrrsrrrrrr sr cOsddlmatt||ttSr)r r rrrrr )rkwdsrrr XmlClients rcCst|}g}|rt|d|}|tkr*qn\t|krFtt|krTnn |t8}n2t|krptt|kr~nn |t8}ntd|||||dd}d}q |S)NFzShould not get hererr) listrxr{r r rOr rr)ZhandlesrLreadyrrrr_exhaustive_wait)s    rc s^|dkrt}n|dkrd}nt|dd}t|}ig}tt}z@|D]&}zt|d} Wn tk r||<YqPXzt | dd\}}Wn8tk r}zd|j}}|tkrƂW5d}~XYnX|t jkr||||j <qP|rjtddd krjz|d \}}Wn*tk rP}z |j}W5d}~XYnX|sjt |drjd|_ |d}qPt|}W5|D]}|q|D]}z|d\}}Wn6tk r}z|j}|tkrW5d}~XYnX|t j kr|j } ||dkrt |drd|_qXfd d |Dfd d|DS) Wait till an object in object_list is ready/readable. Returns list of those objects in object_list which are ready/readable. Nrrg?TrrK)rFc3s|]}|VqdSrr).0r)waithandle_to_objrr szwait..csg|]}|kr|qSrr)ro) ready_objectsrr swait..)rintrsetr~ryrCr _ready_errorsrxZERROR_OPERATION_ABORTEDr|addr+rrAttributeErrorr6rrzrr)Zgetwindowsversionrkeysupdate) object_listrZov_listZ ready_handlesrrrrrrKr)rrrr?sh               PollSelectorc Cst}|D]}||tjq |dk r4t|}||}|r\dd|DW5QRS|dk r4|t}|dkr4|W5QRSq4W5QRXdS)rNcSsg|]\}}|jqSr)Zfileobj)rkeyZeventsrrrrsrr) _WaitSelectorregister selectorsZ EVENT_READrrZselect)r%rZselectorrZZdeadlinerrrrrs   c CsZ|}t|tjtj6}ddlm}||}t||j |j ffW5QRSQRXdS)Nr)resource_sharer) rKr,ZfromfdrZ SOCK_STREAMrr+Z DupSocketrebuild_connectionr<r=)rr;rr+dsrrrreduce_connections   r.cCs|}t|||Srrr)r-r<r=Zsockrrrr,sr,cCsB|jr tjnd|jrtjndB}t||}t||j|jffSr) r<rxZFILE_GENERIC_READr=ZFILE_GENERIC_WRITEr Z DupHandlerKrebuild_pipe_connection)rrdhrrrreduce_pipe_connections r2cCs|}t|||Sr)rru)r1r<r=r;rrrr0sr0cCs t|}t||j|jffSr)r ZDupFdrKr,r<r=)rdfrrrr.scCs|}t|||Srr/)r3r<r=fdrrrr,s)NN)T)T)N)N)J__all__rr!r)r,rrr itertoolsrrrrr contextr ZForkingPicklerrWrxr r r r ImportErrorr*rZCONNECTION_TIMEOUTrcountr$rZfamiliesr+rrr(r-r4r5rurobjectrrrrrrrrrrrrrrrr r rrrZERROR_NETNAME_DELETEDr rr*r&r(ZSelectSelectorr.r,r)r2r0rrrr s           PT=    ,, 8   P