
    h                     ,   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrSSK	J
r
  SSK	Jr  SSK	JrJr  SSKJr  SSKJrJr  S SKJr  SS	K
Jr   SS
KJr  \R.                  S:X  a0  \R0                  r\R2                  r\R4                  r\R6                  r/ SQr\" \S5      rSr Sr!\RD                  " 5       r#Sr$S/r%\" \S5      (       a  Sr$\%S/-  r%\R.                  S:X  a  Sr$\%S/-  r%\!4S jr&S r'S r(S r)S r* " S S5      r+ " S S5      r,\(       a   " S S\,5      r- " S S\,5      r. " S  S!5      r/SES" jr0S# r1\R.                  S:w  a  SFS$ jr2OSFS% jr2 " S& S'5      r3S( r4\R.                  S:X  a&   " S) S*5      r5\Rl                  \Rn                  44S+ jr8S,r9S-r:S.r;S/r<S0 r=S1 r> " S2 S35      r?S4 r@S5 rA " S6 S7\/5      rBS8 rC\R.                  S:X  a!  S9 rD\R                  \R                  1rGSGS: jrHO\" \S;5      (       a  S< rIOS= rISGS> jrH\R.                  S:X  a3  S? rJS@ rK\
R                  " \.\J5        SA rMSB rN\
R                  " \-\M5        gSC rJSD rK\
R                  " \.\J5        g! \ a    \R.                  S:X  a  e Sr GNf = f)H    N   )	reduction)util)AuthenticationErrorBufferTooShort)	_billiard)setblockingsend_offset	monotonic)ForkingPickler)_winapiwin32)ClientListenerPipewaitpypy_version_infoi    g      4@AF_INETAF_UNIXAF_PIPEc                     [        5       U -   $ Nr   )timeouts    ;D:\TimeStamps\venv\Lib\site-packages\billiard/connection.py_init_timeoutr   E   s    ;      c                     [        5       U :  $ r   r   )ts    r   _check_timeoutr    I   s    ;?r   c                    U S:X  a  gU S:X  a(  [         R                  " S[        R                  " 5       S9$ U S:X  a:  [         R                  " S[        R
                  " 5       [        [        5      4-  SS9$ [        S	5      e)
z7
Return an arbitrary free address for the given family
r   )	localhostr   r   z	listener-)prefixdirr   z\\.\pipe\pyc-%d-%d- zunrecognized family)	tempfilemktempr   get_temp_dirosgetpidnext_mmap_counter
ValueErrorfamilys    r   arbitrary_addressr0   Q   sy     	9	kt7H7H7JKK	9	&< "		T--@A'BGIK 	K .//r   c                     [         R                  S:w  a  U S:X  a  [        SU -  5      e[         R                  S:X  a+  U S:X  a$  [        [        U 5      (       d  [        SU -  5      eggg)z<
Checks if the family is valid for the current environment.
r   r   zFamily %s is not recognized.r   N)sysplatformr-   hasattrsocketr.   s    r   _validate_familyr6   `   sf     ||w6Y#67&@AA
||w6Y#6vv&&;fDEE ' $7r   c                     [        U 5      [        :X  a  g[        U 5      [        L a  U R                  S5      (       a  g[        U 5      [        L a  g[	        SU -  5      e)zQ
Return the types of the address

This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
r   z\\r   r   zaddress type of %r unrecognized)typetuplestr
startswithr-   )addresss    r   address_typer=   m   sR     G}	g#	'"4"4V"<"<	g#	:WDEEr   c                       \ rS rSrS rSrg)_SocketContainer   c                     Xl         g r   sock)selfrC   s     r   __init___SocketContainer.__init__   s    	r   rB   N)__name__
__module____qualname____firstlineno__rE   __static_attributes__ r   r   r?   r?      s    r   r?   c                       \ rS rSrSrSS jrS rS rS rS r	S r
\S	 5       r\S
 5       r\S 5       rS rS rSS jrS rSS jrSS jrS rSS jrS rS rS rS rSrg)_ConnectionBase   Nc                    [        U[        5      (       a+  UR                  U l        UR                  R	                  5       nUR                  5       nUS:  a  [        S5      eU(       d  U(       d  [        S5      eXl        X l        X0l	        g )Nr   zinvalid handlez6at least one of `readable` and `writable` must be True)

isinstancer?   rC   _socketfileno	__index__r-   _handle	_readable	_writable)rD   handlereadablewritables       r   rE   _ConnectionBase.__init__   st    f.//!;;DL[['')F!!#A:-..HJ J!!r   c                 @    U R                   b  U R                  5         g g r   rU   _closerD   s    r   __del___ConnectionBase.__del__   s    <<#KKM $r   c                 4    U R                   c  [        S5      eg )Nzhandle is closed)rU   OSErrorr_   s    r   _check_closed_ConnectionBase._check_closed   s    <<,--  r   c                 <    U R                   (       d  [        S5      eg )Nzconnection is write-only)rV   rc   r_   s    r   _check_readable_ConnectionBase._check_readable   s    ~~455 r   c                 <    U R                   (       d  [        S5      eg )Nzconnection is read-only)rW   rc   r_   s    r   _check_writable_ConnectionBase._check_writable   s    ~~344 r   c                 j    U R                   (       a  SU l        OU R                  5         [        S5      e)NFzbad message length)rW   rV   closerc   r_   s    r   _bad_message_length#_ConnectionBase._bad_message_length   s%    >>"DNJJL*++r   c                     U R                   SL $ )z True if the connection is closedNrU   r_   s    r   closed_ConnectionBase.closed   s     ||t##r   c                     U R                   $ )z"True if the connection is readable)rV   r_   s    r   rY   _ConnectionBase.readable        ~~r   c                     U R                   $ )z"True if the connection is writable)rW   r_   s    r   rZ   _ConnectionBase.writable   rv   r   c                 :    U R                  5         U R                  $ )z+File descriptor or handle of the connection)rd   rU   r_   s    r   rS   _ConnectionBase.fileno   s    ||r   c                 h    U R                   b   U R                  5         SU l         gg! SU l         f = f)zClose the connectionNr]   r_   s    r   rm   _ConnectionBase.close   s1    <<#$#	 $  $s   ( 	1c                 |   U R                  5         U R                  5         [        U5      nUR                  S:  a  [        [	        U5      5      n[        U5      nUS:  a  [        S5      eXR:  a  [        S5      eUc  XR-
  nO$US:  a  [        S5      eX#-   U:  a  [        S5      eU R                  XBX#-    5        g)z,Send the bytes data from a bytes-like objectr   r   zoffset is negativezbuffer length < offsetNzsize is negativezbuffer length < offset + size)rd   rj   
memoryviewitemsizebyteslenr-   _send_bytes)rD   bufoffsetsizemns         r   
send_bytes_ConnectionBase.send_bytes   s    sO::>58$AFA:122:566<:DAX/00]Q<==&-01r   c                     U R                  5         U R                  5         U R                  [        R                  " U5      5        g)zSend a (picklable) objectN)rd   rj   r   r   dumpsrD   objs     r   send_ConnectionBase.send   s3    --c23r   c                     U R                  5         U R                  5         Ub  US:  a  [        S5      eU R                  U5      nUc  U R	                  5         UR                  5       $ )z'
Receive bytes data as a bytes object.
r   znegative maxlength)rd   rg   r-   _recv_bytesrn   getvalue)rD   	maxlengthr   s      r   
recv_bytes_ConnectionBase.recv_bytes   sa     	 Y]122y);$$&||~r   c                    U R                  5         U R                  5         [        U5       nUR                  nU[	        U5      -  nUS:  a  [        S5      eX%:  a  [        S5      eU R                  5       nUR                  5       nXRU-   :  a  [        UR                  5       5      eUR                  S5        UR                  UX$-  X'-   U-   5        UsSSS5        $ ! , (       d  f       g= f)zY
Receive bytes data into a writeable bytes-like object.
Return the number of bytes read.
r   znegative offsetzoffset too largeN)rd   rg   r~   r   r   r-   r   tellr   r   seekreadinto)rD   r   r   r   r   bytesizeresultr   s           r   recv_bytes_into_ConnectionBase.recv_bytes_into   s    
 	_zzH#a&(Hz !233" !344%%'F;;=D4-'$V__%677KKNOOA"FMh#>  # __s   B*C  
C.c                     U R                  5         U R                  5         U R                  5       n[        R                  " U5      $ )zReceive a (picklable) object)rd   rg   r   r   loadbuf)rD   r   s     r   recv_ConnectionBase.recv  s9     %%c**r   c                 d    U R                  5         U R                  5         U R                  U5      $ )z/Whether there is any input available to be read)rd   rg   _pollrD   r   s     r   poll_ConnectionBase.poll  s)    zz'""r   c                     U $ r   rL   r_   s    r   	__enter___ConnectionBase.__enter__      r   c                 $    U R                  5         g r   rm   rD   exc_type	exc_valueexc_tbs       r   __exit___ConnectionBase.__exit__      

r   c                 6    [        U R                  5       X5      $ r   )r
   rS   )rD   r   r   s      r   r
   _ConnectionBase.send_offset"  s    4;;=#66r   c                 8    [        U R                  5       U5        g r   )r	   rS   )rD   blockings     r   r	   _ConnectionBase.setblocking%  s    DKKM8,r   )rU   rV   rR   rW   )TT)r   Nr   )r   )g        )rG   rH   rI   rJ   rU   rE   r`   rd   rg   rj   rn   propertyrr   rY   rZ   rS   rm   r   r   r   r   r   r   r   r   r
   r	   rK   rL   r   r   rN   rN      s    G" .65, $ $    
$2*44+#7-r   rN   c                   X    \ rS rSrSrSr\R                  4S jrS r	SS jr
S rS	 rS
rg)PipeConnectioni+  z
Connection class based on a Windows named pipe.
Overlapped I/O is used, so the handles must have been created
with FILE_FLAG_OVERLAPPED.
Fc                 (    U" U R                   5        g r   rq   )rD   _CloseHandles     r   r^   PipeConnection._close3  s    &r   c                    [         R                  " U R                  USS9u  p# U[         R                  :X  a3  [         R                  " UR
                  /S[        5      nU[        :X  d   eUR                  S5      u  pSUS:X  d   eU[        U5      :X  d   eg !   UR                  5         e = f! UR                  S5      u  pSf = f)NT
overlappedFr   )r   	WriteFilerU   ERROR_IO_PENDINGWaitForMultipleObjectseventINFINITEWAIT_OBJECT_0cancelGetOverlappedResultr   )rD   r   overrwaitresnwrittens         r   r   PipeConnection._send_bytes6  s    ''cdKGB
='222%<<
E85G #m333
 !# 6 6t <!8O8s3x'''		 " 6 6t <#s   AB B++B. .CNc                    U R                   (       a  SU l         [        R                  " 5       $ Uc  SO[        US5      n [        R
                  " U R                  USS9u  p4 U[        R                  :X  a3  [        R                  " UR                  /S[        5      nU[        :X  d   eUR                  S5      u  pdUS:X  a6  [        R                  " 5       nUR                  UR                  5       5        U$ U[        R                   :X  a  U R#                  X15      $  [-        S5      e!   UR                  5         e = f! UR                  S5      u  pdUS:X  a:  [        R                  " 5       nUR                  UR                  5       5        Us  s $ U[        R                   :X  a  U R#                  X15      s  s $ f = f! [$         a*  nUR&                  [        R(                  :X  a  [*        ee S nAff = f)NF   Tr   r   z.shouldn't get here; expected KeyboardInterrupt)_got_empty_messageioBytesIOminr   ReadFilerU   r   r   r   r   r   r   r   write	getbufferERROR_MORE_DATA_get_more_datarc   winerrorERROR_BROKEN_PIPEEOFErrorRuntimeError)	rD   maxsizebsizer   r   r   nreadfes	            r   r   PipeConnection._recv_bytesF  s   &&*/'zz|#&C4E%..eGBD'":"::&-&D&D!#
E8'=G#*m#;;#;
 &(%;%;D%A
!8 "

AGGBLLN3#$H G$;$;;#'#6#6r#CC < @B B!		%'%;%;D%A
!8 "

AGGBLLN3#$H G$;$;;#'#6#6r#CC < zzW%>%>>&	s]    "G #AD* *AG 9$G *D==E   AF>G 'F>;G =F>>G 
G5%G00G5c                     U R                   (       d'  [        R                  " U R                  5      S   S:w  a  g[	        [        U /U5      5      $ )Nr   T)r   r   PeekNamedPiperU   boolr   r   s     r   r   PipeConnection._pollh  s>    ''))$,,7:a?dVW-..r   c                    UR                  5       n[        R                  " 5       nUR                  U5        [        R
                  " U R                  5      S   nUS:  d   eUb"  [        U5      U-   U:  a  U R                  5         [        R                  " U R                  USS9u  pUR                  S5      u  pvUS:X  d   eXu:X  d   eUR                  UR                  5       5        U$ )Nr   r   Tr   )r   r   r   r   r   r   rU   r   rn   r   r   )rD   r   r   r   r   leftr   rbytess           r   r   PipeConnection._get_more_datan  s    ,,.C

AGGCL((6q9D!8O8"s3x$'@((*&&t||TdKGB006KF!8O8>!>GGBLLN#Hr   )r   r   )rG   rH   rI   rJ   __doc__r   r   CloseHandler^   r   r   r   r   rK   rL   r   r   r   r   +  s3    	
 #&-&9&9 	'	(  	BD	/	r   r   c                       \ rS rSrSr\(       a)  \R                  4S jr\R                  r
\R                  rO(\R                  4S jr\R                  r
\R                   r\
4S jr\4S jr\4S jrSS	 jrS
 rSrg)
Connectioni~  zc
Connection class based on an arbitrary file descriptor (Unix only), or
a socket handle (Windows).
c                 (    U" U R                   5        g r   rq   rD   r^   s     r   r^   Connection._close      4<< r   c                 (    U" U R                   5        g r   rq   r   s     r   r^   r     r   r   c                     [        U5      n  U" U R                  U5      nX4-  nUS:X  a  g XS  nM%  ! [        [        [        R
                  4 a*  n[        USS 5      [        R                  :w  a  e  S nANFS nAff = f)Nr   errno)	r   rU   rc   IOErrorr5   errorgetattrr   EINTR)rD   r   r   	remainingr   excs         r   _sendConnection._send  s~    H		$,,,
 	>"g  Wfll3 3.%++= >s   2 A; A66A;c                    [         R                  " 5       nU R                  nUnUS:  aM   U" XE5      n[        U5      nUS:X  a  XQ:X  a  [        e[        S5      eUR                  U5        XW-  nUS:  a  MM  U$ ! [
        [        [        R                  4 a*  n[        USS 5      [        R                  :w  a  e  S nANNS nAff = f)Nr   zgot end of file during messager   )r   r   rU   r   r   rc   r   r   r5   r   r   r   r   )	rD   r   readr   rX   r   chunkr   r   s	            r   _recvConnection._recv  s    jjl	!mV/
 J6 (&%&FGG		% 	 !m 
 Wfll3 3.%++= >s   A9 9C B==Cc                     [        U5      n[        R                  " SU5      nUS:  a#  U R                  U5        U R                  U5        g [	        X5      (       a  UR                  5       nU R                  XA-   5        g )N!ii @  )r   structpackr   rQ   tobytes)rD   r   r~   r   headers        r   r   Connection._send_bytes  sa    HT1%u9 JJvJJsO #**kkmJJv|$r   Nc                     U R                  S5      n[        R                  " SUR                  5       5      u  nUb  X1:  a  g U R                  U5      $ )N   r  )r  r  unpackr   )rD   r   r   r   s       r   r   Connection._recv_bytes  sC    jjmdCLLN34>zz$r   c                 2    [        U /U5      n[        U5      $ r   )r   r   )rD   r   rs      r   r   Connection._poll  s    $!Awr   rL   r   )rG   rH   rI   rJ   r   r   r   closesocketr^   r   _writer   _readr)   rm   r   r   r   r  r~   r   r   r   rK   rL   r   r   r   r   ~  sp    
  ) 5 5 	! " 	!%   % * +5 %$ r   r   c                   ^    \ rS rSrSrSS jrS rS r\" S 5      r	\" S 5      r
S	 rS
 rSrg)r   i  z
Returns a listener object.

This is a wrapper for a bound socket which is 'listening' for
connections, or for a Windows named pipe.
Nc                 8   U=(       d!    U=(       a    [        U5      =(       d    [        nU=(       d    [        U5      n[        U5        US:X  a  [	        X5      U l        O[        XU5      U l        Ub   [        U[        5      (       d  [        S5      eX@l
        g )Nr   authkey should be a byte string)r=   default_familyr0   r6   PipeListener	_listenerSocketListenerrQ   r   	TypeError_authkey)rD   r<   r/   backlogauthkeys        r   rE   Listener.__init__  s     H4|G4H9G 	6.v6 Y)';DN+GWEDNz'5'A'A=>>r   c                     U R                   c  [        S5      eU R                   R                  5       nU R                  (       a*  [	        XR                  5        [        XR                  5        U$ )zb
Accept a connection on the bound socket or named pipe of `self`.

Returns a `Connection` object.
zlistener is closed)r  rc   acceptr  deliver_challengeanswer_challenge)rD   cs     r   r"  Listener.accept  sP     >>!.//NN!!#==a/Q.r   c                 R    U R                   nUb  SU l         UR                  5         gg)z1
Close the bound socket or named pipe of `self`.
N)r  rm   )rD   listeners     r   rm   Listener.close  s)     >>!DNNN  r   c                 .    U R                   R                  $ r   )r  _addressr_   s    r   <lambda>Listener.<lambda>  s    DNN$;$;r   c                 .    U R                   R                  $ r   )r  _last_acceptedr_   s    r   r,  r-    s    $..*G*Gr   c                     U $ r   rL   r_   s    r   r   Listener.__enter__  r   r   c                 $    U R                  5         g r   r   r   s       r   r   Listener.__exit__  r   r   )r  r  )NNr   N)rG   rH   rI   rJ   r   rE   r"  rm   r   r<   last_acceptedr   r   rK   rL   r   r   r   r     s8       ;<GGHMr   r   c                     U=(       d    [        U 5      n[        U5        US:X  a  [        U 5      nO[        U 5      nUb   [	        U[
        5      (       d  [        S5      eUb  [        X25        [        X25        U$ )z5
Returns a connection to the address of a `Listener`
r   r  )	r=   r6   
PipeClientSocketClientrQ   r   r  r$  r#  )r<   r/   r  r%  s       r   r   r     sp     ,|G,FVw!:gu#=#=9::$!%Hr   c                 Z    [        U S5      (       a  U R                  5       $ [        U 5      $ )Ndetach)r4   r9  r?   rB   s    r   r9  r9  !  s(    tX{{} D!!r   c                    U (       an  [         R                  " 5       u  p4UR                  U(       + 5        UR                  U(       + 5        [        [	        U5      5      n[        [	        U5      5      nXV4$ [
        R                  " 5       u  pxU(       a  [        US5        U(       a  [        US5        [        USS9n[        USS9nXV4$ )<
Returns pair of connection objects at either end of a pipe
r   FrZ   rY   )r5   
socketpairr	   r   r9  r)   pipe)	duplex	rnonblock	wnonblocks1s2c1c2fd1fd2s	            r   r   r   +  s     &&(FBNNy=)NNy=)F2J'BF2J'B v wwyHCC#C#C%0BC%0Bvr   c           
         U(       a   S5       eU(       a   S5       e[        S5      nU (       a=  [        R                  n[        R                  [        R                  -  n[
        [
        pvO'[        R                  n[        R                  nS[
        pv[        R                  " X4[        R                  -  [        R                  -  [        R                  [        R                  -  [        R                  -  SXg[        R                  [        R                  5      n[        R                  " X5S[        R                  [        R                   [        R                  [        R                  5      n	[        R"                  " U	[        R                  SS5        [        R$                  " USS9n
U
R'                  S5      u  pUS:X  d   e[)        XS	9n[)        XS
9nX4$ )r;  z"rnonblock not supported on windowsz"wnonblock not supported on windowsr   r   r   NTr   r<  r=  )r0   r   PIPE_ACCESS_DUPLEXGENERIC_READGENERIC_WRITEBUFSIZEPIPE_ACCESS_INBOUNDCreateNamedPipeFILE_FLAG_OVERLAPPEDFILE_FLAG_FIRST_PIPE_INSTANCEPIPE_TYPE_MESSAGEPIPE_READMODE_MESSAGE	PIPE_WAITNMPWAIT_WAIT_FOREVERNULL
CreateFileOPEN_EXISTINGSetNamedPipeHandleStateConnectNamedPiper   r   )r@  rA  rB  r<   openmodeaccessobsizeibsizeh1h2r   _r   rE  rF  s                  r   r   r   B  ss    BBB}BBB}#I.11H))G,A,AAF$gF22H**FF$$ < <<112%%(E(EEvw;;LL
 Qg.C.C((',,
 	''--tT	
 --bTB
//5axxB0B0vr   c                   .    \ rS rSrSrSS jrS rS rSrg)	r  iq  zG
Representation of a socket which is bound to an address and listening
c                    [         R                   " [        [         U5      5      U l         [        R                  S:X  a9  U R                  R                  [         R                  [         R                  S5        U R                  R                  S5        U R                  R                  U5        U R                  R                  U5        U R                  R                  5       U l        X l        S U l        US:X  a,  ["        R$                  " U [        R&                  U4SS9U l        g S U l        g ! [         a    U R                  R                  5         e f = f)Nposixr   Tr   r   argsexitpriority)r5   r   rR   r)   name
setsockopt
SOL_SOCKETSO_REUSEADDRr	   bindlistengetsocknamer+  rc   rm   _familyr/  r   Finalizeunlink_unlink)rD   r<   r/   r  s       r   rE   SocketListener.__init__u  s    }}WVV%<=	ww'!''(9(9(.(;(;Q@LL$$T*LLg&LL( LL446DM "Y==biiwjqDL  DL  	LL 	s   B=D/ /&Ec                 0     U R                   R                  5       u  ol         UR                  S5        [        [        U5      5      $ ! [        [        [
        R                  4 a*  n[        USS 5      [        R                  :w  a  e  S nAOS nAff = fM  )NTr   )rR   r"  r/  rc   r   r5   r   r   r   r   r	   r   r9  )rD   sr   s      r   r"  SocketListener.accept  s    )-)<)<)>&&
 	d&)$$ Wfll3 3.%++= > s   !A
 
B) BBc                      U R                   R                  5         U R                  nUb  S U l        U" 5         g g ! U R                  nUb  S U l        U" 5         f f = fr   )rR   rm   rr  )rD   rq  s     r   rm   SocketListener.close  s[    	LL \\F!# " \\F!# "s	   ;  A)r+  ro  r/  rR   rr  N)r   )	rG   rH   rI   rJ   r   rE   r"  rm   rK   rL   r   r   r  r  q  s     0
%r   r  c                     [        U 5      n[        R                  " [        [        U5      5      nUR                  S5        UR	                  U 5        [        [        U5      5      $ )zG
Return a connection object connected to the socket given by `address`
T)r=   r5   r   r	   connectr   r9  )r<   r/   ru  s      r   r7  r7    sJ     '"Fgff-.AMM$IIgfQi  r   c                   B    \ rS rSrSrS	S jrS
S jrS r\S 5       r	Sr
g)r  i  z 
Representation of a named pipe
Nc                 
   Xl         U R                  SS9/U l        S U l        [        R
                  " SU R                   5        [        R                  " U [        R                  U R                  U R                   4SS9U l	        g )NT)firstz listener created with address=%rr   re  )
r+  _new_handle_handle_queuer/  r   	sub_debugrp  r  _finalize_pipe_listenerrm   )rD   r<   r  s      r   rE   PipeListener.__init__  sj    #M"&"2"2"2">!?D"&DNN=t}}Ml::(($--8qDJr   c           
         [         R                  [         R                  -  nU(       a  U[         R                  -  n[         R                  " U R
                  U[         R                  [         R                  -  [         R                  -  [         R                  [        [        [         R                  [         R                  5      $ r   )r   rJ  rP  rQ  rO  r+  rR  rS  rT  PIPE_UNLIMITED_INSTANCESrM  rU  rV  )rD   r}  flagss      r   r~  PipeListener._new_handle  s    ..1M1MME>>>**u))G,I,II!!"00'7,,gll r   c                 Z   U R                   R                  U R                  5       5        U R                   R                  S5      n [        R
                  " USS9n [        R                  " UR                  /S[        5         UR                  S5      u  p4US:X  d   e [        U5      $ !   UR                  5         [        R                  " U5        e = f! UR                  S5      u  p4US:X  d   ef = f! [         a)  nUR                  [        R                  :w  a  e  S nANS nAff = f)Nr   Tr   F)r  appendr~  popr   rZ  r   r   r   r   r   r   rc   r   ERROR_NO_DATAr   )rD   rX   r   ra  r   r   s         r   r"  PipeListener.accept  s    %%d&6&6&89''++A.F$--fF	$22
E85  33D9FA!8O8!&))IIK''/33D9FA!8O8  ::!6!66 7s0   C7 'B+ +)CC C47
D*D%%D*c                 p    [         R                  " SU5        U  H  n[        R                  " U5        M     g )Nz closing listener with address=%r)r   r  r   r   )queuer<   rX   s      r   r  $PipeListener._finalize_pipe_listener  s)    NN=wG##F+  r   )r+  r  r/  rm   r   )F)rG   rH   rI   rJ   r   rE   r~  r"  staticmethodr  rK   rL   r   r   r  r    s*    			
		*. 
	, 
	,r   r  c           	         [        5       n  [        R                  " U S5        [        R                  " U [        R                  [        R
                  -  S[        R                  [        R                  [        R                  [        R                  5      n [        R                  " U[        R                  SS5        [        U5      $ ! [         a+  nUR                  U;  d  [        U5      (       a  e  SnAOSnAff = fM  )zE
Return a connection object connected to the pipe given by `address`
  r   N)r   r   WaitNamedPiperW  rK  rL  rV  rX  rP  rc   r   r    rY  rS  r   )r<   _ignorer   hr   s        r   r6  r6    s    
 O%%gt4&&W11G4I4IIw||W%:%:00',,  	''w,,dD	
 a    ::W,q0A0A 1B s   B
C
 

C?!C::C?   s   #CHALLENGE#s	   #WELCOME#s	   #FAILURE#c                 t   SS K n[        U[        5      (       d   e[        R                  " [
        5      nU R                  [        U-   5        UR                  XS5      R                  5       nU R                  S5      nXT:X  a  U R                  [        5        g U R                  [        5        [        S5      e)Nr   md5   zdigest received was wrong)hmacrQ   r   r)   urandomMESSAGE_LENGTHr   	CHALLENGEnewdigestr   WELCOMEFAILUREr   
connectionr  r  messager  responses         r   r#  r#    s    gu%%%%jj(G)g-.XXg.557F$$S)Hg&g&!"=>>r   c                 v   SS K n[        U[        5      (       d   eU R                  S5      nUS [	        [
        5       [
        :X  d
   SU-  5       eU[	        [
        5      S  nUR                  XS5      R                  5       nU R                  U5        U R                  S5      nU[        :w  a  [        S5      eg )Nr   r  zmessage = %rr  zdigest sent was rejected)r  rQ   r   r   r   r  r  r  r   r  r   r  s         r   r$  r$    s    gu%%%%##C(G?C	N#y0J.72JJ0c)no&GXXg.557F&!$$S)H7!"<== r   c                   &    \ rS rSrS rS rS rSrg)ConnectionWrapperi0  c                 h    Xl         X l        X0l        S H  n[        X5      n[	        XU5        M     g )N)rS   rm   r   r   r   )_conn_dumps_loadsr   setattr)rD   connr   loadsattrr   s         r   rE   ConnectionWrapper.__init__2  s0    
KD$%CD$ Lr   c                 \    U R                  U5      nU R                  R                  U5        g r   )r  r  r   )rD   r   ru  s      r   r   ConnectionWrapper.send:  s"    KK

a r   c                 X    U R                   R                  5       nU R                  U5      $ r   )r  r   r  )rD   ru  s     r   r   ConnectionWrapper.recv>  s"    JJ!!#{{1~r   )r  r  r  N)rG   rH   rI   rJ   rE   r   r   rK   rL   r   r   r  r  0  s    %!r   r  c                 X    [         R                  U 4S S S S5      nUR                  S5      $ )Nr   utf-8)	xmlrpclibr   encode)r   os     r   
_xml_dumpsr  C  s)    tT15A88Gr   c                 V    [         R                  U R                  S5      5      u  u  pU$ )Nr  )r  r  decode)ru  r   methods      r   
_xml_loadsr  H  s"    __QXXg%67NFSJr   c                       \ rS rSrS rSrg)XmlListeneriM  c                 b    SS K Jq  [        R	                  U 5      n[        U[        [        5      $ Nr   )xmlrpc.clientclientr  r   r"  r  r  r  r   s     r   r"  XmlListener.acceptO  s"    )ood# j*==r   rL   N)rG   rH   rI   rJ   r"  rK   rL   r   r   r  r  M  s    >r   r  c                  J    SS K Jq  [        [	        U 0 UD6[
        [        5      $ r  )r  r  r  r  r   r  r  )rf  kwdss     r   	XmlClientr  V  s    %VT2T2J
KKr   c                    [        U 5      n/ nU(       a  [        R                  " USU5      nU[        :X  a   U$ [        Us=::  a  [        [        U5      -   :  a  O  O
U[        -  nO9[        Us=::  a  [        [        U5      -   :  a  O  O
U[        -  nO[        S5      eUR                  X$   5        X$S-   S  nSnU(       a  M  U$ )NFzShould not get herer   r   )	listr   r   WAIT_TIMEOUTr   r   WAIT_ABANDONED_0r   r  )handlesr   Lreadyress        r   _exhaustive_waitr  a  s     M00E7CCl"  #>A(>>}$!SD+;c!f+DD''"#899LL '(AG a r   c                   ^ Uc  [         nOUS:  a  SnO[        US-  S-   5      n[        U 5      n 0 m/ n[        5       n[        5       n U  Hy  n [	        US5      n [
        R                  " U" 5       SS5      u  pxU[
        R                  :X  a"  UR                  W5        UTUR                  '   Mf  UR                  U5        SnM{     [!        TR#                  5       U5      nU H  nUR%                  5         M     U Ho  n UR'                  S5      u  pU[
        R(                  :w  d  M-  TUR                     nUR                  U5        US:X  d  MU  [+        US5      (       d  Mh  SUl        Mq     UR/                  U4S jU 5       5        U  Vs/ s H  oU;   d  M
  UPM     sn$ ! [         a"  n	U	R                  nU[        ;  a  e  Sn	A	GNQSn	A	ff = f! [         a    UTUR                  5       '    GM  f = f! [         a"  n	U	R                  nU[        ;  a  e  Sn	A	GNSn	A	ff = f! U H  nUR%                  5         M     U H  n UR'                  S5      u  pO.! [         a!  n	U	R                  nU[        ;  a  e  Sn	A	OSn	A	ff = fU[
        R(                  :w  d  M\  TUR                     nUR                  U5        US:X  d  M  [+        US5      (       d  M  SUl        M     f = fs  snf )	
Wait till an object in object_list is ready/readable.

Returns list of those objects in object_list which are ready/readable.
Nr   r  g      ?rS   Tr   c              3   .   >#    U  H
  nTU   v   M     g 7fr   rL   ).0r  waithandle_to_objs     r   	<genexpr>wait.<locals>.<genexpr>  s     I=a.q1=s   )r   intr  setr   r   r   rc   r   _ready_errorsr   r  r   addAttributeErrorrT   r  keysr   r   ERROR_OPERATION_ABORTEDr4   r   update)object_listr   ov_listready_objectsready_handlesr  rS   r   r   r   ra  pr  s               @r   r   r   w  s    ?Gq[G'D.3./G;'-	8 $$Q1F
"")"2"268Q"E
 g666r*67)"((3
 &))!,"#+ !. -->-C-C-EwOM 		  33D9FA
 '999)"((3A!%%a(ax #1&:;;37A0   	I=II&=;a}*<;==M # "jjm3! 4" & 978%akkm49<  **C-/ 0 		  33D9FAs **C-/ 0 '999)"((3A!%%a(ax #1&:;;37A0 " >s   
H) GF&<A'H) G:	K+K+&
G0GH) GH) G72H) 6G77H) :
H&H!!H&)K(	IK(
J	'J	>K(J	K(!$K(	K(K(r   c                    Ub  [        US-  5      n0 n[        R                  " 5       nU  HL  nUR                  U[        R                  5        [        US5      (       a  XBUR                  5       '   MH  XBU'   MN     / nUR                  U5       H>  u  pFU[        R                  -  (       a  [        SU-  5      eUR                  X$   5        M@     U$ )Nr  rS   zinvalid file descriptor %i)
r  selectr   registerPOLLINr4   rS   POLLNVALr-   r  )fdsr   fd_mappollsterfdlsr   s          r   r   r     s    "gn-F{{}H!!"fmm42x((*,299;'!#2J  B%]]73	6??*$%AB%FGG		&*% 4 Ir   c                 :    [         R                   " U / / U5      S   $ r  )r  )r  r   s     r   r   r     s    ==b"g6q99r   c                    Ub  US::  a  [        U S5      $ [        5       U-   n  [        X5      $ ! [        [        [        R
                  4 a)  nUR                  [        R                  :w  a  e  SnAOSnAff = fUb  W[        5       -
  nMi  )r  Nr   )r   r   rc   r   r5   r   r   r   )r  r   deadliner   s       r   r   r     s     !|[!,,$;0[22Wfll3 77ekk) * ""Y[0 s   
0 A8A33A8c                 *   U R                  5       n[        R                  " U[        R                  [        R                  5       nSSKJn  UR                  U5      n[        X@R                  U R                  44sS S S 5        $ ! , (       d  f       g = f)Nr   )resource_sharer)rS   r5   fromfdr   SOCK_STREAMr%   r  	DupSocketrebuild_connectionrY   rZ   )r  rX   ru  r  dss        r   reduce_connectionr    s^    ]]66>>63E3EF!) **1-B%MM4=='II GFFs   5B
Bc                 L    U R                  5       n[        [        U5      X5      $ r   )r9  r   )r  rY   rZ   rC   s       r   r  r    s    yy{&,;;r   c                    U R                   (       a  [        R                  OSU R                  (       a  [        R                  OS-  n[
        R                  " U R                  5       U5      n[        X R                   U R                  44$ r  )	rY   r   FILE_GENERIC_READrZ   FILE_GENERIC_WRITEr   	DupHandlerS   rebuild_pipe_connection)r  r\  dhs      r   reduce_pipe_connectionr    s\    047,,1157--AG  7&]]DMM(JJJr   c                 ,    [        [        U 5      X5      $ r   )r   r9  )r  rY   rZ   s      r   r   r     s    fRj(==r   c                     [         R                  " U R                  5       5      n[        XR                  U R
                  44$ r   )r   DupFdrS   r  rY   rZ   )r  dfs     r   r  r    s.    __T[[]+!Bt}}#EEEr   c                 ,    [        [        U 5      X5      $ r   )r   r9  )r  rY   rZ   s      r   r  r    s    &*h99r   )NN)TFFr   )Or   r   r)   r2   r5   r  r  r&   	itertoolsr%   r   r   r   r   _extr   compatr	   r
   timer   r   r   r3   r   r  r  r   ImportError__all__r4   is_pypyrM  CONNECTION_TIMEOUTcountr,   r  familiesr   r    r0   r6   r=   r?   rN   r   r   r   r   r9  r   r  r7  r  ERROR_SEM_TIMEOUTERROR_PIPE_BUSYr6  r  r  r  r  r#  r$  r  r  r  r  r  r  r   ERROR_NETNAME_DELETEDr  r   r   r  r  r  r  r   rL   r   r   <module>r     s    	 	 
        1  ,  %$ ||w--"33++##
0
#*
+  !;
69NH<<7NH - !0
FF( _- _-D P PfO Ol5 5p*" <<7.(^/ /d! <<76, 6,p &-%>%>%,%<%<%> !> 	

?
>" &

>( >L <<7( ..0M0MNMC>N vv	$	:10 <<7J< z#45K>~'=>F:z#45W  
||wGs   I6 6JJ