+
    Dfj
J                       R t ^ RIHt ^ RIt ^ RIHt ^ RIH	t	H
t
 ^ RIHtHt ^ RIHtHt ^ RIHt ^ RIHtHt ^ R	IHtHt ^ R
IHt  ! R R4      t]
! ]P8                  4       ! R R4      4       t]
! ]P<                  ]P>                  ]P@                  4       ! R R4      4       t!R t"R t# ! R R4      t$RR lt%]"]#RRR3R lt&R t' ! R R4      t(RR lt)R#   ] d     Li ; i)z0
Utilities and helpers for simulating a network
)annotationsN)Error)directlyProvidesimplementer)error
interfaces)TCP4ClientEndpointTCP4ServerEndpoint)ConnectionRefusedError)FactoryProtocol)MemoryReactorMemoryReactorClock)Failurec                  .    ] tR t^tR tR R ltR tRtR# )TLSNegotiationc                	8    Wn         W n        R V n        W n        R# )FN)objconnectStatesentreadyToSend)selfr   r   s   &&&4/usr/lib/python3/dist-packages/twisted/test/iosim.py__init__TLSNegotiation.__init__   s    (	'    c                   V ^8  d   QhRR/#    returnstr )formats   "r   __annotate__TLSNegotiation.__annotate__"   s     / /# /r   c                	$    R V P                   : R2# )zTLSNegotiation())r   r   s   &r   __repr__TLSNegotiation.__repr__"   s     A..r   c                	    V P                   P                  VP                   4      '       g"   \        4       Vn        VP	                  4        R # R # N)r   iosimVerifyNativeOpenSSLErrordisconnectReasonloseConnection)r   othertpts   &&&r   pretendToVerifyTLSNegotiation.pretendToVerify%   s9     xx##EII..#5#7C   /r   )r   r   r   r   N)__name__
__module____qualname____firstlineno__r   r(   r2   __static_attributes__r!   r   r   r   r      s    (/!r   r   c                      ] tR t^.tRtRtR# )FakeAddresszQ
The default address type for the host and peer of L{FakeTransport}
connections.
r!   N)r4   r5   r6   r7   __doc__r8   r!   r   r   r:   r:   .   s    r   r:   c                  0   ] tR t^6tRt]! ]P                  ! 4       3R l4      t^ t	^ t
^ t]P                  ! R4      tRt^ tRtR R ltR R ltR tR	 tR
 tR tR tR tR tR tR tR tR tR tR t R t!R t"R!R lt#R t$R t%R t&R t'R t(R t)R t*Rt+R# )"FakeTransportz
A wrapper around a file-like object to make it behave as a Transport.

This doesn't actually stream the file to the attached protocol,
and is thus useful mainly as a utility for debugging protocols.
c                	*    \        \        V 4      4      # r+   )intnext)counters   &r   <lambda>FakeTransport.<lambda>?   s    T']ASr   zConnection doneNc                    Wn         W n        . V n        V P                  4       V n        Vf   \        4       pW0n        Vf   \        4       pW@n        R# )at  
@param protocol: This transport will deliver bytes to this protocol.
@type protocol: L{IProtocol} provider

@param isServer: C{True} if this is the accepting side of the
    connection, C{False} if it is the connecting side.
@type isServer: L{bool}

@param hostAddress: The value to return from C{getHost}.  L{None}
    results in a new L{FakeAddress} being created to use as the value.
@type hostAddress: L{IAddress} provider or L{None}

@param peerAddress: The value to return from C{getPeer}.  L{None}
    results in a new L{FakeAddress} being created to use as the value.
@type peerAddress: L{IAddress} provider or L{None}
N)protocolisServerstream_nextserialserialr:   hostAddresspeerAddress)r   rE   rF   rJ   rK   s   &&&&&r   r   FakeTransport.__init__H   sK    " ! &&(%-K&%-K&r   c                   V ^8  d   QhRR/# r   r!   )r"   s   "r   r#   FakeTransport.__annotate__d   s     
 
# 
r   c                	    R P                  V P                  ;'       d    R;'       g    RV P                  V P                  P                  P
                  4      # )zFakeTransport<{},{},{}>SC)r"   rF   rI   rE   	__class__r4   r'   s   &r   r(   FakeTransport.__repr__d   sF    (//MM!!c((SKKMM##,,
 	
r   c                	    V P                   '       d   R # V P                  e   V P                  P                  V4       R # V P                  P                  V4       R # r+   )disconnectingtlstlsbufappendrG   )r   datas   &&r   writeFakeTransport.writek   s?    88KKt$KKt$r   c                	    V P                   '       d1   V P                  '       g   V P                   P                  4        R # R # R # r+   producerstreamingProducerresumeProducingr'   s   &r   _checkProducerFakeTransport._checkProduceru   s/     ===!7!7!7MM))+ "8=r   c                R    Wn         W n        V'       g   VP                  4        R# R# )z
From abstract.FileDescriptor
Nr]   )r   r^   	streamings   &&&r   registerProducerFakeTransport.registerProducer{   s#     !!*$$& r   c                	    R V n         R # r+   )r^   r'   s   &r   unregisterProducer FakeTransport.unregisterProducer   s	    r   c                	F    V P                  4        V P                  4        R # r+   )rh   r/   r'   s   &r   stopConsumingFakeTransport.stopConsuming   s    !r   c                	F    V P                  R P                  V4      4       R# )r   N)rZ   join)r   iovecs   &&r   writeSequenceFakeTransport.writeSequence   s    

388E?#r   c                	    R V n         R# )TNrU   r'   s   &r   r/   FakeTransport.loseConnection   s
    !r   c                    RV n         R# )zX
For the time being, this is the same as loseConnection; no buffered
data will be lost.
TNrs   r'   s   &r   abortConnectionFakeTransport.abortConnection   s    
 "r   c                	    V P                   e   \        4       pMV P                  pV P                  P	                  \        V4      4       R # r+   )rV   r-   r.   rE   connectionLostr   )r   errs   & r   reportDisconnectFakeTransport.reportDisconnect   s7    88 %&C''C$$WS\2r   c                    R# )z=
Identify this transport/event source to the logging system.
iosimr!   r'   s   &r   	logPrefixFakeTransport.logPrefix   s     r   c                	    V P                   # r+   )rK   r'   s   &r   getPeerFakeTransport.getPeer       r   c                	    V P                   # r+   )rJ   r'   s   &r   getHostFakeTransport.getHost   r   r   c                	    R # r+   r!   r'   s   &r   r`   FakeTransport.resumeProducing       r   c                	    R # r+   r!   r'   s   &r   pauseProducingFakeTransport.pauseProducing   r   r   c                	&    V P                  4        R # r+   )r/   r'   s   &r   stopProducingFakeTransport.stopProducing   s    r   c                	Z    V P                   V,          p\        W4      V n        . V n        R # r+   )rF   r   rV   rW   )r   contextFactorybeNormalr   s   &&& r   startTLSFakeTransport.startTLS   s%     }}x/!.?r   c                    V P                   pV'       d   . V n         RP                  V4      # V P                  e<   V P                  P                  '       d   RV P                  n        V P                  # R# R# )z
Get the pending writes from this transport, clearing them from the
pending buffer.

@return: the bytes written with C{transport.write}
@rtype: L{bytes}
r   NT)rG   rn   rV   r   r   )r   rP   s   & r   getOutBufferFakeTransport.getOutBuffer   sY     KKDK88A;XX!xx### $xxr   c                	   \        V\        4      '       d   V P                  f   Q hV P                  P                  '       dc   V P                  P	                  W4       R V n        V P
                  R uq n        V P                  V4       \        V \        P                  4       R # RV P                  n
        R # V P                  P                  V4       R # )NT)
isinstancer   rV   r   r2   rW   rp   r   r   ISSLTransportr   rE   dataReceived)r   bufbs   && r   bufferReceivedFakeTransport.bufferReceived   s    c>**88''' xx}}}((3 "&d;""1% z'?'?@ (,$MM&&s+r   c                	    R # r+   r!   r'   s   &r   getTcpKeepAliveFakeTransport.getTcpKeepAlive   r   r   c                	    R # r+   r!   r'   s   &r   getTcpNoDelayFakeTransport.getTcpNoDelay   r   r   c                	    R # r+   r!   r'   s   &r   loseWriteConnection!FakeTransport.loseWriteConnection   r   r   c                	    R # r+   r!   r   enableds   &&r   setTcpKeepAliveFakeTransport.setTcpKeepAlive   r   r   c                	    R # r+   r!   r   s   &&r   setTcpNoDelayFakeTransport.setTcpNoDelay   r   r   )rU   rJ   rF   rK   r^   rE   rI   rG   r_   rV   rW   )NN)T),r4   r5   r6   r7   r;   staticmethod	itertoolscountrH   closedrU   disconnectedr   ConnectionDoner.   r^   r_   rV   r   r(   rZ   ra   re   rh   rk   rp   r/   rv   r{   r   r   r   r`   r   r   r   r   r   r   r   r   r   r   r8   r!   r   r   r=   r=   6   s     ioo.?STKFML++,=>H
C'8
%,'$""3  ,,&r   r=   c                    \        V RR7      # )z
Create and return a new in-memory transport hooked up to the given protocol.

@param clientProtocol: The client protocol to use.
@type clientProtocol: L{IProtocol} provider

@return: The transport.
@rtype: L{FakeTransport}
FrF   r=   )clientProtocols   &r   makeFakeClientr      s     %88r   c                    \        V RR7      # )z
Create and return a new in-memory transport hooked up to the given protocol.

@param serverProtocol: The server protocol to use.
@type serverProtocol: L{IProtocol} provider

@return: The transport.
@rtype: L{FakeTransport}
Tr   r   )serverProtocols   &r   makeFakeServerr     s     $77r   c                  8    ] tR tRtRtRR ltR	R ltR	R ltRtR# )
IOPumpi  z
Utility to pump data between clients and servers for protocol testing.

Perhaps this is a utility worthy of being in protocol.py?
Nc                	j    Wn         W n        W0n        W@n        WPn        Vf   \        4       pW`n        R # r+   )clientserverclientIOserverIOdebugr   clock)r   r   r   r   r   r   r   s   &&&&&&&r   r   IOPump.__init__  s-      
=&(E
r   c                p    Rp\        R4       F  pV P                  W4      '       d   RpK   V# 	  Q R4       h)zS
Pump until there is no more input or output.

Returns whether any data was moved.
Fi  TzToo long)rangepump)r   r   advanceClockresult_s   &&&  r   flushIOPump.flush)  sA     tAyy--   !j 1r   c                X   V'       d   V P                   P                  ^ 4       V P                  '       g	   V'       d   \        R4       V P                  P                  4       pV P                  P                  4       pV P                  P                  4        V P                  P                  4        V P                  '       g	   V'       dR   \        R4       V'       d   \        R\        V4      ,           4       V'       d   \        R\        V4      ,           4       V'       d   V P                  P                  V4       V'       d   V P                  P                  V4       V'       g	   V'       d   R# V P                  P                  '       d   V P                  P                  '       gd   V P                  '       g	   V'       d   \        R4       RV P                  n        RV P                  n
        V P                  P                  4        R# V P                  P                  '       d   V P                  P                  '       gd   V P                  '       g	   V'       d   \        R4       RV P                  n        RV P                  n
        V P                  P                  4        R# R# )	z
Move data back and forth, while also triggering any currently pending
scheduled calls (i.e. C{callLater(0, f)}).

Returns whether any data was moved.
z
-- GLUG --.zC: zS: Tz* Cz* SF)r   advancer   printr   r   r   ra   reprr   rU   r   r{   )r   r   r   sDatacDatas   &&&  r   r   IOPump.pump9  s    JJq!:::,**,**,$$&$$&:::#Jed5k)*ed5k)*MM((/MM((/E==&&&t}}/I/I/IzzzUe)-DMM&*.DMM'MM**,==&&&t}}/I/I/IzzzUe)-DMM&*.DMM'MM**,r   )r   r   r   r   r   r   r+   FT)	r4   r5   r6   r7   r;   r   r   r   r8   r!   r   r   r   r     s     * *r   r   FTc           	         V P                  V4       VP                  V4       \        VV VVVVR7      pV'       d   VP                  4        V# )as  
Create a new L{IOPump} connecting two protocols.

@param serverProtocol: The protocol to use on the accepting side of the
    connection.
@type serverProtocol: L{IProtocol} provider

@param serverTransport: The transport to associate with C{serverProtocol}.
@type serverTransport: L{FakeTransport}

@param clientProtocol: The protocol to use on the initiating side of the
    connection.
@type clientProtocol: L{IProtocol} provider

@param clientTransport: The transport to associate with C{clientProtocol}.
@type clientTransport: L{FakeTransport}

@param debug: A flag indicating whether to log information about what the
    L{IOPump} is doing.
@type debug: L{bool}

@param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
    returning to put the protocols into their post-handshake or
    post-server-greeting state?
@type greet: L{bool}

@param clock: An optional L{Clock}. Pumping the resulting L{IOPump} will
    also increase clock time by a small increment.

@return: An L{IOPump} which connects C{serverProtocol} and
    C{clientProtocol} and delivers bytes between them when it is pumped.
@rtype: L{IOPump}
r   )makeConnectionr   r   )r   serverTransportr   clientTransportr   greetr   r   s   &&&&&&& r   connectr   f  sP    T !!/2!!/2D 

Kr   c                `    V! 4       pV ! 4       pV! V4      p	V! V4      p
Wx\        WWyWEVR7      3# )a  
Connect a given server and client class to each other.

@param ServerClass: a callable that produces the server-side protocol.
@type ServerClass: 0-argument callable returning L{IProtocol} provider.

@param ClientClass: like C{ServerClass} but for the other side of the
    connection.
@type ClientClass: 0-argument callable returning L{IProtocol} provider.

@param clientTransportFactory: a callable that produces the transport which
    will be attached to the protocol returned from C{ClientClass}.
@type clientTransportFactory: callable taking (L{IProtocol}) and returning
    L{FakeTransport}

@param serverTransportFactory: a callable that produces the transport which
    will be attached to the protocol returned from C{ServerClass}.
@type serverTransportFactory: callable taking (L{IProtocol}) and returning
    L{FakeTransport}

@param debug: Should this dump an escaped version of all traffic on this
    connection to stdout for inspection?
@type debug: L{bool}

@param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
    returning to put the protocols into their post-handshake or
    post-server-greeting state?
@type greet: L{bool}

@param clock: An optional L{Clock}. Pumping the resulting L{IOPump} will
    also increase clock time by a small increment.

@return: the client protocol, the server protocol, and an L{IOPump} which,
    when its C{pump} and C{flush} methods are called, will move data
    between the created client and server protocol instances.
@rtype: 3-L{tuple} of L{IProtocol}, L{IProtocol}, L{IOPump}
r   )r   )ServerClassClientClassclientTransportFactoryserverTransportFactoryr   r   r   csciosios   &&&&&&&    r   connectedServerAndClientr     s=    \ 	AA
 
#C
 
#CUCCCr   c                2    V w  pppppVw  rxrWs8X  d   WH3# R# )a  
Should the client and server described by the arguments be connected to
each other, i.e. do their port numbers match?

@param clientInfo: the args for connectTCP
@type clientInfo: L{tuple}

@param serverInfo: the args for listenTCP
@type serverInfo: L{tuple}

@return: If they do match, return factories for the client and server that
    should connect; otherwise return L{None}, indicating they shouldn't be
    connected.
@rtype: L{None} or 2-L{tuple} of (L{ClientFactory},
    L{IProtocolFactory})
Nr!   )
clientInfo
serverInfo
clientHost
clientPortclientFactoryclientTimeoutclientBindAddress
serverPortserverFactoryserverBacklogserverInterfaces   &&         r   _factoriesShouldConnectr     s7    . 	BL?Z++r   c                  ^    ] tR tRtRtR R ltRR R llt]! ]! 4       4      3R R llt	R	t
R
# )ConnectionCompleteri  z
A L{ConnectionCompleter} can cause synthetic TCP connections established by
L{MemoryReactor.connectTCP} and L{MemoryReactor.listenTCP} to succeed or
fail.
c                    V ^8  d   QhRRRR/# )r   memoryReactorr   r   Noner!   )r"   s   "r   r#    ConnectionCompleter.__annotate__  s     & &m & &r   c                    Wn         R# )zk
Create a L{ConnectionCompleter} from a L{MemoryReactor}.

@param memoryReactor: The reactor to attach to.
N_reactor)r   r   s   &&r   r   ConnectionCompleter.__init__  s	     &r   c               $    V ^8  d   QhRRRRRR/# )r   r   boolr   r   zIOPump | Noner!   )r"   s   "r   r#   r     s!          d  m  r   c                   V P                   p\        VP                  4       F  w  rEVP                   F  p\	        WV4      pV'       g   K  VP                  P                  V4       VP                  P                  V4       Vw  rVP                  R4      p
V	P                  R4      p\        V4      p\        V
4      p\        VVV
VVVR7      pVu u # 	  K  	  R# )a  
Complete a single TCP connection established on this
L{ConnectionCompleter}'s L{MemoryReactor}.

@param debug: A flag; whether to dump output from the established
    connection to stdout.

@return: a pump for the connection, or L{None} if no connection could
    be established.
N)r   )r  	enumerate
tcpClients
tcpServersr   remove
connectorspopbuildProtocolr   r   r   )r   r   r   r   	clientIdxr   r   	factoriesr   r   r   r   r   r   r   s   &&&            r   succeedOnceConnectionCompleter.succeedOnce  s     %.}/G/G%H!I+66
3JK	9!,,33J?!,,00;3<0M%2%@%@%FN%2%@%@%FN&4^&DO&4^&DO%,&'&'#&F "M% 7 &I( r   c                    V ^8  d   QhRRRR/# )r   reasonr   r   r   r!   )r"   s   "r   r#   r   %  s     	
 	
w 	
t 	
r   c                    V P                   P                  P                  ^ 4      ^,          P                  V P                   P                  P                  ^ 4      V4       R# )z
Fail a single TCP connection established on this
L{ConnectionCompleter}'s L{MemoryReactor}.

@param reason: the reason to provide that the connection failed.
N)r  r  r  clientConnectionFailedr
  )r   r  s   &&r   failOnceConnectionCompleter.failOnce%  sF     	  $$Q'*AAMM$$((+V	
r   r   Nr   )r4   r5   r6   r7   r;   r   r  r   r
   r  r8   r!   r   r   r   r     s*    & D *11G1I)J 	
 	
r   r   c                    \        4       p\        VRR4      p\        VR4      pVP                  \        P
                  ! \        4      4       V\        V4      3# )ae  
Create an endpoint that can be fired on demand.

@param debug: A flag; whether to dump output from the established
    connection to stdout.
@type debug: L{bool}

@return: A client endpoint, and an object that will cause one of the
    L{Deferred}s returned by that client endpoint.
@rtype: 2-L{tuple} of (L{IStreamClientEndpoint}, L{ConnectionCompleter})
z0.0.0.0i  )r   r   r	   listenr   forProtocolr   r   )r   reactorclientEndpointserverEndpoints   &   r   connectableEndpointr  1  sP     !"G'DAN'6N'--h78.w777r   )FTN)F)*r;   
__future__r   r   OpenSSL.SSLr   r-   ImportErrorzope.interfacer   r   twisted.internetr   r   twisted.internet.endpointsr   r	   twisted.internet.errorr
   twisted.internet.protocolr   r   twisted.internet.testingr   r   twisted.python.failurer   r   IAddressr:   
ITransportITLSTransport	IConsumerr=   r   r   r   r   r   r   r   r  r!   r   r   <module>r,     s   
 # 	7 9 . M 9 7 F *! !& Z  !  " Z""J$<$<j>R>RSD D TDN
9
8K K\7z *)


2Dj>:
 :
z8G  		s   C C#"C#