3 /fVy @s ddddgZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z m Z dd lmZejZy$ddlZdd lmZmZmZmZWn$ek rejd kr‚dZYnXd Zd ZdZejZdZdgZe 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 krdFdGZEdHdIZFejGe(eEdJdKZHdLdMZIejGe'eHndNdGZEdOdIZFejGe(eEdS)UClientListenerPipewaitN)util)AuthenticationErrorBufferTooShort) reduction) WAIT_OBJECT_0WAIT_ABANDONED_0 WAIT_TIMEOUTINFINITEwin32i g4@Zsha256AF_INETAF_UNIXAF_PIPEcCs tj|S)N)time monotonic)timeoutr2/usr/lib64/python3.6/multiprocessing/connection.py _init_timeout?srcCs tj|kS)N)rr)trrr_check_timeoutBsrcCsX|dkr d S|dkr&tjdtjdS|dkrLtjdtjttfd dStd dS) Nr localhostrrz listener-)prefixdirrz\\.\pipe\pyc-%d-%d-zunrecognized family)rr) tempfileZmktemprZ get_temp_dirosgetpidnext _mmap_counter ValueError)familyrrrarbitrary_addressIsr&cCsJtjdkr|dkrtd|tjdkrF|dkrFtt|sFtd|dS)NrrzFamily %s is not recognized.r)sysplatformr$hasattrsocket)r%rrr_validate_familyWs   r+cCsJt|tkrdSt|tkr*|jdr*dSt|tkr:dStd|dS)Nrz\\rrzaddress type of %r unrecognized)typetuplestr startswithr$)addressrrr address_typecs  r1c@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_ConnectionBaseNTcCsB|j}|dkrtd| r,| r,td||_||_||_dS)Nrzinvalid handlez6at least one of `readable` and `writable` must be True) __index__r$_handle _readable _writable)selfhandlereadablewritablerrr__init__ys z_ConnectionBase.__init__cCs|jdk r|jdS)N)r4_close)r7rrr__del__s z_ConnectionBase.__del__cCs|jdkrtddS)Nzhandle is closed)r4OSError)r7rrr _check_closeds z_ConnectionBase._check_closedcCs|jstddS)Nzconnection is write-only)r5r>)r7rrr_check_readablesz_ConnectionBase._check_readablecCs|jstddS)Nzconnection is read-only)r6r>)r7rrr_check_writablesz_ConnectionBase._check_writablecCs"|jrd|_n|jtddS)NFzbad message length)r6r5closer>)r7rrr_bad_message_lengthsz#_ConnectionBase._bad_message_lengthcCs |jdkS)N)r4)r7rrrclosedsz_ConnectionBase.closedcCs|jS)N)r5)r7rrrr9sz_ConnectionBase.readablecCs|jS)N)r6)r7rrrr:sz_ConnectionBase.writablecCs|j|jS)N)r?r4)r7rrrfilenosz_ConnectionBase.filenoc Cs$|jdk r z |jWdd|_XdS)N)r4r<)r7rrrrBs  z_ConnectionBase.closercCs|j|jt|}|jdkr.tt|}t|}|dkrFtd||krVtd|dkrh||}n&|dkrztdn|||krtd|j||||dS)Nrrzoffset is negativezbuffer length < offsetzsize is negativezbuffer length < offset + size)r?rA memoryviewitemsizebyteslenr$ _send_bytes)r7bufoffsetsizemnrrr send_bytess"     z_ConnectionBase.send_bytescCs$|j|j|jtj|dS)N)r?rArJ_ForkingPicklerdumps)r7objrrrsendsz_ConnectionBase.sendcCsJ|j|j|dk r(|dkr(td|j|}|dkrB|j|jS)Nrznegative maxlength)r?r@r$ _recv_bytesrCgetvalue)r7Z maxlengthrKrrr recv_bytess z_ConnectionBase.recv_bytesc Cs|j|jt|}|j}|t|}|dkr>tdn||krNtd|j}|j}|||krvt|j |j d|j |||||||SQRXdS)Nrznegative offsetzoffset too large) r?r@rFrGrIr$rUtellr rVseekreadinto)r7rKrLrNrGZbytesizeresultrMrrrrecv_bytes_intos"       z_ConnectionBase.recv_bytes_intocCs&|j|j|j}tj|jS)N)r?r@rUrQloads getbuffer)r7rKrrrrecvsz_ConnectionBase.recvcCs|j|j|j|S)N)r?r@_poll)r7rrrrpollsz_ConnectionBase.pollcCs|S)Nr)r7rrr __enter__sz_ConnectionBase.__enter__cCs |jdS)N)rB)r7exc_type exc_valueexc_tbrrr__exit__ sz_ConnectionBase.__exit__)TT)rN)N)r)r`)__name__ __module__ __qualname__r4r;r=r?r@rArCpropertyrDr9r:rErBrPrTrWr\r_rbrcrgrrrrr2vs(       r2c@s@eZdZdZejfddZddZd ddZd d Z d d Z dS)PipeConnectionFcCs||jdS)N)r4)r7Z _CloseHandlerrrr<szPipeConnection._closecCshtj|j|dd\}}zwinerrorERROR_BROKEN_PIPEEOFError RuntimeError) r7maxsizeZbsizertrurvZnreadferrrrU*s6      zPipeConnection._recv_bytescCs.|jstj|jddkrdStt|g|S)NrT)rxrn PeekNamedPiper4boolr)r7rrrrraJszPipeConnection._pollcCs|j}tj}|j|tj|jd}|dk rJt|||krJ|jtj |j|dd\}}|j d\}}|j|j|S)NrT)rm) r^ryrzr}rnrr4rIrCr|rs)r7rtrrKrleftruZrbytesrrrr~Ps zPipeConnection._get_more_data)N) rhrirjrxrn CloseHandler<rJrUrar~rrrrrls  rlc@sxeZdZer(ejfddZejZej Z ne j fddZe j Ze jZ efddZe fddZdd Zdd d Zd dZd S) ConnectioncCs||jdS)N)r4)r7r<rrrr<gszConnection._closecCs||jdS)N)r4)r7r<rrrr<lscCs<t|}x.||j|}||8}|dkr(P||d}q WdS)Nr)rIr4)r7rKr} remainingrOrrr_sendqs zConnection._sendcCsftj}|j}|}xN|dkr`|||}t|}|dkrL||krDtntd|j|||8}qW|S)Nrzgot end of file during message)ryrzr4rIrr>r})r7rMreadrKr8rchunkrOrrr_recvzs    zConnection._recvcCsDt|}tjd|}|dkr2|j||j|n|j||dS)Nz!ii@)rIstructZpackr)r7rKrOheaderrrrrJs    zConnection._send_bytesNcCs:|jd}tjd|j\}|dk r0||kr0dS|j|S)Nz!i)rrZunpackrV)r7rrKrMrrrrUs  zConnection._recv_bytescCst|g|}t|S)N)rr)r7rrrrrras zConnection._poll)N)rhrirjrn_multiprocessingZ closesocketr<rTZ_writer_Z_readr rBr}rrrrJrUrarrrrr`s  rc@sNeZdZdddZddZddZed d Zed d Zd d Z ddZ dS)rNrcCsr|p|rt|pt}|pt|}t||dkr>t|||_nt||||_|dk rht|t rht d||_ dS)Nrzauthkey should be a byte string) r1default_familyr&r+ PipeListener _listenerSocketListener isinstancerH TypeError_authkey)r7r0r%backlogauthkeyrrrr;s zListener.__init__cCs>|jdkrtd|jj}|jr:t||jt||j|S)Nzlistener is closed)rr>acceptrdeliver_challengeanswer_challenge)r7crrrrs    zListener.acceptcCs |j}|dk rd|_|jdS)N)rrB)r7ZlistenerrrrrBszListener.closecCs|jjS)N)r_address)r7rrrszListener.cCs|jjS)N)r_last_accepted)r7rrrrscCs|S)Nr)r7rrrrcszListener.__enter__cCs |jdS)N)rB)r7rdrerfrrrrgszListener.__exit__)NNrN) rhrirjr;rrBrkr0Z last_acceptedrcrgrrrrrs   cCsj|p t|}t||dkr&t|}nt|}|dk rJt|t rJtd|dk rft||t|||S)Nrzauthkey should be a byte string) r1r+ PipeClient SocketClientrrHrrr)r0r%rrrrrrs    TcCsj|r>tj\}}|jd|jdt|j}t|j}n$tj\}}t|dd}t|dd}||fS)NTF)r:)r9)r*Z socketpair setblockingrdetachr pipe)duplexs1s2c1c2Zfd1Zfd2rrrrs       c Cstd}|r*tj}tjtjB}tt}}ntj}tj}dt}}tj||tjBtj Btj tj Btj Bd||tj tj}tj||dtjtjtjtj}tj|tj ddtj|dd}|jd\} } t||d} t||d} | | fS)NrrrT)rm)r:)r9)r&rnPIPE_ACCESS_DUPLEX GENERIC_READ GENERIC_WRITEBUFSIZEZPIPE_ACCESS_INBOUNDCreateNamedPipeFILE_FLAG_OVERLAPPEDFILE_FLAG_FIRST_PIPE_INSTANCEPIPE_TYPE_MESSAGEPIPE_READMODE_MESSAGE PIPE_WAITNMPWAIT_WAIT_FOREVERNULL CreateFile OPEN_EXISTINGSetNamedPipeHandleStateConnectNamedPipersrl) rr0ZopenmodeaccessZobsizeZibsizeZh1Zh2rm_rurrrrrr s2         c@s&eZdZd ddZddZddZdS) rrcCstjtt||_yRtjdkr2|jjtjtjd|jjd|jj ||jj ||jj |_ Wn t k r|jjYnX||_d|_|dkrtj|tj|fdd|_nd|_dS)NposixrTrr)args exitpriority)r*getattr_socketr nameZ setsockoptZ SOL_SOCKETZ SO_REUSEADDRrZbindZlistenZ getsocknamerr>rBZ_familyrrFinalizeunlink_unlink)r7r0r%rrrrr;<s$       zSocketListener.__init__cCs&|jj\}|_|jdt|jS)NT)rrrrrr)r7srrrrTs zSocketListener.acceptc Cs0z|jjWd|j}|dk r*d|_|XdS)N)rrBr)r7rrrrrBYs zSocketListener.closeN)r)rhrirjr;rrBrrrrr8s rc CsDt|}tjtt|"}|jd|j|t|jSQRXdS)NT)r1r*rrZconnectrr)r0r%rrrrrcs   rc@s4eZdZd ddZd ddZddZed d ZdS) rNcCsL||_|jddg|_d|_tjd|jtj|tj|j|jfdd|_ dS)NT)firstz listener created with address=%rr)rr) r _new_handle _handle_queuerr sub_debugrr_finalize_pipe_listenerrB)r7r0rrrrr;wszPipeListener.__init__Fc CsHtjtjB}|r|tjO}tj|j|tjtjBtjBtj t t tj tj S)N) rnrrrrrrrrZPIPE_UNLIMITED_INSTANCESrrr)r7rflagsrrrrs   zPipeListener._new_handlecCs|jj|j|jjd}ytj|dd}Wn0tk r^}z|jtjkrNWYdd}~XnPXzrZ ERROR_NO_DATArprqrrrrrsrl)r7r8rtrresrrurrrrs"    zPipeListener.acceptcCs(tjd|x|D]}tj|qWdS)Nz closing listener with address=%r)rrrnr)Zqueuer0r8rrrrs  z$PipeListener._finalize_pipe_listener)N)F)rhrirjr;rr staticmethodrrrrrrss rcCst}x~y6tj|dtj|tjtjBdtjtjtjtj}Wn>t k r|}z"|j tj tj fksjt |rlWYdd}~XqXPqWtj|tjddt|S)Nir)rrnZ WaitNamedPiperrrrrrr>rZERROR_SEM_TIMEOUTZERROR_PIPE_BUSYrrrrl)r0rhrrrrrs"   rs #CHALLENGE#s #WELCOME#s #FAILURE#cCsfddl}tjt}|jt||j||tj}|j d}||krP|jt n|jt t ddS)Nrzdigest received was wrong) hmacr urandomMESSAGE_LENGTHrP CHALLENGEnewHMAC_DIGEST_NAMEdigestrWWELCOMEFAILUREr) connectionrrmessagerresponserrrrs    rcCs\ddl}|jd}|ttd}|j||tj}|j||jd}|tkrXt ddS)Nrrzdigest sent was rejected) rrWrIrrrrrPrr)rrrrrrrrrrs   rc@s$eZdZddZddZddZdS)ConnectionWrappercCs:||_||_||_x"dD]}t||}t|||qWdS)NrErBrbrWrP)rErBrbrWrP)_conn_dumps_loadsrsetattr)r7connrRr]attrrSrrrr;s   zConnectionWrapper.__init__cCs|j|}|jj|dS)N)rrrP)r7rSrrrrrTs zConnectionWrapper.sendcCs|jj}|j|S)N)rrWr)r7rrrrr_s zConnectionWrapper.recvN)rhrirjr;rTr_rrrrrsrcCstj|fddddjdS)Nrzutf-8) xmlrpclibrRencode)rSrrr _xml_dumpssrcCstj|jd\\}}|S)Nzutf-8)rr]decode)rrSmethodrrr _xml_loadssrc@seZdZddZdS) XmlListenercCs ddljatj|}t|ttS)Nr) xmlrpc.clientclientrrrrrr)r7rSrrrrs  zXmlListener.acceptN)rhrirjrrrrrrsrcOsddljatt||ttS)Nr)rrrrrrr)rkwdsrrr XmlClient s rcCst|}g}x|rtj|d|}|tkr,Pn\t|koFtt|knrV|t8}n2t|koptt|knr|t8}ntd|j||||dd}d}qW|S)NFzShould not get hererr) listrnrpr r rIr rr)ZhandlesrLreadyrrrr_exhaustive_waits    rc .sn|dkrt}n|dkrd}nt|dd}t|}ig}tt}zHx2|D](}yt|d}Wn tk r||j<YqTXytj|dd\}}Wn8t k r}zd|j }}|t krʂWYdd}~XnX|tj kr|j |||j<qT|rptjdddkrpy|jd\} }Wn*t k rT}z |j }WYdd}~XnX| rpt|d rpd|_j|d}qTWtj|}Wdx|D]}|jqWx|D]}y|jd\} }Wn6t k r}z|j }|t krWYdd}~XnX|tjkr|j}j||dkrt|d rd|_qWXjfd d |Dfd d |DS)Nrig?rETFrxc3s|]}|VqdS)Nr).0r)waithandle_to_objrr vszwait..csg|]}|kr|qSrr)ro) ready_objectsrr wszwait..)rr)rintrsetrAttributeErrorr3rnr|r>r _ready_errorsrorrqr'Zgetwindowsversionrsr)rxaddrkeysrrZERROR_OPERATION_ABORTEDupdate) object_listrZov_listZ ready_handlesrrErtrurrr)rrrr+sh              PollSelectorc Cstx}x|D]}|j|tjqW|dk r8tj|}x@|j|}|rVdd|DS|dk r:|tj}|dkr:|Sq:WWdQRXdS)NcSsg|]\}}|jqSr)Zfileobj)rkeyZeventsrrrrszwait..r) _WaitSelectorregister selectorsZ EVENT_READrrZselect)r rZselectorrSZdeadlinerrrrrs    c CsN|j}tj|tjtj*}ddlm}|j|}t||j |j ffSQRXdS)Nr)resource_sharer) rEr*ZfromfdrZ SOCK_STREAMrrZ DupSocketrebuild_connectionr9r:)rr8rrdsrrrreduce_connections   rcCs|j}t|j||S)N)rr)rr9r:ZsockrrrrsrcCsB|jr tjnd|jrtjndB}tj|j|}t||j|jffS)Nr) r9rnZFILE_GENERIC_READr:ZFILE_GENERIC_WRITEr Z DupHandlerErebuild_pipe_connection)rrdhrrrreduce_pipe_connectionsrcCs|j}t|||S)N)rrl)rr9r:r8rrrrsrcCs tj|j}t||j|jffS)N)r ZDupFdrErr9r:)rdfrrrrscCs|j}t|||S)N)rr)rr9r:fdrrrrs)NN)T)T)N)N)J__all__ryr r'r*rrr itertoolsrrrrr contextr ZForkingPicklerrQrnr r r r ImportErrorr(rZCONNECTION_TIMEOUTrcountr#rZfamiliesr)rrr&r+r1r2rlrobjectrrrrrrrrrrrrrrrrrrrrZERROR_NETNAME_DELETEDrrrr r ZSelectSelectorrrr rrrrrr s           PJ8    ,+ 8    P