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 dS) Nr)Z localhostrrz listener-)prefixdirrz\\.\pipe\pyc-%d-%d-zunrecognized family) tempfileZmktemprZ get_temp_dirosgetpidnext _mmap_counter ValueErrorfamilyrrrarbitrary_addressIsr(cCsJtjdkr|dkrtd|tjdkrF|dkrFtt|sFtd|dS)NrrzFamily %s is not recognized.r)sysplatformr%hasattrsocketr&rrr_validate_familyWs   r-cCsTt|tkrdSt|tkr*|dr*dSt|tks@t|rDdStd|dS)Nrz\\rrzaddress type of %r unrecognized)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 |jdkSrr7rArrrclosedsz_ConnectionBase.closedcCs|jSr)r8rArrrr<sz_ConnectionBase.readablecCs|jSr)r9rArrrr=sz_ConnectionBase.writablecCs||jSr)rDr7rArrrfilenosz_ConnectionBase.filenocCs$|jdk r z |W5d|_XdSrr?rArrrrGs  z_ConnectionBase.closercCs||t|}|jdkr.tt|}t|}|dkrFtd||krVtd|dkrh||}n&|dkrztdn|||krtd|||||dS)Nrrzoffset is negativezbuffer length < offsetzsize is negativezbuffer length < offset + size)rDrF memoryviewitemsizebyteslenr% _send_bytes)r:bufoffsetsizemnrrr send_bytess"     z_ConnectionBase.send_bytescCs$|||t|dSr)rDrFrP_ForkingPicklerdumpsr:objrrrsendsz_ConnectionBase.sendcCsJ|||dk r(|dkr(td||}|dkrB||S)Nrznegative maxlength)rDrEr% _recv_bytesrHgetvalue)r:Z maxlengthrQrrr recv_bytess z_ConnectionBase.recv_bytesc Cs||t|}|j}|t|}|dkr>tdn||krNtd|}|}|||krvt| | d| |||||||W5QRSQRXdS)Nrznegative offsetzoffset too large) rDrErLrMrOr%r\tellr r]seekreadinto)r:rQrRrTrMZbytesizeresultrSrrrrecv_bytes_intos$        z_ConnectionBase.recv_bytes_intocCs&|||}t|Sr)rDrEr\rWloads getbuffer)r:rQrrrrecvsz_ConnectionBase.recvcCs||||Sr)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@s@eZdZdZejfddZddZd ddZd d Z d d Z dS)PipeConnectionFcCs||jdSrrI)r:Z _CloseHandlerrrr@szPipeConnection._closec Cshtj|j|dd\}}z      zPipeConnection._recv_bytescCs.|jst|jddkrdStt|g|S)NrT)rrx PeekNamedPiper7boolrrirrrrhJs zPipeConnection._pollcCs|}t}||t|jd}|dk rJt|||krJ|tj |j|dd\}}| d\}}|||S)NrTrv) rerrrrxrr7rOrHrry)r:r~rrQrleftrZrbytesrrrrPs zPipeConnection._get_more_data)N) rqrrrsrrx CloseHandler@rPr\rhrrrrrrus  ruc@sxeZdZer(ejfddZejZej Z ne j fddZe j Ze jZ efddZe fddZdd Zdd d Zd dZd S) ConnectioncCs||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)rqrrrsrx_multiprocessingZ closesocketr@r[Z_writerfZ_readr!rGrrrrrPr\rhrrrrr`s  rc@sNeZdZdddZddZddZed d Zed d Zd dZ ddZ dS)rNrcCsp|p|rt|pt}|pt|}t||dkr>t|||_nt||||_|dk rft|tsft d||_ dSNrzauthkey 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)Nzlistener is closed)rrCacceptrdeliver_challengeanswer_challenge)r:crrrrs    zListener.acceptcCs |j}|dk rd|_|dSr)rrG)r:ZlistenerrrrrGszListener.closecCs|jjSr)r_addressrArrrr3szListener.addresscCs|jjSr)r_last_acceptedrArrr last_acceptedszListener.last_acceptedcCs|SrrrArrrrkszListener.__enter__cCs |dSrrlrmrrrrpszListener.__exit__)NNrN) rqrrrsr>rrGrtr3rrkrprrrrrs    cCsh|p t|}t||dkr&t|}nt|}|dk rHt|tsHtd|dk rdt||t|||Sr) r4r- PipeClient SocketClientrrNrrr)r3r'rrrrrrs    TcCsj|r>t\}}|d|dt|}t|}n$t\}}t|dd}t|dd}||fS)NTFr=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\} } t||d} t||d} | | fS)NrrrTrvrr)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_EXISTINGSetNamedPipeHandleStateConnectNamedPiperyru) rr3ZopenmodeaccessZobsizeZibsizeZh1Zh2rw_rrrrrrrsT       c@s&eZdZd ddZddZddZdS) rrcCsttt||_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|SNT)rrrrrrr:srrrrds zSocketListener.acceptcCs0z|jW5|j}|dk r*d|_|XdSr)rrrG)r:rrrrrGis zSocketListener.closeN)r)rqrrrsr>rrGrrrrrGs rc CsPt|}ttt|.}|d||t|W5QRSQRXdSr)r4r,rrZconnectrr)r3r'rrrrrss   rc@s4eZdZd ddZd ddZddZed d ZdS) rNcCsL||_|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}~XYnPXzrr staticmethodrrrrrrs  rc Cst}z6t|dt|tjtjBdtjtjtjtj}Wqt k rz}z |j tj tj fksht |rjW5d}~XYqXqqt|tjddt|S)Nr)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      rcCsxddl}t|ts$tdt||d}|ttd}| ||t  }| ||d}|t krttddS)Nrrrzdigest sent was rejected)rrrNr%rr.r^rOrrrrrVrrrrrrrs     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_loadssrc@seZdZddZdS) XmlListenercCs"ddlmat|}t|ttSr) xmlrpc.clientclientrrrrrrrYrrrrs  zXmlListener.acceptN)rqrrrsrrrrrr sr cOsddlmatt||ttSr)r r rrrrr)rkwdsrrr XmlClients r cCst|}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|rjtdddkrjz|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)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_handlesr~rrrrrKr)rrrr?sh               PollSelectorc Cst}|D]}||tjq |dk r4t|}||}|r\dd|DW5QRS|dk r4|t}|dkr4|W5QRSq4W5QRXdS)NcSsg|]\}}|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 r/cCs|}t|||Sr)rru)r.r<r=r;rrrr-sr-cCs t|}t||j|jffSr)r ZDupFdrKr)r<r=)rdfrrrr+scCs|}t|||Srr,)r0r<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-r4r5rurobjectrrrrrrrrrrrrrrrrr r rrZERROR_NETNAME_DELETEDrrr'r#r%ZSelectSelectorr+r)r&r/r-rrrr s           PT=    ,, 8   P