+
    Dfj5                        R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHtHtH	t	H
t
HtHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt  ! R	 R
]P0                  4      t]! ]
P4                  ! ]R4      '       * R4       ! R R]P6                  4      4       t ! R R]P:                  4      t ! R R]P>                  4      t ]! ]
PB                  ! ]R4      '       * R4       ! R R]P6                  4      4       t"R# )zK
Tests for implementations of L{IReactorUNIX} and L{IReactorUNIXDatagram}.
N)skipIf)addressdefererror
interfacesprotocolreactorutils)lockfile)networkString)FilePath)MyClientFactoryMyServerFactory)unittestc                   ,   a  ] tR t^t o R tR tRtV tR# )FailedConnectionClientFactoryc                    Wn         R # NonFail)selfr   s   &&8/usr/lib/python3/dist-packages/twisted/test/test_unix.py__init__&FailedConnectionClientFactory.__init__   s        c                <    V P                   P                  V4       R # r   )r   errback)r   	connectorreasons   &&&r   clientConnectionFailed4FailedConnectionClientFactory.clientConnectionFailed   s    F#r   r   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes____classdictcell____classdict__s   @r   r   r      s     $ $r   r   1This reactor does not support UNIX domain socketsc                      a  ] tR t^t o Rt]P                  ! ]R4      '       g   RtR t	R t
R tR tR tR	 tR
 tR tR tRtV tR# )UnixSocketTestsz
Test unix sockets.
Nr)   c                  a aa S P                  4       pS P                  4       o\        4       o\        P                  ! 4       ;pSn        \
        P                  ! VS4      pS P                  VP                  4       \        P                  ! \        P                  \        P                  4      pS P                  VP                  4       VP                  S4       VP                  V4       VV V3R lpVP                  V4       V# )z
The address passed to the server factory's C{buildProtocol} method and
the address returned by the connected protocol's transport's C{getPeer}
method match the address the client socket is bound to.
c                    < \         P                  ! S4      pSP                  SP                  V.4       SP                  V P                  P                  4       V4       R # r   )r   UNIXAddressassertEqualpeerAddresses	transportgetPeer)protoexpectedpeernamer   serverFactorys   & r   
cbConnMade1UnixSocketTests.test_peerBind.<locals>.cbConnMade;   sH    **84H]888*EU__446Ar   )mktempr   r   DeferredprotocolConnectionMader   
listenUNIX
addCleanupstopListeningsocketAF_UNIXSOCK_STREAMclosebindconnectaddCallback)r   filenameconnMadeunixPort
unixSocketr7   r5   r6   s   f     @@r   test_peerBindUnixSocketTests.test_peerBind*   s     ;;=;;='):?..:JJ=7%%h>../]]6>>63E3EF

(()!8$	B
 	Z(r   c                  a aa S P                  4       o\        4       p\        P                  ! 4       pW!n        \
        P                  ! SV4      pS P                  VP                  4       \        4       o\        P                  ! 4       pVSn        \
        P                  ! SS4       \        P                  ! W$.4      pVVV 3R lpVP                  V4       V# )zr
L{IReactorUNIX.connectUNIX} can be used to connect a client to a server
started with L{IReactorUNIX.listenUNIX}.
c                    < V w  rSP                  SP                  \        P                  ! S4      .4       VP                  P                  4        VP                  P                  4        R # r   )r/   r0   r   r.   r1   loseConnection)argsserverProtocolclientProtocolclientFactoryrF   r   s   &  r   allConnected1UnixSocketTests.test_dumber.<locals>.allConnectedT   sZ    -1*N ++g.A.A(.K-L $$335$$335r   )r9   r   r   r:   r;   r   r<   r=   r>   r   connectUNIXgatherResultsrE   )	r   r6   serverConnMaderH   clientConnMadedrS   rR   rF   s	   f      @@r   test_dumberUnixSocketTests.test_dumberC   s    
 ;;='))/=,%%h>../'))/=,Hm4 @A		6 	
l#r   c                  a aaa	 S P                  4       o\        4       p\        P                  ! 4       pW!n        \
        P                  ! SVRR7      o	S P                  \        P                  ! SR,           4      4       \        4       o\        P                  ! 4       pVSn        \
        P                  ! SS^R7       \        P                  ! W#.4      pVVV V	3R lpVP                  V4       VV 3R lpVP                  V4       V# )z
A lockfile is created and locked when L{IReactorUNIX.listenUNIX} is
called and released when the Deferred returned by the L{IListeningPort}
provider's C{stopListening} method is called back.
TwantPID.lockcheckPIDc                    < V w  rSP                  SP                  \        P                  ! S4      .4       VP                  P                  4        VP                  P                  4        SP                  4       # r   )r/   r0   r   r.   r1   rN   r>   )rO   rP   clientProtorR   rF   r   rH   s   &  r   
_portStuff0UnixSocketTests.test_pidFile.<locals>._portStuffy   si    *.'N ++g.A.A(.K-L !!002$$335))++r   c                 b   < SP                  \        P                  ! SR ,           4      R4       R# )r_   lockedN)assertFalser
   isLocked)ignoredrF   r   s   &r   _check,UnixSocketTests.test_pidFile.<locals>._check   s#    X..x'/ABHMr   )r9   r   r   r:   r;   r   r<   
assertTruer
   ri   r   rU   rV   rE   )
r   r6   rW   rX   rY   rd   rk   rR   rF   rH   s
   f      @@@r   test_pidFileUnixSocketTests.test_pidFileb   s     ;;='))/=,%%htL))(W*<=>
 ())/=,Hma@ @A	, 	, 	
j!	N 	
fr   c                  aa V P                  4       o\        4       o\        P                  ! SSRR7      pV P	                  \
        P                  \        P                  SSRR7       VV3R lpVP                  4       P                  V4      # )z
L{IReactorUNIX.listenUNIX} raises L{error.CannotListenError} if passed
the name of a file on which a server is already listening.
Tr]   c                 V   < \         P                  ! SSR R7      pVP                  4       # Tr]   )r   r<   r>   )ignrH   rF   r6   s   & r   stoppedListening<UnixSocketTests.test_socketLocking.<locals>.stoppedListening   s&    ))(M4PH))++r   )	r9   r   r   r<   assertRaisesr   CannotListenErrorr>   rE   )r   rH   rt   rF   r6   s   &  @@r   test_socketLocking"UnixSocketTests.test_socketLocking   s|    
 ;;=')%%htL## 	 	
	, %%'334DEEr   c                   V P                  4       V n        \        R V P                  : R24      pR\        \        P
                  P                  \        P                  4      4      P                  4       P                  /p\        \        P                  4      P                  4       P                  p\        P                  ! VRRV3VR7      pVP                  V4       V# )zBfrom twisted.internet import protocol, reactor
reactor.listenUNIX(z), protocol.ServerFactory(),wantPID=True)
s
   PYTHONPATHs   -us   -c)env)r9   rF   r   r   ospathsepjoinsyspathasBytesMode
executabler	   getProcessValuerE   )r   callbacksourcer{   pyExerY   s   &&    r   _uncleanSocketTest"UnixSocketTests._uncleanSocketTest   s     }}
 hrzzsxx'@AMMOTTU(446;;!!%%)?SI	hr   c                2   a  V 3R lpS P                  V4      # )z
If passed C{True} for the C{wantPID} parameter, a server can be started
listening with L{IReactorUNIX.listenUNIX} when passed the name of a
file on which a previous server which has not exited cleanly has been
listening using the C{wantPID} option.
c                 z   < \         P                  ! SP                  \        4       R R7      pVP	                  4       # rr   )r   r<   rF   r   r>   )rs   pr   s   & r   ranStupidChildGUnixSocketTests.test_uncleanServerSocketLocking.<locals>.ranStupidChild   s+    ""4==/2CTRA??$$r   r   r   r   s   f r   test_uncleanServerSocketLocking/UnixSocketTests.test_uncleanServerSocketLocking   s    	%
 &&~66r   c                2   a  V 3R lpS P                  V4      # )z
If passed C{True} for the C{checkPID} parameter, a client connection
attempt made with L{IReactorUNIX.connectUNIX} fails with
L{error.BadFileError}.
c                    < \         P                  ! 4       p\        V4      p\        P                  ! SP
                  VR R7       SP                  V\        P                  4      # )Tr`   )	r   r:   r   r   rU   rF   assertFailurer   BadFileError)rs   rY   fr   s   &  r   r   CUnixSocketTests.test_connectToUncleanServer.<locals>.ranStupidChild   sH     A-a0Aq4@%%a););<<r   r   r   s   f r   test_connectToUncleanServer+UnixSocketTests.test_connectToUncleanServer   s    	= &&~66r   c                J  a aa S P                  4       p\        P                  ! W14      oRS RV: R2pS P                  \	        S4      V4       S P                  \        S4      V4       \        P                  ! SP                  4      pVV V3R lpVP                  V4       V# )zf
Test the C{__str__} and C{__repr__} implementations of a UNIX port when
used with the given factory.
< on >c                    < R S R2pSP                  \        S4      V4       SP                  \        S4      V4       R# r   z (not listening)>Nr/   reprstr)rs   unconnectedStringfactoryNamer   rH   s   & r   rt   3UnixSocketTests._reprTest.<locals>.stoppedListening   s=    "#K=0A BT(^->?S],=>r   )
r9   r   r<   r/   r   r   r   maybeDeferredr>   rE   )r   r6   r   rF   connectedStringrY   rt   rH   s   f&f    @r   	_reprTestUnixSocketTests._reprTest   s    
 ;;=%%h>k]$xl!<h9X8 6 67	?
 	
&'r   c                p     ! R R4      pV P                  V\        4       V P                  V! 4       R4      # )z
The two string representations of the L{IListeningPort} returned by
L{IReactorUNIX.listenUNIX} contains the name of the new-style factory
class being used and the filename on which the port is listening or
indicates that the port is not listening.
c                   ,   a  ] tR t^t o R tR tRtV tR# )EUnixSocketTests.test_reprWithNewStyleFactory.<locals>.NewStyleFactoryc                    R # r    r   s   &r   doStartMUnixSocketTests.test_reprWithNewStyleFactory.<locals>.NewStyleFactory.doStart       r   c                    R # r   r   r   s   &r   doStopLUnixSocketTests.test_reprWithNewStyleFactory.<locals>.NewStyleFactory.doStop   r   r   r   N)r!   r"   r#   r$   r   r   r%   r&   r'   s   @r   NewStyleFactoryr            r   r   z&twisted.test.test_unix.NewStyleFactoryassertIsInstancetyper   )r   r   s   & r   test_reprWithNewStyleFactory,UnixSocketTests.test_reprWithNewStyleFactory   s8    	 	 	ot4~~G
 	
r   )rF   )r!   r"   r#   r$   __doc__r   IReactorUNIXr   skiprJ   rZ   rn   rx   r   r   r   r   r   r%   r&   r'   s   @r   r+   r+      sX     
 ""7D11B2>*XF."77,
 
r   r+   c                   D   a  ] tR tRt o R;ttRtR tR tR t	R t
RtV tR# )	ClientProtoi  FNc                n    \         P                  ! 4       V n        \         P                  ! 4       V n        R # r   )r   r:   deferredStarteddeferredGotBackr   s   &r   r   ClientProto.__init__       $~~/$~~/r   c                    R V n         R# TNstoppedr   s   &r   stopProtocolClientProto.stopProtocol	  	    r   c                J    R V n         V P                  P                  R4       R# r   startedr   r   r   s   &r   startProtocolClientProto.startProtocol      %%d+r   c                H    Wn         V P                  P                  R 4       R # r   )gotbackr   r   )r   datas   &&r   datagramReceivedClientProto.datagramReceived  s    %%d+r   )r   r   r   r   r   )r!   r"   r#   r$   r   r   r   r   r   r   r   r%   r&   r'   s   @r   r   r     s-     GgG0,, ,r   r   c                   H   a  ] tR tRt o R;ttR;ttR tR t	R t
R tRtV tR# )	ServerProtoi  FNc                n    \         P                  ! 4       V n        \         P                  ! 4       V n        R # r   )r   r:   r   deferredGotWhatr   s   &r   r   ServerProto.__init__  r   r   c                    R V n         R# r   r   r   s   &r   r   ServerProto.stopProtocol  r   r   c                J    R V n         V P                  P                  R4       R# r   r   r   s   &r   r   ServerProto.startProtocol   r   r   c                    W n         V P                  P                  R V4       Wn        V P                  P                  R4       R# )   hi backN)gotfromr1   writegotwhatr   r   )r   r   addrs   &&&r   r   ServerProto.datagramReceived$  s4    Z.%%d+r   )r   r   r   r   r   r   )r!   r"   r#   r$   r   r   r   r   r   r   r   r   r%   r&   r'   s   @r   r   r     s2     GgGg0,, ,r   r   z3This reactor does not support UNIX datagram socketsc                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	DatagramUnixSocketTestsi+  z
Test datagram UNIX sockets.
c                  a aaa	 S P                  4       oS P                  4       p\        4       o	\        4       o\        P                  ! VS	4      pS P                  VP                  4       \        P                  ! VSSR7      pS P                  VP                  4       \        P                  ! S	P                  SP                  .4      pVV	3R lpVVV V	3R lpVP                  V4       VP                  V4       V# )zN
Test that a datagram can be sent to and received by a server and vice
versa.
)bindAddressc                    < SP                   P                  R 4       \        P                  ! SP                  SP
                  .4      # )   hi)r1   r   r   rV   r   r   )rj   cpsps   &r   r   4DatagramUnixSocketTests.test_exchange.<locals>.writeD  s7    LLu%&&(:(:B<N<N'OPPr   c                    < SP                  R SP                  4       SP                  SSP                  4       SP                  RSP                  4       R# )r   r   N)r/   r   r   r   )rj   
clientaddrr   r   r   s   &r   _cbTestExchange>DatagramUnixSocketTests.test_exchange.<locals>._cbTestExchangeH  s?    UBJJ/Z4Z4r   )r9   r   r   r   listenUNIXDatagramr=   r>   connectUNIXDatagramr   rV   r   rE   )
r   
serveraddrscrY   r   r   r   r   r   s
   f      @@@r   test_exchange%DatagramUnixSocketTests.test_exchange4  s    
 [[]
[[]
]]&&z26(''
BJO(!3!3R5G5G HI	Q	5 	5
 	
e	o&r   c                   V P                  4       p\        4       p\        P                  ! W4      pV P	                  \
        P                  \        P                  W4       VP                  4        \        P                  ! V4       R# )z~
L{IReactorUNIXDatagram.listenUNIXDatagram} raises
L{error.CannotListenError} if the unix socket specified is already in
use.
N)
r9   r   r   r   rv   r   rw   r>   r|   unlink)r   r   r   r   s   &   r   test_cannotListen)DatagramUnixSocketTests.test_cannotListenQ  sY     {{}M&&t/%1173M3MtW	
		$r   c                J  a aa S P                  4       p\        P                  ! W14      oRS RV: R2pS P                  \	        S4      V4       S P                  \        S4      V4       \        P                  ! SP                  4      pVV V3R lpVP                  V4       V# )zp
Test the C{__str__} and C{__repr__} implementations of a UNIX datagram
port when used with the given protocol.
r   r   r   c                    < R S R2pSP                  \        S4      V4       SP                  \        S4      V4       R# r   r   )rs   r   protocolNamer   rH   s   & r   rt   ;DatagramUnixSocketTests._reprTest.<locals>.stoppedListeningn  s=    "#L>1B CT(^->?S],=>r   )
r9   r   r   r/   r   r   r   r   r>   rE   )r   serverProtor  rF   r   stopDeferredrt   rH   s   f&f    @r   r   !DatagramUnixSocketTests._reprTest`  s    
 ;;=--hDl^4|1=h9X8**8+A+AB	?
 	  !12r   c                p     ! R R4      pV P                  V\        4       V P                  V! 4       R4      # )a
  
The two string representations of the L{IListeningPort} returned by
L{IReactorUNIXDatagram.listenUNIXDatagram} contains the name of the
new-style protocol class being used and the filename on which the port
is listening or indicates that the port is not listening.
c                   ,   a  ] tR tRt o R tR tRtV tR# )ODatagramUnixSocketTests.test_reprWithNewStyleProtocol.<locals>.NewStyleProtocoli~  c                    R # r   r   )r   r1   s   &&r   makeConnection^DatagramUnixSocketTests.test_reprWithNewStyleProtocol.<locals>.NewStyleProtocol.makeConnection  r   r   c                    R # r   r   r   s   &r   r   VDatagramUnixSocketTests.test_reprWithNewStyleProtocol.<locals>.NewStyleProtocol.doStop  r   r   r   N)r!   r"   r#   r$   r  r   r%   r&   r'   s   @r   NewStyleProtocolr
  ~  r   r   r  z'twisted.test.test_unix.NewStyleProtocolr   )r   r  s   & r   test_reprWithNewStyleProtocol5DatagramUnixSocketTests.test_reprWithNewStyleProtocolv  s9    	 	 	.5~~ I
 	
r   r   N)r!   r"   r#   r$   r   r   r   r   r  r%   r&   r'   s   @r   r   r   +  s#     
:,
 
r   r   )#r   r|   r?   r   r   r   twisted.internetr   r   r   r   r   r   r	   twisted.pythonr
   twisted.python.compatr   twisted.python.filepathr   twisted.test.test_tcpr   r   twisted.trialClientFactoryr   r   TestCaser+   ConnectedDatagramProtocolr   DatagramProtocolr   IReactorUNIXDatagramr   r   r   r   <module>r     s   
 
  
  X X X # / , B "$H$:$: $ ..7\
h'' \
	\
~,(44 ,(,(++ ,, ''669[
h// [
	[
r   