+
    DfjѦ                       R t ^ RIt^ RI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Ht ^ RIHtHt ^ RIt^ RIHtHt ^ RIHtHtHtH t H!t!H"t" ^ R	I#H$t$H%t% ^ R
I&H't'H(t(H)t)H*t*H+t+H,t,H-t-H.t.H/t/ ^ RI0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8H9t9H:t:H;t; ^ RI<H=t=H>t>H?t? ^ RI@HAtAHBtBHCtCHDtDHEtEHFtFHGtG ^ RIHHItIHJtJHKtKHLtLHMtMHNtNHOtOHPtPHQtQ ^ RIRHStSHTtTHUtU ^ RIVHWtWHXtX ^ RIYHZtZ ^ RI[H\t\ ^ RI]H^t^ ^ RI_H`t` ^ RIaHbtbHctcHdtdHete ^ RIfHgtgHhthHiti  ^ RIjHktk ^ RIlHmtm RtnRtp ]P
                  ! ]P                  ]P                  4      tp]pP                  R4       RttRtu]pe   ]pP                  4        ]`P                  ! 4       '       d   ^ RIzH{t{ ]{P                  t}Rt~M ^ RIzHt ]EP                   t}Rt~R  tR! t ! R" R#4      t ! R$ R%]i4      t ! R& R']>4      t]! ]64       ! R( R)4      4       t]! ]6]4        ! R* R+]i4      t ! R, R-]i4      t ! R. R/]L4      t ! R0 R1]4      t]! ]:4       ! R2 R34      4       t ! R4 R5]S]K]O4      t ! R6 R7]4      t]! ]t]u4       ! R8 R9]4      4       t ! R: R;]S4      t ! R< R=]4      t]! ]t]u4       ! R> R?]4      4       tR@ t ! RA RB]4      t]! ]4      ]P                  ! RRC7       ! RD RE4      4       4       t]! ]~RF4       ! RG RH]h4      4       tRI t]! ]~RF4       ! RJ RK]h4      4       t ! RL RM]M4      t ! RN RO4      t ! RP RQ]4      t ! RR RS]4      t ! RT RU4      t ! RV RW]S]]]4      t ! RX RY]S]]]4      t ! RZ R[]>4      tR\ tR] tR^ t ! R_ R`]S4      t ! Ra Rb4      t ! Rc Rd4      t ! Re Rf]]]S4      t ! Rg Rh]]]S4      t]! 4       EPS                  ]EPU                  4       4       ]! 4       EPS                  ]EPU                  4       4       ]! 4       EPS                  ]EPU                  4       4       ]! 4       EPS                  ]EPU                  4       4       ]! 4       EPS                  ]EPU                  4       4       ]! 4       EPS                  ]EPU                  4       4       ]! 4       EPS                  ]EPU                  4       4       ]! 4       EPS                  ]EPU                  4       4       ]! 4       EPS                  ]EPU                  4       4        ! Ri Rj]J4      t ! Rk Rl]J4      t ! Rm Rn]J4      t ! Ro Rp]4      t ! Rq Rr]J4      t ! Rs Rt]J4      t ! Ru Rv]J4      t ! Rw Rx]4      t ! Ry Rz]4      t ! R{ R|]4      t ! R} R~]4      t ! R R]J4      t ! R R]J4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R4      t ! R R]S]4      t]! 4       EPS                  ]EPU                  4       4       ]! ]t]u4       ! R R]i4      4       t ! R R]h4      t]! ]~RF4       ! R R]h4      4       t ! R R]h4      tR#   ]o d    Rtn ELi ; i  ]v d   twRttR]w 2tu RtwAwELRtwAwii ; i  ]o d    R t} ELi ; i)zU
Tests for implementations of L{IReactorTCP} and the TCP parts of
L{IReactorSocket}.
Nwraps)CallableClassVarListMappingOptionalSequenceType)skipIf)	Interfaceimplementer)verifyClassverifyObject)IPv4AddressIPv6Address)DeferredDeferredListfailgatherResultsmaybeDeferredsucceed)TCP4ClientEndpointTCP4ServerEndpoint)	ConnectBindErrorConnectionAbortedConnectionClosedConnectionDoneConnectionLostConnectionRefusedErrorDNSLookupError
NoProtocol	UserError)
IConnectorIHalfCloseableProtocolILoggingContextIPullProducerIPushProducerIReactorFDSetIReactorSocketIReactorTCPIReactorTimeIResolverSimpleITLSTransport)ClientFactoryProtocolServerFactory)
ConnectionServer_BuffersLogs_FileDescriptorReservation_IFileDescriptorReservation_NullFileDescriptorReservation_resolveIPv6)	BrokenContextFactoryConnectableProtocolConnectionTestsMixinEndpointCreatorLogObserverMixinStopStreamClientTestsMixinfindFreePortrunProtocolsWithReactor)ReactorBuilderneedsRunningReactorstopOnError)MemoryReactorStringTransport)Logger)log)Failure)platform)ClientStartStopFactoryClosingFactoryMyClientFactoryMyServerFactory)SkipTestSynchronousTestCaseTestCase)SSL)ClientContextFactoryTF zIPv6 not available. )_win32ifaces)_posixifacesc                      . # N rX       @/usr/lib/python3/dist-packages/twisted/internet/test/test_tcp.py<lambda>r[      s    BrY   c                 N    \        4       p V '       d
   V ^ ,          # \        R4      h)aP  
Find and return a configured link local IPv6 address including a scope
identifier using the % separation syntax.  If the system has no link local
IPv6 addresses, raise L{SkipTest} instead.

@raise SkipTest: if no link local address can be found or if the
    C{netifaces} module is not available.

@return: a C{str} giving the address
z#Link local IPv6 address unavailable)getLinkLocalIPv6AddressesrN   )	addressess    rZ   getLinkLocalIPv6Addressr_      s%     *+I|
8
99rY   c                    Vw  r#RV9   g   RV9   d&   \         P                  ! W#4      ^ ,          ^,          pMW#3pV P                  V4       R# )a  
Connect a socket to the given destination.

@param client: A C{socket.socket}.

@param destination: A tuple of (host, port). The host is a C{str}, the
    port a C{int}. If the C{host} is an IPv6 IP, the address is resolved
    using C{getaddrinfo} and the first version found is used.
%:N)socketgetaddrinfoconnect)clientdestinationhostportaddresss   &&   rZ   re   re      sE     LT
d{cTk$$T03A6,
NN7rY   c                   T   a  ] tR t^t o RtR tR tR tR tR t	R t
R tR	 tR
tV tR# )
FakeSocketz
A fake for L{socket.socket} objects.

@ivar data: A C{str} giving the data which will be returned from
    L{FakeSocket.recv}.

@ivar sendBuffer: A C{list} of the objects passed to L{FakeSocket.send}.
c                     Wn         . V n        R # rW   )data
sendBufferselfrn   s   &&rZ   __init__FakeSocket.__init__   s    	rY   c                    Wn         R # rW   )blocking)rq   ru   s   &&rZ   setblockingFakeSocket.setblocking   s     rY   c                    V P                   # rW   rn   )rq   sizes   &&rZ   recvFakeSocket.recv   s    yyrY   c                N    V P                   P                  V4       \        V4      # )z
I{Send} all of C{bytes} by accumulating it into C{self.sendBuffer}.

@return: The length of C{bytes}, indicating all the data has been
    accepted.
)ro   appendlenrq   bytess   &&rZ   sendFakeSocket.send   s      	u%5zrY   c                    R# )z
Shutdown is not implemented.  The method is provided since real sockets
have it and some code expects it.  No behavior of L{FakeSocket} is
affected by a call to it.
NrX   )rq   hows   &&rZ   shutdownFakeSocket.shutdown       rY   c                    R# )z
Close is not implemented.  The method is provided since real sockets
have it and some code expects it.  No behavior of L{FakeSocket} is
affected by a call to it.
NrX   rq   s   &rZ   closeFakeSocket.close   r   rY   c                    R# )z
Setsockopt is not implemented.  The method is provided since
real sockets have it and some code expects it.  No behavior of
L{FakeSocket} is affected by a call to it.
NrX   )rq   argss   &*rZ   
setsockoptFakeSocket.setsockopt   r   rY   c                    ^# )z
Return a fake file descriptor.  If actually used, this will have no
connection to this L{FakeSocket} and will probably cause surprising
results.
rX   r   s   &rZ   filenoFakeSocket.fileno   s     rY   )ru   rn   ro   N)__name__
__module____qualname____firstlineno____doc__rr   rv   r{   r   r   r   r   r   __static_attributes____classdictcell____classdict__s   @rZ   rl   rl      s7     ! rY   rl   c                   6   a  ] tR t^t o RtR tR tR tRtV t	R# )FakeSocketTestszL
Test that the FakeSocket can be used by the doRead method of L{Connection}
c                v    \        R 4      pVP                  ^ 4       V P                  VP                  ^ 4       R#    someDataN)rl   rv   assertEqualru   rq   skts   & rZ   test_blockingFakeSocketTests.test_blocking   s,    %q)rY   c                ^    \        R 4      pV P                  VP                  ^
4      R 4       R# r   )rl   r   r{   r   s   & rZ   	test_recvFakeSocketTests.test_recv   s$    %"{3rY   c                    \        R4      pVP                  R4      pV P                  V^4       V P                  VP                  R.4       R# )zp
L{FakeSocket.send} accepts the entire string passed to it, adds it to
its send buffer, and returns its length.
rY   s   fooN)rl   r   r   ro   )rq   r   counts   &  rZ   	test_sendFakeSocketTests.test_send   sA    
 o "&2rY   rX   N)
r   r   r   r   r   r   r   r   r   r   r   s   @rZ   r   r      s     *
43 3rY   r   c                   *   a  ] tR tRt o RtR tRtV tR# )FakeProtocoli  zD
An L{IProtocol} that returns a value from its dataReceived method.
c                    R# )zY
Return something other than L{None} to trigger a deprecation warning for
that behavior.
rX   rX   rp   s   &&rZ   dataReceivedFakeProtocol.dataReceived  s	    
 	rY   rX   Nr   r   r   r   r   r   r   r   r   s   @rZ   r   r     s      rY   r   c                   T   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tRtV tR# )_FakeFDSetReactori  ag  
An in-memory implementation of L{IReactorFDSet}, which records the current
sets of active L{IReadDescriptor} and L{IWriteDescriptor}s.

@ivar _readers: The set of L{IReadDescriptor}s active on this
    L{_FakeFDSetReactor}
@type _readers: L{set}

@ivar _writers: The set of L{IWriteDescriptor}s active on this
    L{_FakeFDSetReactor}
@ivar _writers: L{set}
c                B    \        4       V n        \        4       V n        R # rW   )set_readers_writersr   s   &rZ   rr   _FakeFDSetReactor.__init__  s    rY   c                <    V P                   P                  V4       R # rW   )r   addrq   readers   &&rZ   	addReader_FakeFDSetReactor.addReader!      &!rY   c                `    WP                   9   d   V P                   P                  V4       R # R # rW   )r   remover   s   &&rZ   removeReader_FakeFDSetReactor.removeReader$  #    ]]"MM  ( #rY   c                <    V P                   P                  V4       R # rW   )r   r   rq   writers   &&rZ   	addWriter_FakeFDSetReactor.addWriter(  r   rY   c                `    WP                   9   d   V P                   P                  V4       R # R # rW   )r   r   r   s   &&rZ   removeWriter_FakeFDSetReactor.removeWriter+  r   rY   c                p    V P                  4       V P                  4       ,           pV P                  4        V# rW   )
getReaders
getWritersrr   rq   results   & rZ   	removeAll_FakeFDSetReactor.removeAll/  s(    "T__%66rY   c                ,    \        V P                  4      # rW   )listr   r   s   &rZ   r   _FakeFDSetReactor.getReaders4      DMM""rY   c                ,    \        V P                  4      # rW   )r   r   r   s   &rZ   r   _FakeFDSetReactor.getWriters7  r   rY   )r   r   N)r   r   r   r   r   rr   r   r   r   r   r   r   r   r   r   r   s   @rZ   r   r     s7     ")")
## #rY   r   c                   B   a  ] tR tRt o RtR tR tR tR tR t	Rt
V tR	# )
TCPServerTestsi>  z4
Whitebox tests for L{twisted.internet.tcp.Server}.
c                    \        4       V n         ! R  R4      p\        R4      V n        \	        4       V n        \        V P                  V P
                  RV! 4       RV P                  4      V n        R# )c                       ] tR tRt^tRtR# )&TCPServerTests.setUp.<locals>.FakePortiF  rX   N)r   r   r   r   _realPortNumberr   rX   rY   rZ   FakePortr   F  s    OrY   r   rY   N)rS       )r   reactorrl   r   r/   protocolr2   server)rq   r   s   & rZ   setUpTCPServerTests.setUpC  sS    (*	  	  c? 
HHdmmWhj$
rY   c                    V P                   P                  \        \        R4      4      4       V P                   P	                  R4       V P                  V P                  P                  . 4       R# )zY
L{Server.write} discards bytes passed to it if called after it has lost
its connection.
Simulated lost connection   hello worldN)r   connectionLostrH   	Exceptionwriter   r   ro   r   s   &rZ   test_writeAfterDisconnect(TCPServerTests.test_writeAfterDisconnectO  sM    
 	""795P+Q#RS.),,b1rY   c                H    RV P                   n        V P                  4        R# )z}
L{Server.write} discards bytes passed to it if called after it has lost
its connection when the connection had started TLS.
TN)r   TLSr   r   s   &rZ   !test_writeAfterDisconnectAfterTLS0TCPServerTests.test_writeAfterDisconnectAfterTLSX  s    
 &&(rY   c                    V P                   P                  \        \        R4      4      4       V P                   P	                  R.4       V P                  V P                  P                  . 4       R# )za
L{Server.writeSequence} discards bytes passed to it if called after it
has lost its connection.
r   r   N)r   r   rH   r   writeSequencer   r   ro   r   s   &rZ   !test_writeSequenceAfterDisconnect0TCPServerTests.test_writeSequenceAfterDisconnect`  sP    
 	""795P+Q#RS!!>"23,,b1rY   c                H    RV P                   n        V P                  4        R# )z
L{Server.writeSequence} discards bytes passed to it if called after it
has lost its connection when the connection had started TLS.
TN)r   r   r   r   s   &rZ   )test_writeSequenceAfterDisconnectAfterTLS8TCPServerTests.test_writeSequenceAfterDisconnectAfterTLSi  s    
 ..0rY   )r   r   r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   s   @rZ   r   r   >  s(     

2)21 1rY   r   c                   X   a  ] tR tRt o RtR tR t]! ]'       * R4      R 4       t	Rt
V tR# )	TCPConnectionTestsir  z8
Whitebox tests for L{twisted.internet.tcp.Connection}.
c                d   \        R4      p\        4       p\        W4      pVP                  4        V P	                  \        P
                  .4      pV P                  V^ ,          R,          \        4       V P                  V^ ,          R,          R4       V P                  \        V4      ^4       R# )z|
When an L{IProtocol} implementation that returns a value from its
C{dataReceived} method, a deprecated warning is emitted.
r   categorymessagezReturning a value other than None from twisted.internet.test.test_tcp.FakeProtocol.dataReceived is deprecated since Twisted 11.0.0.N)	rl   r   r1   doReadflushWarningsr   r   DeprecationWarningr   )rq   r   r   connwarningss   &    rZ   test_doReadWarningIsRaised-TCPConnectionTests.test_doReadWarningIsRaisedw  s    
 %>#(%%|'@'@&AB!Z02DEQK	"2	
 	X*rY   c                |    \        R4      p\        4       p\        W4      pV P                  VP                  4       R# )zg
The C{TLS} attribute of a L{Connection} instance is C{False} before
L{Connection.startTLS} is called.
rY   N)rl   r   r1   assertFalser   rq   r   r   r  s   &   rZ   test_noTLSBeforeStartTLS+TCPConnectionTests.test_noTLSBeforeStartTLS  s0    
 o>#("rY   zNo SSL support availablec                    \        R4      p\        4       p\        W\        4       R7      pRVn        VP                  \        4       R4       V P                  VP                  4       R# )ze
The C{TLS} attribute of a L{Connection} instance is C{True} after
L{Connection.startTLS} is called.
rY   )r   TN)	rl   r   r1   r   _tlsClientDefaultstartTLSrR   
assertTruer   r
  s   &   rZ   test_tlsAfterStartTLS(TCPConnectionTests.test_tlsAfterStartTLS  sN     o>#1B1DE!%*,d3!rY   rX   N)r   r   r   r   r   r  r  r   useSSLr  r   r   r   s   @rZ   r   r   r  s2     +&# J23
" 4
"rY   r   c                   4   a  ] tR tRt o RtRtR tR tRtV t	R# )
TCPCreatori  zG
Create IPv4 TCP endpoints for L{runProtocolsWithReactor}-based tests.
	127.0.0.1c                2    \        V^ V P                  R7      # )z$
Create a server-side TCP endpoint.
	interface)r   r  )rq   r   s   &&rZ   r   TCPCreator.server  s     "'1GGrY   c                B    \        WP                  VP                  4      # )zh
Create a client end point that will connect to the given address.

@type serverAddress: L{IPv4Address}
)r   r  ri   )rq   r   serverAddresss   &&&rZ   rf   TCPCreator.client  s     "'>>=;M;MNNrY   rX   N)
r   r   r   r   r   r  r   rf   r   r   r   s   @rZ   r  r    s#      IHO OrY   r  c                   *   a  ] tR tRt o RtR tRtV tR# )TCP6Creatori  a.  
Create IPv6 TCP endpoints for
C{ReactorBuilder.runProtocolsWithReactor}-based tests.

The endpoint types in question here are still the TCP4 variety, since
these simply pass through IPv6 address literals to the reactor, and we are
only testing address literals, not name resolution (as name resolution has
not yet been implemented).  See http://twistedmatrix.com/trac/ticket/4470
for more specific information about new endpoint classes.  The naming is
slightly misleading, but presumably if you're passing an IPv6 literal, you
know what you're asking for.
c                $    \        4       V n        R # rW   r_   r  r   s   &rZ   rr   TCP6Creator.__init__      02rY   r  N)r   r   r   r   r   rr   r   r   r   s   @rZ   r  r    s     3 3rY   r  c                   L   a  ] tR tRt o RtV 3R lR ltR	V 3R lR lltRtV tR# )
FakeResolveri  zJ
A resolver implementation based on a C{dict} mapping names to addresses.
c                6   < V ^8  d   QhRS[ S[S[3,          /# )   names)r   str)formatr   s   "rZ   __annotate__FakeResolver.__annotate__  s      gc3h/ rY   c                    Wn         R # rW   r(  )rq   r(  s   &&rZ   rr   FakeResolver.__init__  s    
rY   c                :   < V ^8  d   QhRS[ RS[S[,          RR/# )r'  nametimeoutreturnzDeferred[str])r)  r	   int)r*  r   s   "rZ   r+  r,    s+     N N# N N NrY   c                     \        V P                  V,          4      #   \         d    \        \	        RT,           4      4      u # i ; i)z
Return the address mapped to C{name} if it exists, or raise a
C{DNSLookupError}.

@param name: The name to resolve.

@param timeout: The lookup timeout, ignore here.
zFakeResolver couldn't find )r   r(  KeyErrorr   r    )rq   r1  r2  s   &&&rZ   getHostByNameFakeResolver.getHostByName  sC    	N4::d+,, 	N'Dt'KLMM	Ns    &AAr.  N)rX   )	r   r   r   r   r   rr   r7  r   r   r   s   @rZ   r%  r%    s&      N N NrY   r%  c                   l   a  ] tR tRt o Rt]3tRt]R 4       t	]R 4       t
R tR tR tR	 tR
 tRtV tR# )TCPClientTestsBasei  aU  
Base class for builders defining tests related to
L{IReactorTCP.connectTCP}.  Classes which uses this in must provide all of
the documented instance variables in order to specify how the test works.
These are documented as instance variables rather than declared as methods
due to some peculiar inheritance ordering concerns, but they are
effectively abstract methods.

@ivar endpoints: A client/server endpoint creator appropriate to the
    address family being tested.
@type endpoints: L{twisted.internet.test.connectionmixins.EndpointCreator}

@ivar interface: An IP address literal to locally bind a socket to as well
    as to connect to.  This can be any valid interface for the local host.
@type interface: C{str}

@ivar port: An unused local listening port to listen on and connect to.
    This will be used in conjunction with the C{interface}.  (Depending on
    what they're testing, some tests will locate their own port with
    L{findFreePort} instead.)
@type port: C{int}

@ivar family: an address family constant, such as L{socket.AF_INET},
    L{socket.AF_INET6}, or L{socket.AF_UNIX}, which indicates the address
    family of the transport type under test.
@type family: C{int}

@ivar addressClass: the L{twisted.internet.interfaces.IAddress} implementor
    associated with the transport type under test.  Must also be a
    3-argument callable which produces an instance of same.
@type addressClass: C{type}

@ivar fakeDomainName: A fake domain name to use, to simulate hostname
    resolution and to distinguish between hostnames and IP addresses where
    necessary.
@type fakeDomainName: C{str}
Nc                    V P                   e%   V P                   P                  4       P                  # \        V P                  V P
                  4      ^,          # )z
Return the port number to connect to, using C{self._port} set up by
C{listen} if available.

@return: The port number to connect to.
@rtype: C{int}
)_portgetHostri   r?   r  familyr   s   &rZ   ri   TCPClientTestsBase.port  sA     ::!::%%',,,DNNDKK8;;rY   c                .    V P                   P                  # )z;
Return the interface attribute from the endpoints object.
)	endpointsr  r   s   &rZ   r  TCPClientTestsBase.interface  s    
 ~~'''rY   c                ^    VP                  ^ W P                  R7      V n        V P                  # )z
Start a TCP server with the given C{factory}.

@param reactor: The reactor to create the TCP port in.

@param factory: The server factory.

@return: A TCP port instance.
r  )	listenTCPr  r<  rq   r   factorys   &&&rZ   listenTCPClientTestsBase.listen!  s)     &&q'^^&L
zzrY   c                P    VP                  V P                  V P                  V4      # )z
Start a TCP client with the given C{factory}.

@param reactor: The reactor to create the connection in.

@param factory: The client factory.

@return: A TCP connector instance.
)
connectTCPr  ri   rE  s   &&&rZ   re   TCPClientTestsBase.connect.  s!     !!$..$))WEErY   c                  a a
aa \        4       oS P                  4       o\        4       pSVn        \	        S S4        ! R R\
        4      o
S P                  P                  S4      P                  V4      pV
VV 3R lpVP                  V4      pV 3R lpR pVP                  WV4       V3R lpVP                  V4      pVP                  \        P                  4       V3R lp	VP                  V	4       S P                  S4       R# )	zZ
When the factory's C{buildProtocol} returns L{None} the connection is
gracefully closed.
c                   &   a  ] tR tRt o R tRtV tR# )ETCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.NoneFactoryiG  c                    R # rW   rX   )rq   rj   s   &&rZ   buildProtocolSTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.NoneFactory.buildProtocolH  s    rY   rX   Nr   r   r   r   rP  r   r   r   s   @rZ   NoneFactoryrN  G  s      rY   rS  c                    < S! 4       pSP                   P                  SV P                  4       4      pVP                  V4      # rW   )rA  rf   r=  re   )ri   clientFactoryendpointrS  r   rq   s   &  rZ   listenedBTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.listenedM  s7    'MM~~,,WdllnEH##M22rY   c                 4   < SP                  R V : R24       R# )z.Stream client endpoint connect succeeded with z%, should have failed with NoProtocol.N)r   )r   rq   s   &rZ   connectSucceededJTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.connectSucceededT  s    II9ADrY   c                 0    V P                  \        4       R # rW   )trapr!   )reasons   &rZ   connectFailedGTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.connectFailedZ  s    KK
#rY   c                    < S# rW   rX   )ignoredr   s   &rZ   	connectedCTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.connected_  s     "!rY   c                 (   < SP                  4        R # rW   stop)rb  r   s   &rZ   disconnectedFTCPClientTestsBase.test_buildProtocolReturnsNone.<locals>.disconnectedj  s    
 LLNrY   N)r   buildReactorrM   protocolConnectionLostrC   r0   rA  r   rG  addCallbackaddCallbacks
addErrbackrG   err
runReactor)rq   serverFactory	listeningrW  
connectingrZ  r_  rc  disconnectingrh  rS  r   r   s   f         @@@rZ   test_buildProtocolReturnsNone0TCPClientTestsBase.test_buildProtocolReturnsNone:  s    
 "##%')/=, 	D'"	- 	 NN))'299-H		3
 **84
		$ 	 0@	" #..y9 	  )	 	!!,/ rY   c                <  a a	a
aaa \        S P                  S P                  4      R,          w  rS P                  4       oS P                  o
SP                  \        S
S P                  /4      4       SP                  ^ \        P                  ! \        4      VR7      oSP                  4       pRRRRRR/o ! VV3R lR\        4      p\        S4      o	VS	n        V	V
VV V3R	 lp\        SV4       S P                  S4       S	P                   '       d*   S P#                  S	P                   P%                  4       4       R
P'                  SR,          P(                  SR,          P*                  \-        SR,          4      4      pV.\/        \0        P2                  ! S P                  S	P4                  4      ^ ,          R,          R,          4      ,           pV.\/        \0        P2                  ! S P                  VP6                  4      ^ ,          R,          R,          4      ,           pS P9                  SR,          S P:                  ! R.VO5!  4       S P9                  SR,          S P:                  ! R.VO5!  4       S P9                  \=        SR,          4      V4       R# )ar  
A client's transport's C{getHost} and C{getPeer} return L{IPv4Address}
instances which have the dotted-quad string form of the resolved
address of the local and remote endpoints of the connection
respectively as their C{host} attribute, not the hostname originally
passed in to
L{connectTCP<twisted.internet.interfaces.IReactorTCP.connectTCP>}, if a
hostname was used.
Nr'  Nr  rh   Npeerinstancec                   0   <a  ] tR tRt o VV3R ltRtV tR# )7TCPClientTestsBase.test_addresses.<locals>.CheckAddressi  c                ~   < VP                  4       SR &   VP                  4       SR&   VSR&   SP                  4        R# )rh   ry  rz  N)r=  getPeerrg  )rq   	transportr   transportDatas   &&rZ   makeConnectionFTCPClientTestsBase.test_addresses.<locals>.CheckAddress.makeConnection  s<    (1(9(9(;f%(1(9(9(;f%,5j)rY   rX   Nr   r   r   r   r  r   r   )r   r   r  s   @rZ   CheckAddressr|    s      rY   r  c                  B  <  \        SP                  SP                  4      p SP                  V ^,          3p\        P                  ! RV 24        SP                  SSP                  4       P                  SVR7       V ^,          Sn        R#   \         d     K  i ; i)Tz!Connect attempt with bindAddress )bindAddressN)
r?   r  r>  rG   msgrJ  r=  ri   	boundPortr   )ri   r  rU  
fakeDomainr   rq   r   s     rZ   	connectMe4TCPClientTestsBase.test_addresses.<locals>.connectMe  s    #DNNDKK@#~~tAw7;K=IJ&&"(--%$/	 '  /31gM+	 ( s   -B BBz<{} to {} at {:x}>   NNTCP)r?   r  r>  rj  fakeDomainNameinstallResolverr%  rD  r0   forProtocolr/   r=  r=   r   rB   rp  
failReasonr   getTracebackr*  	__class__addridr   rc   rd   r  ri   r   addressClassrepr)rq   rh   rb  r  r  r  transportReprr  
serverPortrU  r  r   r   r  s   f        @@@@@rZ   test_addresses!TCPClientTestsBase.test_addressesu  s$    %T^^T[[A"E##%((
j$..-I JK""}((2d # 
 (vtZF	 	8 	 W!-	 	$ 	GY/ ###IIm..;;=>,33*%//*%**}Z()
 FTt~~}/F/FGJ2NrR
 
	 Vdt~~}/A/AB1EbI"M
 

 	v.0A0A%0T)0TUv.0A0A%0U*0UVmJ78-HrY   c                  a aaaa	a
a S P                  4       o
\        4       o. o\        P                  ! \        4      pS
P                  ^ VS P                  R7      pS P                  P                  S
VP                  4       4      p\        4       p\        Vn        VP                  V4      oVVV 3R lo	V3R loVVV	V
3R lp\        S
V4       S P                  S
4       S P                  \!        S4      ^RS 24       \#        S^ ,          \$        4      '       d   S^ ,          P'                  4        S^ ,          R8X  d   \)        R4      hS P                  \        P*                  \-        S^ ,          4      4       R# )	z
If the context factory passed to L{ITCPTransport.startTLS} raises an
exception from its C{getContext} method, that exception is raised by
L{ITCPTransport.startTLS}.
r  c                    < \         P                  ! V P                  4      '       g   SP                  R 4       R# SP                  SP	                  \
        V P                  P                  S4      4       R# )skipN)r-   
providedByr  r~   assertRaises
ValueErrorr  )r   brokenFactoryresultsrq   s   &rZ   rc  5TCPClientTestsBase.test_badContext.<locals>.connected  sS     ++H,>,>??v&%%"H$6$6$?$?rY   c                 *   < SP                  V 4       R # rW   r~   )failurer  s   &rZ   r_  9TCPClientTestsBase.test_badContext.<locals>.connectFailed  s    NN7#rY   c                  v   < S P                  S4       S P                  S4       S P                  V3R  l4       R# )c                 $   < SP                  4       # rW   rf  ignr   s   &rZ   r[   ETCPClientTestsBase.test_badContext.<locals>.whenRun.<locals>.<lambda>  s    rY   N)rl  rn  addBoth)connectDeferredr_  rc  r   s   rZ   whenRun3TCPClientTestsBase.test_badContext.<locals>.whenRun  s.    ''	2&&}5##$>?rY   zmore than one callback result: r  z&Reactor does not support ITLSTransportN)rj  r8   r0   r  r/   rD  r  rA  rf   r=  r.   r   re   rB   rp  r   r   
isinstancerH   raiseExceptionrN   r   r)  )rq   rq  ri   rV  rU  r  r  r  r_  rc  r   r  s   f     @@@@@@rZ   test_badContext"TCPClientTestsBase.test_badContext  s*    ##%,.%11(;  MT^^ L>>(($,,.A%!)"**=9		$	@ 	@
 	GW- Wq,KG9*UVgaj'**AJ%%'1:CDD-55s71:GrY   )r<  )r   r   r   r   r   r*   requiredInterfacesr<  propertyri   r  rG  re   ru  r  r  r   r   r   s   @rZ   r:  r:    se     $L &E
< 
< ( (
F9!vHIT0H 0HrY   r:  c                   H    ] tR tRtRtRt]P                  t]	t
]! 4       tRtR# )TCP4ClientTestsBuilderi  zY
Builder configured with IPv4 parameters for tests related to
L{IReactorTCP.connectTCP}.
zsome-fake.domain.example.comrX   N)r   r   r   r   r   r  rc   AF_INETr>  r   r  r  rA  r   rX   rY   rZ   r  r    s#    
 4N^^FLIrY   r  c                   F   a  ] tR tRt o Rt]P                  t]t	R t
RtV tR# )TCP6ClientTestsBuilderi  zY
Builder configured with IPv6 parameters for tests related to
L{IReactorTCP.connectTCP}.
c                Z    \        4       V n        V P                  P                  V n        R # rW   )r  rA  r  r  r   s   &rZ   r   TCP6ClientTestsBuilder.setUp	  s!     % #nn66rY   )rA  r  N)r   r   r   r   r   rc   AF_INET6r>  r   r  r   r   r   r   s   @rZ   r  r    s$     
 __FL
7 
7rY   r  c                   <   a  ] tR tRt o Rt]3tR tR tR t	Rt
V tR# )TCPConnectorTestsBuilderi  zM
Tests for the L{IConnector} provider returned by L{IReactorTCP.connectTCP}.
c                ,  aaa	 \        4       pV P                  4       oSP                  ^ WP                  R7      pW!n        VP                  4       P                  p. o. o	\        4       pVV	3R lVn        SP                  Vn	        SP                  V P                  W44      pV P                  \        P                  ! V4      4       VP                  4       pV P                  VP                   R4       V P                  VP"                  V P                  4       V P                  VP                  V4       VP$                  P'                  V3R l4       V P)                  S4       S	^ ,          P+                  \,        4       V P                  SWU.4       R# )a%  
L{IReactorTCP.connectTCP} returns an object which provides
L{IConnector}.  The destination of the connector is the address which
was passed to C{connectTCP}.  The same connector object is passed to
the factory's C{startedConnecting} method as to the factory's
C{clientConnectionLost} method.
r  c                 H   < SP                  V 4      SP                  V4      3# rW   r  )	connectorr^  seenConnectorsseenFailuress   &&rZ   r[   ATCPConnectorTestsBuilder.test_connectorIdentity.<locals>.<lambda>/  s%    !!),'H
rY   r  c                 $   < SP                  4       # rW   rf  _r   s   &rZ   r[   r  <      GLLNrY   N)rK   rj  rD  r  ri   r=  rJ   clientConnectionLostr~   startedConnectingrJ  r  r#   r  getDestinationr   typerh   whenStoppedr  rp  r]  r   )
rq   rq  tcpPort
portNumberrU  r  destr   r  r  s
   &      @@@rZ   test_connectorIdentity/TCPConnectorTestsBuilder.test_connectorIdentity  s9    '(##%##A}#O$__&++
.0.
* +9*?*?'&&t~~zQ	
--i89'')E*DNN3J/!!))*BC Q^,))?@rY   c                J  a aaaa \        4       pS P                  4       oSP                  ^ VS P                  R7      pVP	                  4       P
                  o. oVV3R lp\        4       oVSn        SP                  P                  V3R l4       SP                  VVVV 3R l4       S P                  S4       S'       d'   S P                  S^ ,          P                  4       4       SP                  P                  \         4       S P#                  SP$                  ^4       R# )z
Calling L{IConnector.stopConnecting} in C{Factory.startedConnecting}
results in C{Factory.clientConnectionFailed} being called with
L{error.UserError} as the reason.
r  c                    <  V P                  4        R #   \         d.    SP                  \        4       4       SP	                  4         R # i ; irW   )stopConnectingr   r~   rH   rg  )r  fatalErrorsr   s   &rZ   r  ATCPConnectorTestsBuilder.test_userFail.<locals>.startedConnectingP  s<    ((* ""79-s    4AAc                 $   < SP                  4       # rW   rf  r  s   &rZ   r[   8TCPConnectorTestsBuilder.test_userFail.<locals>.<lambda>Z  r  rY   c                  >   < SP                  SP                  SS 4      # rW   )rJ  r  )rU  r  r   rq   s   rZ   r[   r  ]  s    G&&t~~z=QrY   N)rM   rj  rD  r  r=  ri   rJ   r  r  r  callWhenRunningrp  r   r  r^  r]  r"   r   failed)rq   rq  r  r  rU  r  r  r   s   f   @@@@rZ   test_userFail&TCPConnectorTestsBuilder.test_userFailC  s     ()##%##A}#O__&++
	 /0*;'!!))*BCQ	
 	 IIk!n1134!!),--q1rY   c                  aaa \        4       pV P                  4       oSP                  ^ WP                  R7      pW!n        VP                  4       P                  p\        4       oR pVSn        SP                  V P                  VS4       . oVVV3R lpSP                  P                  V4       V P                  S4       SP                  P                  \        4       V P                  SR.4       R# )zn
Calling L{IConnector.connect} in C{Factory.clientConnectionLost} causes
a new connection attempt to be made.
r  c                 &    V P                  4        R # rW   )re   )r  r^  s   &&rZ   r  ETCPConnectorTestsBuilder.test_reconnect.<locals>.clientConnectionLostt  s    rY   c                    < SP                   pSP                  VP                  VP                  34       SP	                  4        R # rW   )lastProtocolr~   madeclosedrg  )rb  prU  protocolMadeAndClosedr   s   & rZ   reconnectFailed@TCPConnectorTestsBuilder.test_reconnect.<locals>.reconnectFailed|  s2    **A!((!&&!(();<LLNrY   N)r  r  )rK   rj  rD  r  ri   r=  rL   r  rJ  failDeferredrl  rp  r^  r]  r   r   )	rq   rq  r  r  r  r  rU  r  r   s	   &     @@@rZ   test_reconnect'TCPConnectorTestsBuilder.test_reconnectg  s    
 '(##%##A}#O$__&++
')	  .B*4>>:}E "	
 	""..? !!"89.9rY   rX   N)r   r   r   r   r   r*   r  r  r  r  r   r   r   s   @rZ   r  r    s+      &$AL"2H: :rY   r  c                   6    ] tR tRtRt]P                  t]t	Rt
R# )TCP4ConnectorTestsBuilderi  r  rX   N)r   r   r   r   r  rc   r  r>  r   r  r   rX   rY   rZ   r  r    s    I^^FLrY   r  c                   B   a  ] tR tRt o ]P
                  t]tR t	Rt
V tR# )TCP6ConnectorTestsBuilderi  c                $    \        4       V n        R # rW   r!  r   s   &rZ   r   TCP6ConnectorTestsBuilder.setUp  r#  rY   r  N)r   r   r   r   rc   r  r>  r   r  r   r   r   r   s   @rZ   r  r    s     __FL3 3rY   r  c                h    \         P                   ! W4      pV P                  VP                  4       V# )z
Create a socket for the duration of the given test.

@param test: the test to add cleanup to.

@param addressFamily: an C{AF_*} constant

@param socketType: a C{SOCK_*} constant.

@return: a socket object.
)rc   
addCleanupr   )testaddressFamily
socketTyper   s   &&& rZ   createTestSocketr    s'     --
2COOCIIJrY   c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )_IExhaustsFileDescriptorsi  z
A way to trigger C{EMFILE}.
c                     R# )z
Open file descriptors until C{EMFILE} is reached.

This can raise any exception except an L{OSError} whose
C{errno} is C{EMFILE}.  Any exception raised to the caller
implies L{release}.
NrX   rX   rY   rZ   exhaust!_IExhaustsFileDescriptors.exhaust  r   rY   c                     R# z4
Release all file descriptors opened by L{exhaust}.
NrX   rX   rY   rZ   release!_IExhaustsFileDescriptors.release  r   rY   c                     R# )
Return the number of opened file descriptors.

@return: The number of opened file descriptors; this will be
    zero if this instance has not opened any.
@rtype: L{int}
NrX   rX   rY   rZ   r   _IExhaustsFileDescriptors.count  r   rY   rX   N
r   r   r   r   r   r  r  r   r   r   r   s   @rZ   r  r    s     
 rY   r  )auto_attribsc                      a  ] tR tRt o Rt]! 4       t]P                  ! R RR7      t	]P                  ! ]
P                  RR7      t]P                  ! ]P                  ! ]4      RRR7      tR tR tR	 tV 3R
 ltRtV tR# )_ExhaustsFileDescriptorsi  a?  
A class that triggers C{EMFILE} by creating as many file
descriptors as necessary.

@ivar fileDescriptorFactory: A factory that creates a new file
    descriptor.
@type fileDescriptorFactory: A L{callable} that accepts no
    arguments and returns an integral file descriptor, suitable
    for passing to L{os.close}.
c                 .    \         P                  ! ^ 4      # r   )osduprX   rY   rZ   r[   !_ExhaustsFileDescriptors.<lambda>  s    q	rY   F)defaultr  )r  initr  c                   \         P                  ! 4           V P                  4       pV P                  P	                  V4       K/    \
         d+   pTP                  \        P                  8X  d    Rp?M	h Rp?ii ; iT P                  P                  RT P                  4       R7       R#   \         d    T P                  4        h i ; i)z3
Open file descriptors until C{EMFILE} is reached.
NzCEMFILE reached by opening {openedFileDescriptors} file descriptors.)openedFileDescriptors)gccollect_fileDescriptorFactory_fileDescriptorsr~   OSErrorerrnoEMFILE_loginfor   r   r  rq   fdes   &  rZ   r   _ExhaustsFileDescriptors.exhaust  s    
 	

	5446B ))004  ww%,,. IINN=&*jjl  	  	LLN	s9   B+ A B+ A;A60B+ 5A66A;;B+ +Cc                    V P                   '       d/   V P                   P                  4       p V P                  V4       K@  R#   \         d,   pTP                  \        P
                  8X  d    Rp?Kr  h Rp?ii ; ir  )r  pop_closer  r  EBADFr   s   &  rZ   r   _ExhaustsFileDescriptors.release  sa     ###&&**,BB $  77ekk)s   A A9A43A44A9c                ,    \        V P                  4      # )r  )r   r  r   s   &rZ   r   _ExhaustsFileDescriptors.count  s     4(())rY   c                   < V ^8  d   Qh/ S[ S[,          ;R&   S[. S[3,          ;R&   S[S[.R3,          ;R&   S[S[,          ;R&   # )r'  r  r  Nr&  r  )r   rF   r   r4  r   )r*  r   s   "rZ   r+  %_ExhaustsFileDescriptors.__annotate__  sZ      6
%  %RW-  $ cUD[!I% & 3i ' rY   rX   N)r   r   r   r   r   rF   r  attribr  r  r   r&  Factoryr   r  r  r  r   __annotate_func__r   r   r   s   @rZ   r  r    ss     	 $XD04!1 %)GGBHH5$IF"&''T"U#4*}  rY   r  9Reserved EMFILE file descriptor not supported on Windows.c                   `   a  ] tR tRt o Rt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# )ExhaustsFileDescriptorsTestsi  z(
Tests for L{_ExhaustsFileDescriptors}.
c                n    \        4       V n        V P                  V P                  P                  4       R # rW   )r  	exhausterr  r  r   s   &rZ   r   "ExhaustsFileDescriptorsTests.setUp  s$    13 	../rY   c                T    \        \        P                  4      P                  4        R# )zH
Attempt to open a file; if successful, the file is immediately
closed.
N)openr  devnullr   r   s   &rZ   	openAFile&ExhaustsFileDescriptorsTests.openAFile  s    
 	RZZ rY   c                :    \        \        V P                  4       R# )zM
L{_ExhaustsFileDescriptors} instances provide
L{_IExhaustsFileDescriptors}.
N)r   r  r5  r   s   &rZ   test_providesInterface3ExhaustsFileDescriptorsTests.test_providesInterface"  s    
 	.?rY   c                j   V P                  V P                  P                  4       ^ 4       V P                  P                  4        V P	                  V P                  P                  4       ^ 4       V P                  P                  4        V P                  V P                  P                  4       ^ 4       R# )zP
L{_ExhaustsFileDescriptors.count} returns the number of open
file descriptors.
N)r   r5  r   r  assertGreaterr  r   s   &rZ   
test_count'ExhaustsFileDescriptorsTests.test_count)  s{    
 	--/3 4>>//115 --/3rY   c                   V P                  V P                  P                  4       V P                  P                  4        V P	                  \
        V P                  4      pV P                  VP                  \        P                  4       R# )zc
L{_ExhaustsFileDescriptors.exhaust} causes the process to
exhaust its available file descriptors.
N)
r  r5  r  r  r  IOErrorr:  r   r  r  )rq   	exceptions   & rZ   test_exhaustTriggersEMFILE7ExhaustsFileDescriptorsTests.test_exhaustTriggersEMFILE4  sX    
 	../ %%gt~~>	%,,7rY   c                b    R p\        V4      pV P                  \        VP                  4       R# )z
An L{OSError} raised within
L{_ExhaustsFileDescriptors.exhaust} with an C{errno} other
than C{EMFILE} is reraised to the caller.
c                  D    \        \        P                  ^,           R4      h)r  z
Not EMFILE)r  r  r  rX   rY   rZ   raiseOSErrorLExhaustsFileDescriptorsTests.test_exhaustRaisesOSError.<locals>.raiseOSErrorE  s    %,,*L99rY   N)r  r  r  r  )rq   rJ  r5  s   &  rZ   test_exhaustRaisesOSError6ExhaustsFileDescriptorsTests.test_exhaustRaisesOSError>  s)    	: -\:	'9#4#45rY   c                    V P                   P                  4        V P                   P                  4        V P                  4        R# )zK
L{_ExhaustsFileDescriptors.release} releases all opened
file descriptors.
N)r5  r  r  r:  r   s   &rZ   test_release)ExhaustsFileDescriptorsTests.test_releaseK  s.    
 	  rY   c                  a . oV3R lp\        V4      pV P                  VP                  4       V P                  \        VP
                  4       V P                  \        S4      ^4       V P                  VP                  4       ^ 4       S FR  pV P                  \        \        P                  V4      pV P                  VP                  \        P                  4       KT  	  R# )z{
L{_ExhaustsFileDescriptors.exhaust} closes any opened file
descriptors if an exception occurs during its exhaustion loop.
c                     < \        S4      ^8X  d   \        R4      h\        P                  ! ^ 4      p SP	                  V 4       V # )   z9test_fileDescriptorsReleasedOnFailure fake open exception)r   r  r  r  r~   r!  fileDescriptorss    rZ   failsAfterThree[ExhaustsFileDescriptorsTests.test_fileDescriptorsReleasedOnFailure.<locals>.failsAfterThree\  sB    ?#q( R  VVAY&&r*	rY   N)r  r  r  r  r  r  r   r   r   r  r  fstatr  r'  )rq   rV  r5  r!  rE  rU  s   &    @rZ   %test_fileDescriptorsReleasedOnFailureBExhaustsFileDescriptorsTests.test_fileDescriptorsReleasedOnFailureU  s    
 	 -_=		))**i&7&78_-q1*A.!B))'288R@IY__ekk: "rY   c                ^  a . oV3R lp\        V4      pV P                  VP                  4       VP                  4        V P	                  VP                  4       ^ 4       \        P                  ! S^ ,          4       VP                  4        V P                  VP                  4       ^ 4       R# )z{
L{_ExhaustsFileDescriptors.release} continues to close opened
file descriptors even when closing one fails with C{EBADF}.
c                  V   < \         P                  ! ^ 4      p SP                  V 4       V # r  )r  r  r~   rT  s    rZ   recordFileDescriptorsTExhaustsFileDescriptorsTests.test_releaseIgnoresEBADF.<locals>.recordFileDescriptorsx  s#    B""2&IrY   N)	r  r  r  r  r@  r   r  r   r   )rq   r]  r5  rU  s   &  @rZ   test_releaseIgnoresEBADF5ExhaustsFileDescriptorsTests.test_releaseIgnoresEBADFq  s    
 	
 --BC		))*9??,a0
#$*A.rY   c                  a . oV3R lpR p\        WR7      pV P                  VP                  4       ^ 4       VP                  4        V P	                  VP                  4       ^ 4       V P                  \        VP                  4       R# )z
An L{OSError} raised within
L{_ExhaustsFileDescriptors.release} with an C{errno} other than
C{EBADF} is reraised to the caller.
c                     < \        S 4      ^8X  d   \        \        P                  R4      hS P	                  R4       S R,          # )rS  zToo many filesr  )r   r  r  r  r~   )fakeFileDescriptorss   rZ   
opensThreeJExhaustsFileDescriptorsTests.test_releaseRaisesOSError.<locals>.opensThree  s<    &'1,ell,<==&&r*&r**rY   c                     \        ^R4      h)   z&test_releaseRaisesOSError fake OSError)r  )r!  s   &rZ   failingCloseLExhaustsFileDescriptorsTests.test_releaseRaisesOSError.<locals>.failingClose  s    "FGGrY   )r   N)r  r   r   r  r@  r  r  r  )rq   rd  rh  r5  rc  s   &   @rZ   test_releaseRaisesOSError6ExhaustsFileDescriptorsTests.test_releaseRaisesOSError  sr     !	+	H -ZL	*A.9??,a0'9#4#45rY   )r5  N)r   r   r   r   r   r   r:  r=  rA  rF  rL  rO  rY  r_  rj  r   r   r   s   @rZ   r3  r3    sB     0!@	486;8/.6 6rY   r3  c                z  aaaaaaa V P                  SP                  4       \        4       o\        4       pVSn        R.oVV3R lpVP                  V4       \        4       o\        P                  ! S4      '       d+   VVVVVV3R lpSP                  ^ SP                  ^ V4       M>S! SS4      p	V	P                  4       p
S! SV
S4       SP                  SP                  4       VV3R lpSP                  P                  V4       SP                  P                  V4       V! S4       . pVP                  VP                   4       V P#                  VR4       V P%                  SP                  4       V P'                  SP                  4       V P)                  \*        SP,                  P.                  4       R# )a  
Assert that an L{IListeningPort} immediately closes an accepted
peer socket when the number of open file descriptors exceeds the
soft resource limit.

@param testCase: The test case under which to run this assertion.
@type testCase: L{trial.unittest.SynchronousTestCase}

@param exhauster: The file descriptor exhauster.
@type exhauster: L{_ExhaustsFileDescriptors}

@param reactor: The reactor under test.

@param runReactor: A callable that will synchronously run the
    provided reactor.

@param listen: A callback to bind to a port.
@type listen: A L{callable} that accepts two arguments: the
    provided C{reactor}; and a L{ServerFactory}.  It must return
    an L{IListeningPort} provider.

@param connect: A callback to connect a client to the listening
    port.
@type connect: A L{callable} that accepts three arguments: the
    provided C{reactor}; the address returned by
    L{IListeningPort.getHost}; and a L{ClientFactory}.  Its return
    value is ignored.
Fc                 2   < SP                  4        R S^ &   R# TNrf  )r  r   serverConnectionCompleteds   &rZ   stopReactorIfServerAccepted=assertPeerClosedOnEMFILE.<locals>.stopReactorIfServerAccepted  s    '+!!$rY   c                  n   < S! SS4      p V P                  4       pS! SVS4       SP                  4        R # rW   )r=  r  )ri   listeningHostrU  re   r5  rG  r   rq  s     rZ   inner'assertPeerClosedOnEMFILE.<locals>.inner  s2    '=1D LLNMG]M:rY   c                 H   < SP                  4        SP                  4        V # rW   )r  rg  )r   r5  r   s   &rZ   "stopReactorAndCloseFileDescriptorsDassertPeerClosedOnEMFILE.<locals>.stopReactorAndCloseFileDescriptors  s    rY   z1Server accepted connection; EMFILE not triggered.N)r  r  rM   r   protocolConnectionMaderl  rL   r+   r  	callLaterr=  r  r  deferredr  r  r~   r	  assertNoResultsuccessResultOfr  r   
lostReasonr  )testCaser5  r   rp  rG  re   serverConnectionMaderp  rt  ri   rs  rw  noResultrU  ro  rq  s   &ff&ff       @@@rZ   assertPeerClosedOnEMFILEr    sq   H 	))*#%M#:+?M(!&, $$%@A#%Mw''	  	  	!W..59 g}-6	 1 12
 ""#EF&&'IJwH  1#VWM667]334  //rY   c                   `   a  ] tR tRt o Rt]! ]4       ! R R4      4       tR tR t	R t
RtV tR	# )
AssertPeerClosedOnEMFILETestsi  z(
Tests for L{assertPeerClosedOnEMFILE}.
c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )+AssertPeerClosedOnEMFILETests.NullExhausteri  z!
An exhauster that does nothing.
c                    R# )z*
See L{_IExhaustsFileDescriptors.exhaust}
NrX   r   s   &rZ   r  3AssertPeerClosedOnEMFILETests.NullExhauster.exhaust	  r   rY   c                    R# )z*
See L{_IExhaustsFileDescriptors.release}
NrX   r   s   &rZ   r  3AssertPeerClosedOnEMFILETests.NullExhauster.release  r   rY   c                    R# )z(
See L{_IExhaustsFileDescriptors.count}
NrX   r   s   &rZ   r   1AssertPeerClosedOnEMFILETests.NullExhauster.count  r   rY   rX   Nr
  r   s   @rZ   NullExhausterr    s     		
	
	 	rY   r  c                B    \        4       V n        \        4       V n        R # rW   )rD   r   rO   r  r   s   &rZ   r   #AssertPeerClosedOnEMFILETests.setUp  s    $+-rY   c                B    \        \        V P                  4       4       R# )zB
L{NullExhauster} instances provide
L{_IExhaustsFileDescriptors}.
N)r   r  r  r   s   &rZ   #test_nullExhausterProvidesInterfaceAAssertPeerClosedOnEMFILETests.test_nullExhausterProvidesInterface  s    
 	.0B0B0DErY   c                V  a V P                  4       pR.oV3R lpV3R lpR pV P                  V P                  P                  \        V P                  VV P
                  VVVR7      pV P                  R\        V4      4       V P                  V P
                  P                  4       R# )z}
If the exhauster fails to trigger C{EMFILE} and a connection
reaches the server, the reactor is stopped and the test fails.
Nc                    < V P                  4        S^ ,          P                  \        RRR4      4      pVP                  \	        4       4       R# )r   r  r  i  N)runrP  r   r  rE   )r   protorq  s   & rZ   rp  [AssertPeerClosedOnEMFILETests.test_reactorStoppedOnSuccessfulConnection.<locals>.runReactor+  s@    KKM!!$22E;5E   !23rY   c                 X   < V P                  R RV4      pVP                  4        VS^ &   V# )r  i  )rD  doStart)r   rF  ri   rq  s   && rZ   rG  WAssertPeerClosedOnEMFILETests.test_reactorStoppedOnSuccessfulConnection.<locals>.listen2  s0    $$[$@DOO&M!KrY   c                 ,    V P                  R ^ V4       R# )r  N)rJ  )r   rj   rF  s   &&&rZ   re   XAssertPeerClosedOnEMFILETests.test_reactorStoppedOnSuccessfulConnection.<locals>.connect8  s    {Aw7rY   r  r5  r   rp  rG  re   r  )
r  r  r  failureExceptionr  r   assertInr)  r	  running)rq   r5  rp  rG  re   rE  rq  s   &     @rZ   )test_reactorStoppedOnSuccessfulConnectionGAssertPeerClosedOnEMFILETests.test_reactorStoppedOnSuccessfulConnection#  s    
 &&(		4		8 %%MM**$]]LL! & 	
	 	hI/--.rY   )r   r  N)r   r   r   r   r   r   r  r  r   r  r  r   r   r   s   @rZ   r  r    s>      *+  ,(.F$/ $/rY   r  c                   N   a  ] tR tRt o RtR tR t]! ]R4      R 4       t	Rt
V tR# )	StreamTransportTestsMixiniJ  zJ
Mixin defining tests which apply to any port/connection based transport.
c                   V P                  4       pV P                  4       p\        \        4       ! R R\        4      4       pV! 4       pV P                  W$4      pV P                  VR4      pV P                  V3V^ ,          R,          4       R# )z\
When a port starts, a message including a description of the associated
factory is logged.
c                   &   a  ] tR tRt o R tRtV tR# )NStreamTransportTestsMixin.test_startedListeningLogMessage.<locals>.SomeFactoryiW  c                    R # )Crazy FactoryrX   r   s   &rZ   	logPrefixXStreamTransportTestsMixin.test_startedListeningLogMessage.<locals>.SomeFactory.logPrefixY  s    &rY   rX   N)r   r   r   r   r  r   r   r   s   @rZ   SomeFactoryr  W  s     ' 'rY   r  r  r   N)observerj  r   r%   r0   getListeningPort#getExpectedStartListeningLogMessager   )rq   loggedMessagesr   r  rF  r  expectedMessages   &      rZ   test_startedListeningLogMessage9StreamTransportTestsMixin.test_startedListeningLogMessageO  s    
 ##%	_	%	'- 	' 
&	' -!!'3BB1oV/+^A->y-IJrY   c                F  aaaaa . oV3R loV P                  4       oV P                  S\        4       4      oV P                  S4      p\        P
                  ! S4       VV3R loVVV3R lpSP                  V4       SP                  4        V P                  VS4       R# )z
When a connection is lost, an informative message should be logged
(see L{getExpectedConnectionLostLogMsg}): an address identifying
the port and the fact that it was closed.
c                 R   < SP                  \        P                  ! V 4      4       R # rW   )r~   rG   textFromEventDict)	eventDictr  s   &rZ   logConnectionLostMsgQStreamTransportTestsMixin.test_connectionLostLogMsg.<locals>.logConnectionLostMsgj  s    !!#"7"7	"BCrY   c                 T   < \         P                  ! S4       SP                  4        R # rW   )rG   removeObserverrg  )rb  r  r   s   &rZ   stopReactorHStreamTransportTestsMixin.test_connectionLostLogMsg.<locals>.stopReactorr  s    34LLNrY   c                  |   < \         P                  ! S 4       \        SP                  4      P	                  S4       R # rW   )rG   addObserverr   stopListeningrl  )r  r  r  s   rZ   doStopListeningLStreamTransportTestsMixin.test_connectionLostLogMsg.<locals>.doStopListeningv  s'    OO01!//*66{CrY   N)	rj  r  r0   getExpectedConnectionLostLogMsgrG   r  r  r  r  )rq   r  r  r  r  r  r   r  s   &  @@@@@rZ   test_connectionLostLogMsg3StreamTransportTestsMixin.test_connectionLostLogMsga  s     	D ##%!!'=?;>>qA,-		D 	0o~6rY   r1  c           	         \        V \        4       V P                  4       V P                  V P                  V P
                  R7       R# )z"
See L{assertPeerClosedOnEMFILE}.
r  N)r  r  rj  rp  r  connectToListenerr   s   &rZ   test_closePeerOnEMFILE0StreamTransportTestsMixin.test_closePeerOnEMFILE  s:    
 	!.0%%'((**	
rY   rX   N)r   r   r   r   r   r  r  r   SKIP_EMFILEr  r   r   r   s   @rZ   r  r  J  s2     K$7< KTU
 V
rY   r  c                   .   a  ] tR tRt o RtRtR tRtV tR# )ConnectToTCPListenerMixini  aB  
Provides L{connectToListener} for TCP transports.

@ivar LISTENER_HOST: The host on which the port is expected to be
    listening.  This is specific to avoid compatibility issues
    with Windows, which cannot connect to the wildcard host.
@type LISTENER_HOST: L{str}

@see: U{http://twistedmatrix.com/trac/ticket/1472}
r  c                P    VP                  V P                  VP                  V4      # )al  
Connect to the given listening TCP port.

@param reactor: The reactor under test.
@type reactor: L{IReactorTCP}

@param address: The listening port's address.  Only the
    C{port} component is used; see L{LISTENER_HOST}.
@type address: L{IPv4Address} or L{IPv6Address}

@param factory: The client factory.
@type factory: L{ClientFactory}

@return: The connector
)rJ  LISTENER_HOSTri   )rq   r   rj   rF  s   &&&&rZ   r  +ConnectToTCPListenerMixin.connectToListener  s#      !!$"4"4gllGLLrY   rX   N)	r   r   r   r   r   r  r  r   r   r   s   @rZ   r  r    s     	  MM MrY   r  c                   .   a  ] tR tRt o RtRR ltRtV tR# )ListenTCPMixini  zL
Mixin which uses L{IReactorTCP.listenTCP} to hand out listening TCP ports.
c                (    VP                  W2VR7      # )z 
Get a TCP port from a reactor.
r  )rD  )rq   r   rF  ri   r  s   &&&&&rZ   r  ListenTCPMixin.getListeningPort  s       ) DDrY   rX   Nr   rS   r   r   r   r   r   r  r   r   r   s   @rZ   r  r    s     E ErY   r  c                   .   a  ] tR tRt o RtRR ltRtV tR# )SocketTCPMixini  zU
Mixin which uses L{IReactorSocket.adoptStreamPort} to hand out
listening TCP ports.
c                b   \         P                  ! V4      '       d   RV9   d6   \        P                  p\        P                  ! WC4      ^ ,          ^,          pM\        P
                  pWC3p\        P                  ! V4      pVP                  V4       VP                  ^4       VP                  R4        VP                  VP                  4       VP                  V4      VP                  4        VP                  4        # \        R4      h  TP                  4        TP                  4        i ; i)zQ
Get a TCP port from a reactor, wrapping an already-initialized file
descriptor.
rb   Fz'Reactor does not provide IReactorSocket)r)   r  rc   r  rd   r  bindrG  rv   adoptStreamPortr   r>  r   rN   )rq   r   rF  ri   r  domainrj   portSocks   &&&&&   rZ   r  SocketTCPMixin.getListeningPort  s    
 $$W--i ,,Y=a@C$+}}V,HMM'"OOA  '
!..OO%x !  DEE !  s   6*D "D.rX   Nr  r  r   s   @rZ   r  r    s     
F FrY   r  c                   V  a  ] tR tRt o Rt]3tR tR tR t	]
! ]]4      R 4       t]
! ]]4      R 4       tR tR	 t]
! ]]4      R
 4       t]
! ]]4      R 4       tR tR t]
! ]]4      R 4       t]
! ]]4      R 4       tR t]
! ]]4      R 4       t]
! ]]4      R 4       tV 3R ltRtV tR# )TCPPortTestsMixini  z$
Tests for L{IReactorTCP.listenTCP}
c                F    RW!P                  4       P                  3,          # )zI
Get the message expected to be logged when a TCP port starts listening.
z%s starting on %dr=  ri   )rq   ri   rF  s   &&&rZ   r  5TCPPortTestsMixin.getExpectedStartListeningLogMessage  s     #g||~/B/B%CCCrY   c                >    RVP                  4       P                   R2# )z:
Get the expected connection lost message for a TCP port.
z
(TCP Port z Closed)r  )rq   ri   s   &&rZ   r  1TCPPortTestsMixin.getExpectedConnectionLostLogMsg  s      DLLN//099rY   c                    V P                  4       pV P                  V\        4       4      pVP                  4       pV P	                  V\
        4       R# )zr
When no interface is passed to L{IReactorTCP.listenTCP}, the returned
listening port listens on an IPv4 address.
N)rj  r  r0   r=  assertIsInstancer   )rq   r   ri   rj   s   &   rZ   test_portGetHostOnIPv4(TCPPortTestsMixin.test_portGetHostOnIPv4  sA    
 ##%$$Wmo>,,.g{3rY   c                ^   V P                  4       p\        \        P                  RR7      R,          w  r#V P	                  V\        4       W24      pVP                  4       pV P                  V\        4       V P                  RVP                  4       V P                  W5P                  4       R# )z
When listening on an IPv6 address, L{IListeningPort.getHost} returns
an L{IPv6Address} with C{host} and C{port} attributes reflecting the
address the port is bound to.
::1)r>  r  rx  N)rj  r?   rc   r  r  r0   r=  r  r   r   rh   ri   )rq   r   rh   r  ri   rj   s   &     rZ   test_portGetHostOnIPv6(TCPPortTestsMixin.test_portGetHostOnIPv6  s     ##%'v%PQST$$WmozP,,.g{3-\\2rY   c                    \        4       pV P                  4       pV P                  V\        4       ^ V4      pVP	                  4       pV P                  V\        4       V P                  WP                  4       R# )a   
When a link-local IPv6 address including a scope identifier is passed
as the C{interface} argument to L{IReactorTCP.listenTCP}, the resulting
L{IListeningPort} reports its address as an L{IPv6Address} with a host
value that includes the scope identifier.
N)	r_   rj  r  r0   r=  r  r   r   rh   )rq   	linkLocalr   ri   rj   s   &    rZ   test_portGetHostOnIPv6ScopeID/TCPPortTestsMixin.test_portGetHostOnIPv6ScopeID  s_     ,-	##%$$Wmoq)L,,.g{3LL1rY   c                  a  ! V3R lR\         4      pV! 4       pV P                  4       oV P                  SV^ V4      pVP                  R4        \	        WP                  4       P                  VP                  4       P                  34       V P                  S4       VP                  #   \         dE   pT P                  TP                  \        P                  \        P                  34        Rp?LgRp?ii ; i)a  
Connect C{client} to a server listening on C{interface} started with
L{IReactorTCP.listenTCP} and return the address passed to the factory's
C{buildProtocol} method.

@param client: A C{SOCK_STREAM} L{socket.socket} created with an address
    family such that it will be able to connect to a server listening on
    C{interface}.

@param interface: A C{str} giving an address for a server to listen on.
    This should almost certainly be the loopback address for some
    address family supported by L{IReactorTCP.listenTCP}.

@return: Whatever object, probably an L{IAddress} provider, is passed to
    a server factory's C{buildProtocol} method when C{client}
    establishes a connection.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )CTCPPortTestsMixin._buildProtocolAddressTest.<locals>.ObserveAddressi.  c                D   < SP                  4        Wn        \        4       # rW   )rg  observedAddressr/   )rq   rj   r   s   &&rZ   rP  QTCPPortTestsMixin._buildProtocolAddressTest.<locals>.ObserveAddress.buildProtocol/  s    '.$z!rY   )r  NrR  )r   r   s   @rZ   ObserveAddressr  .  s     " "rY   r  FN)r0   rj  r  rv   re   r=  rh   ri   r  r  r  EINPROGRESSEWOULDBLOCKrp  r  )rq   rf   r  r  rF  ri   r"  r   s   &&&    @rZ   _buildProtocolAddressTest+TCPPortTestsMixin._buildProtocolAddressTest  s    &	"] 	" !"##%$$Wgq)D5!	KF\\^00$,,.2E2EFG 	 &&&  	KMM!''E$5$5u7H7H#IJJ	Ks   =B+ +C:6:C55C:c                    Rp\        V \        P                  \        P                  4      pV P	                  W!4      pV P                  \        R.VP                  4       O5!  V4       R# )z
When a connection is accepted over IPv4, an L{IPv4Address} is passed
to the factory's C{buildProtocol} method giving the peer's address.
r  r  N)r  rc   r  SOCK_STREAMr  r   r   getsockname)rq   r  rf   r  s   &   rZ   test_buildProtocolIPv4Address/TCPPortTestsMixin.test_buildProtocolIPv4AddressA  sT    
  	!$8J8JK88KUBV-?-?-ABOTrY   c                <   Rp\        V \        P                  \        P                  4      pV P	                  W!4      pVP                  4       p\        P                  ! V\        P                  4      ^ ,          pV P                  \        RWT^,          4      V4       R# )z
When a connection is accepted to an IPv6 address, an L{IPv6Address} is
passed to the factory's C{buildProtocol} method giving the peer's
address.
r  r  N)
r  rc   r  r  r  r  getnameinfoNI_NUMERICHOSTr   r   rq   r  rf   r  ry  hostnames   &     rZ   test_buildProtocolIPv6Address/TCPPortTestsMixin.test_buildProtocolIPv6AddressK  sw     	!$9K9KL88K!!#%%dF,A,AB1EUH1g>PrY   c                P   \        4       p\        V \        P                  \        P                  4      pV P                  W!4      pVP                  4       p\        P                  ! V\        P                  4      ^ ,          pV P                  \        RV.VR,          O5!  V4       R# )z
When a connection is accepted to a link-local IPv6 address, an
L{IPv6Address} is passed to the factory's C{buildProtocol} method
giving the peer's address, including a scope identifier.
r  r  N)r_   r  rc   r  r  r  r  r  r  r   r   r  s   &     rZ   $test_buildProtocolIPv6AddressScopeID6TCPPortTestsMixin.test_buildProtocolIPv6AddressScopeID[  s     ,-	!$9K9KL88K!!#%%dF,A,AB1EUH@tBx@/RrY   c                  aa  ! VV3R lR\         4      pV P                  4       o\        4       pWEn        V P	                  SV^ V4      pVP                  R4        \        WP                  4       P                  VP                  4       P                  34       V P                  S4       VP                   #   \         dE   pT P                  TP                  \        P                  \        P                  34        Rp?LgRp?ii ; i)a%  
Connect C{client} to a server listening on C{interface} started with
L{IReactorTCP.listenTCP} and return the address returned by one of the
server transport's address lookup methods, C{getHost} or C{getPeer}.

@param client: A C{SOCK_STREAM} L{socket.socket} created with an address
    family such that it will be able to connect to a server listening on
    C{interface}.

@param interface: A C{str} giving an address for a server to listen on.
    This should almost certainly be the loopback address for some
    address family supported by L{IReactorTCP.listenTCP}.

@param which: A C{str} equal to either C{"getHost"} or C{"getPeer"}
    determining which address will be returned.

@return: Whatever object, probably an L{IAddress} provider, is returned
    from the method indicated by C{which}.
c                   0   <a  ] tR tRt o VV3R ltRtV tR# )ITCPPortTestsMixin._serverGetConnectionAddressTest.<locals>.ObserveAddressi  c                h   < SP                  4        \        VS4      ! 4       V P                  n        R # rW   )rg  getattrrF  rj   )rq   r  r   whichs   &&rZ   r  XTCPPortTestsMixin._serverGetConnectionAddressTest.<locals>.ObserveAddress.makeConnection  s"    '.y%'@'B$rY   rX   Nr  )r   r   r  s   @rZ   r  r    s     C CrY   r  FN)r/   rj  r0   r   r  rv   re   r=  rh   ri   r  r  r  r  r  rp  rj   )	rq   rf   r  r  r  rF  ri   r"  r   s	   &&&f    @rZ   _serverGetConnectionAddressTest1TCPPortTestsMixin._serverGetConnectionAddressTestk  s    *	C 	CX 	C
 ##%/)$$Wgq)D5!	KF\\^00$,,.2E2EFG 	   	KMM!''E$5$5u7H7H#IJJ	Ks   =B6 6D:D  Dc                    Rp\        V \        P                  \        P                  4      pV P	                  W!R4      pV P                  \        R.VP                  4       O5!  V4       R# )z
When a connection is accepted over IPv4, the server
L{ITransport.getHost} method returns an L{IPv4Address} giving the
address on which the server accepted the connection.
r  r=  r  N)r  rc   r  r  r  r   r   getpeername)rq   r  rf   hostAddresss   &   rZ   test_serverGetHostOnIPv4*TCPPortTestsMixin.test_serverGetHostOnIPv4  V      	!$8J8JK::6iXUBV-?-?-ABKPrY   c                B   Rp\        V \        P                  \        P                  4      pV P	                  W!R4      pVP                  4       p\        P                  ! V\        P                  4      ^ ,          pV P                  \        RV.VR,          O5!  V4       R# )z
When a connection is accepted over IPv6, the server
L{ITransport.getHost} method returns an L{IPv6Address} giving the
address on which the server accepted the connection.
r  r=  r  r  N)
r  rc   r  r  r  r  r  r  r   r   rq   r  rf   r  ry  r  s   &     rZ   test_serverGetHostOnIPv6*TCPPortTestsMixin.test_serverGetHostOnIPv6  ~     	!$9K9KL::6iX!!#%%dF,A,AB1EUH@tBx@+NrY   c                R   \        4       p\        V \        P                  \        P                  4      pV P                  W!R4      pVP                  4       p\        P                  ! V\        P                  4      ^ ,          pV P                  \        RV.VR,          O5!  V4       R# )z
When a connection is accepted over IPv6, the server
L{ITransport.getHost} method returns an L{IPv6Address} giving the
address on which the server accepted the connection, including the scope
identifier.
r=  r  r  N)r_   r  rc   r  r  r  r  r  r  r   r   r  s   &     rZ   test_serverGetHostOnIPv6ScopeID1TCPPortTestsMixin.test_serverGetHostOnIPv6ScopeID       ,-	!$9K9KL::6iX!!#%%dF,A,AB1EUH@tBx@+NrY   c                    Rp\        V \        P                  \        P                  4      pV P	                  W!R4      pV P                  \        R.VP                  4       O5!  V4       R# )z
When a connection is accepted over IPv4, the server
L{ITransport.getPeer} method returns an L{IPv4Address} giving the
address of the remote end of the connection.
r  r~  r  N)r  rc   r  r  r  r   r   r  )rq   r  rf   peerAddresss   &   rZ   test_serverGetPeerOnIPv4*TCPPortTestsMixin.test_serverGetPeerOnIPv4  r  rY   c                B   Rp\        V \        P                  \        P                  4      pV P	                  W!R4      pVP                  4       p\        P                  ! V\        P                  4      ^ ,          pV P                  \        RV.VR,          O5!  V4       R# )z
When a connection is accepted over IPv6, the server
L{ITransport.getPeer} method returns an L{IPv6Address} giving the
address on the remote end of the connection.
r  r~  r  r  N)
r  rc   r  r  r  r  r  r  r   r   rq   r  rf   r$  ry  r  s   &     rZ   test_serverGetPeerOnIPv6*TCPPortTestsMixin.test_serverGetPeerOnIPv6  r  rY   c                R   \        4       p\        V \        P                  \        P                  4      pV P                  W!R4      pVP                  4       p\        P                  ! V\        P                  4      ^ ,          pV P                  \        RV.VR,          O5!  V4       R# )z
When a connection is accepted over IPv6, the server
L{ITransport.getPeer} method returns an L{IPv6Address} giving the
address on the remote end of the connection, including the scope
identifier.
r~  r  r  N)r_   r  rc   r  r  r  r  r  r  r   r   r(  s   &     rZ   test_serverGetPeerOnIPv6ScopeID1TCPPortTestsMixin.test_serverGetPeerOnIPv6ScopeID  r"  rY   c                V   < V ^8  d   Qh/ S[ S[S[S[,          ,          ,          ;R&   # r'  r  r   r	   r
   r   )r*  r   s   "rZ   r+  TCPPortTestsMixin.__annotate__        
 !$y/!:;L rY   rX   N)r   r   r   r   r   r*   r  r  r  r  r   ipv6Skipipv6SkipReasonr  r  r  r  r  r	  r  r  r  r   r%  r)  r,  r0  r   r   r   s   @rZ   r  r    s0     @KnD:4 Hn%3 &3 Hn%2 &2$'LU Hn%Q &Q Hn%S &S$L	Q Hn%O &O Hn%O &O 	Q Hn%O &O Hn%O &Os  rY   r  c                       ] tR tRtRtR# )TCPPortTestsBuilderi  rX   Nr   r   r   r   r   rX   rY   rZ   r6  r6         	rY   r6  c                       ] tR tRtRtR# )TCPFDPortTestsBuilderi  rX   Nr7  rX   rY   rZ   r:  r:    r8  rY   r:  c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )StopStartReadingProtocoli  z<
Protocol that pauses and resumes the transport a few times
c                6    R V n         V P                  ^4       R# )rY   N)rn   pauseResumeProducingr   s   &rZ   connectionMade'StopStartReadingProtocol.connectionMade  s    	!!!$rY   c                |   V P                   P                  4        V P                   P                  4        V'       d;   V P                  P                  P                  ^ V P                  V^,
          4       R# V P                  P                  P                  ^ V P                  P                  P                  V 4       R# )z/
Toggle transport read state, then count down.
N)	r  pauseProducingresumeProducingrF  r   rz  r>  readycallback)rq   counters   &&rZ   r>  -StopStartReadingProtocol.pauseResumeProducing  sz     	%%'&&(LL  **1d.G.GSTULL  **1dll.@.@.I.I4PrY   c                   \         P                  ! R \        V4      4       V ;P                  V,          un        \        V P                  4      R8X  d2   V P                  P
                  P                  V P                  4       R# R# )zgot dataNi @  )rG   r  r   rn   rF  rg  rE  rp   s   &&rZ   r   %StopStartReadingProtocol.dataReceived  sS    
CI&		T	tyy>X%LL&&tyy1 &rY   ry   N)
r   r   r   r   r   r?  r>  r   r   r   r   s   @rZ   r<  r<    s     %	Q2 2rY   r<  c                0   a  \        S 4      V 3R l4       pV# )a  
Decorate a L{ReactorBuilder} test function which tests one reactor and one
connected transport.  Run that test method in the context of
C{connectionMade}, and immediately drop the connection (and end the test)
when that completes.

@param testMethod: A unit test method on a L{ReactorBuilder} test suite;
    taking two additional parameters; a C{reactor} as built by the
    L{ReactorBuilder}, and an L{ITCPTransport} provider.
@type testMethod: 3-argument C{function}

@return: a no-argument test method.
@rtype: 1-argument C{function}
c                    <a a \        4       o ! V VV3R  lR\         4      pV! 4       p\        S VS\        4       4       R# )c                   2   <a  ] tR tRt o VVV3R ltRtV tR# )BoneTransportTest.<locals>.actualTestMethod.<locals>.ServerProtocoli+  c                  <  S! SV P                   V P                  4       V P                  e   V P                  P                  4        SP                  e   SP                  P                  4        R # R #   T P                  e   T P                  P                  4        SP                  e   SP                  P                  4        i i ; irW   )r   r  loseConnection)rq   builderother
testMethods   &rZ   r?  QoneTransportTest.<locals>.actualTestMethod.<locals>.ServerProtocol.connectionMade,  s    9wdnnE~~15572668 3 ~~15572668 3s   A5 5ACrX   Nr   r   r   r   r?  r   r   )r   rP  rQ  rR  s   @rZ   ServerProtocolrM  +  s     9 9rY   rU  N)r9   r@   r  )rP  rU  serverProtocolrQ  rR  s   f  @rZ   actualTestMethod*oneTransportTest.<locals>.actualTestMethod'  s7    #%	9 	90 	9 ()
MrY   r   )rR  rW  s   f rZ   oneTransportTestrY    s&      :N N  rY   c                    \         P                  ! V4      '       d"   V P                  W!P                  4       4       R# V P                  W!P                  4       V P                  VP                  4       R# )a.  
Use the given test to assert that the given transport is actively reading
in the given reactor.

@note: Maintainers; for more information on why this is a function rather
    than a method on a test case, see U{this document on how we structure
    test tools
    <http://twistedmatrix.com/trac/wiki/Design/KeepTestToolsOutOfFixtures>}

@param testCase: a test case to perform the assertion upon.
@type testCase: L{TestCase}

@param reactor: A reactor, possibly one providing L{IReactorFDSet}, or an
    IOCP reactor.

@param transport: An L{ITCPTransport}
N)r(   r  r  r   handlesr  readingr  r   r  s   &&&rZ   assertReadingr^  ;  sT    $ (()%7%7%9: 	)__5I--.rY   c                    \         P                  ! V4      '       d"   V P                  W!P                  4       4       R# V P	                  VP
                  4       R# )a5  
Use the given test to assert that the given transport is I{not} actively
reading in the given reactor.

@note: Maintainers; for more information on why this is a function rather
    than a method on a test case, see U{this document on how we structure
    test tools
    <http://twistedmatrix.com/trac/wiki/Design/KeepTestToolsOutOfFixtures>}

@param testCase: a test case to perform the assertion upon.
@type testCase: L{TestCase}

@param reactor: A reactor, possibly one providing L{IReactorFDSet}, or an
    IOCP reactor.

@param transport: An L{ITCPTransport}
N)r(   r  assertNotInr   r	  r\  r]  s   &&&rZ   assertNotReadingra  U  sB    $ ((Y(:(:(<= 	Y../rY   c                   l   a  ] tR tRt o Rt]3tR t]R 4       t	]R 4       t
]R 4       tR tR tR	tV tR
# )TCPConnectionTestsBuilderin  zH
Builder defining tests relating to L{twisted.internet.tcp.Connection}.
c                  a a	a
a \        4       oS P                  4       ;o
Sn        RR.pS
P                  P                  pW!9   d'   \
        P                  ! 4       '       d   \        R4      h\        Sn	        \        4       Sn        \        4       Sn        S
P                  ^ S4      pVP                  4       P                  pV	V
V V3R lpV 3R lo	\!        S
RV4      p\#        4       p\$        Vn	        \'        VP)                  V4      SP                  .4      P+                  WS4      pVP-                  \.        P0                  4       S P3                  S
4       R# )z\
This test verifies transport socket read state after multiple
pause/resumeProducing calls.
Glib2ReactorGtk2Reactorz.This test is broken on gtk/glib under Windows.c                p  < SP                  V ^ ,          4       SP                  V ^,          4       V ^ ,          ^,          V ^,          ^,          3p V ^ ,          P                  P                  RR,          RR,          ,           4       SP                  P	                  SW4      P	                  V3R l4      # )z4
Send several IOCPReactor's buffers' worth of data.
   x   yc                 $   < SP                  4       # rW   rf  r  s   &rZ   r[   RTCPConnectionTestsBuilder.test_stopStartReading.<locals>.proceed.<locals>.<lambda>  s    GLLNrY       )r  r  r   rg  rl  )protosri   cleanupr   rq   sfs   &&rZ   proceed@TCPConnectionTestsBuilder.test_stopStartReading.<locals>.proceed  s     OOF1I&OOF1I&AYq\6!9Q</F1I%%dh&7$(:K&KL77&&w=II* rY   c                &  < SP                  V RR,          RR,          ,           R4       \        \        V^ ,          P                  P                  4      \        V^,          P                  P                  4      \        VP
                  4      .4      # )zd
Make sure IOCPReactor didn't start several WSARecv operations
that clobbered each other's results.
rh  ri  zdid not get the right datarl  )r   r   r   r  rO  r  )rn   rm  ri   rq   s   &&&rZ   rn  @TCPConnectionTestsBuilder.test_stopStartReading.<locals>.cleanup  s}    
 !DH$55,
  !&)"5"5"D"DE!&)"5"5"D"DE!$"4"45 rY   r  N)r0   rj  r   r  r   rI   	isWindowsrN   r<  r   r   rD  rg  rD  r=  ri   r   r.   r/   r   re   rl  rn  rG   ro  rp  )rq   skippedReactorsreactorClassNamer  ri   rp  cccfdrn  r   ro  s   f        @@@rZ   test_stopStartReading/TCPConnectionTestsBuilder.test_stopStartReadingu  s   
 _#0022"*)=9",,55.83E3E3G3GKLL.:*a$yy{
	 
		$  d;_"**R."((34@@L	SWW rY   c                v    VP                  4        \        WV4       VP                  4        \        WV4       R# )zb
When a L{Server} is connected, its C{resumeProducing} method adds it as
a reader to the reactor.
N)rB  ra  rC  r^  rq   r   r   s   &&&rZ   test_resumeProducing.TCPConnectionTestsBuilder.test_resumeProducing  s0     	/ dV,rY   c                ^    VP                  4        VP                  4        \        WV4       R# )z
When a L{Server} has already started disconnecting via
C{loseConnection}, its C{resumeProducing} method does not add it as a
reader to its reactor.
N)rO  rC  ra  r}  s   &&&rZ   &test_resumeProducingWhileDisconnecting@TCPConnectionTestsBuilder.test_resumeProducingWhileDisconnecting  s&     	 /rY   c                    VP                  \        \        R4      4      4       \        WV4       VP	                  4        \        WV4       R# )z}
When a L{Server} has already lost its connection, its
C{resumeProducing} method does not add it as a reader to its reactor.
dummyN)r   rH   r   ra  rC  r}  s   &&&rZ   %test_resumeProducingWhileDisconnected?TCPConnectionTestsBuilder.test_resumeProducingWhileDisconnected  s<     	gi&89:/ /rY   c                     ! R R\         4      p ! R R\         4      pV! 4       p\        WV! 4       \        4       4       V P                  VP                  . RO4       R# )a  
Alice connects to Bob.  Alice writes some bytes and then shuts down the
connection.  Bob receives the bytes from the connection and then pauses
the transport object.  Shortly afterwards Bob resumes the transport
object.  At that point, Bob is notified that the connection has been
closed.

This is no problem for most reactors.  The underlying event notification
API will probably just remind them that the connection has been closed.
It is a little tricky for win32eventreactor (MsgWaitForMultipleObjects).
MsgWaitForMultipleObjects will only deliver the close notification once.
The reactor needs to remember that notification until Bob resumes the
transport.
c                   8   a  ] tR tRt o R tR tR tR tRtV t	R# )QTCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauseri  c                    . V n         R # rW   eventsr   s   &rZ   rr   ZTCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauser.__init__  s	     rY   c                    V P                   P                  R 4       V P                  P                  4        V P                  P                  ^ V P                  4       R# )pausedN)r  r~   r  rB  r   rz  resumer   s   &&rZ   r   ^TCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauser.dataReceived  s<    ""8,--/&&q$++6rY   c                p    V P                   P                  R 4       V P                  P                  4        R# )resumedN)r  r~   r  rC  r   s   &rZ   r  XTCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauser.resume  s$    ""9-..0rY   c                h    V P                   P                  R 4       \        P                  ! W4       R# )lostN)r  r~   r9   r   rq   r^  s   &&rZ   r   `TCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Pauser.connectionLost  s"    ""6*#224@rY   r  N)
r   r   r   r   rr   r   r  r   r   r   r   s   @rZ   Pauserr    s      !7
1A ArY   r  c                   &   a  ] tR tRt o R tRtV tR# )QTCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Clienti  c                p    V P                   P                  R 4       V P                   P                  4        R# )s   some bytes for youN)r  r   rO  r   s   &rZ   r?  `TCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport.<locals>.Client.connectionMade  s%    $$%:;--/rY   rX   NrT  r   s   @rZ   Clientr    s     0 0rY   r  N)r  r  r  )r9   r@   r  r   r  )rq   r  r  pausers   &   rZ   'test_connectionLostAfterPausedTransportATCPConnectionTestsBuilder.test_connectionLostAfterPausedTransport  sL     	A( 	A$	0( 	0
 fh
E(EFrY   c                    \        \        4       ! R R\        4      4       p ! R R\        4      p\        W! 4       V! 4       \	        4       4       R# )a  
If one side half-closes its connection, and then the other side of the
connection calls C{loseWriteConnection}, and then C{loseConnection} in
{writeConnectionLost}, the connection is closed correctly.

This rather obscure case used to fail (see ticket #3037).
c                   ,   a  ] tR tRt o R tR tRtV tR# )HTCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.ListenerProtocoli  c                :    V P                   P                  4        R # rW   )r  loseWriteConnectionr   s   &rZ   readConnectionLost[TCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.ListenerProtocol.readConnectionLost  s    224rY   c                :    V P                   P                  4        R # rW   r  rO  r   s   &rZ   writeConnectionLost\TCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.ListenerProtocol.writeConnectionLost      --/rY   rX   N)r   r   r   r   r  r  r   r   r   s   @rZ   ListenerProtocolr    s     50 0rY   r  c                   &   a  ] tR tRt o R tRtV tR# )>TCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.Clienti
  c                :    V P                   P                  4        R # rW   r  r   s   &rZ   r?  MTCPConnectionTestsBuilder.test_doubleHalfClose.<locals>.Client.connectionMade  r  rY   rX   NrT  r   s   @rZ   r  r  
  s     0 0rY   r  N)r   r$   r9   r@   r  )rq   r  r  s   &  rZ   test_doubleHalfClose.TCPConnectionTestsBuilder.test_doubleHalfClose  sI     
+	,	02 	0 
-	0	0( 	0
 	 &6&8&(JLQrY   rX   N)r   r   r   r   r   r*   r  rz  rY  r~  r  r  r  r  r   r   r   s   @rZ   rc  rc  n  si      &6!p - - 0 0 0 0)GVR RrY   rc  c                   T   a  ] tR tRt o Rt]3tR tR tR t	R t
R tV 3R ltR	tV tR
# )WriteSequenceTestsMixini  zE
Test for L{twisted.internet.abstract.FileDescriptor.writeSequence}.
c                @    \        VRR4      e	   W!n        R# W!n        R# )z
Set the write buffer size for the given transport, mananing possible
differences (ie, IOCP). Bug #4322 should remove the need of that hack.
writeBufferSizeN)r  r  
bufferSize)rq   r  values   &&&rZ   setWriteBufferSize*WriteSequenceTestsMixin.setWriteBufferSize  s     
 9/6B(-%#( rY   c                   a  V 3R lpS P                  4       pS P                  VR\        P                  4      pVP	                  V4       VP                  \        P                  4       S P                  V4       R# )zF
C{writeSequence} sends the data even if C{write} hasn't been called.
c                 h   <a V w  orVV3R  lpW1n         SP                  P                  . RO4       R# )c                    < \         P                  ! R V ,          4       SP                  V R4       SP                  P	                  4        R# )zdata received: %rs   Some sequence splittedN)rG   r  r   r  rO  )rn   rf   rq   s   &rZ   r   ^WriteSequenceTestsMixin.test_writeSequeceWithoutWrite.<locals>.connected.<locals>.dataReceived+  s8    +d23  '@A  //1rY   N)s   Some s	   sequence s   splitted)r   r  r   )	protocolsr   ri   r   rf   rq   s   &   @rZ   rc  HWriteSequenceTestsMixin.test_writeSequeceWithoutWrite.<locals>.connected(  s/    #, FF2
 #/**+PQrY   r  N	rj  getConnectedClientAndServerrc   r  rl  rn  rG   ro  rp  rq   rc  r   ry  s   f   rZ   test_writeSequeceWithoutWrite5WriteSequenceTestsMixin.test_writeSequeceWithoutWrite#  sY    

	R ##%,,Wk6>>R	i 	SWW rY   c                   a  V 3R lpS P                  4       pS P                  VR\        P                  4      pVP	                  V4       VP                  \        P                  4       S P                  V4       R# )zW
C{writeSequence} with an element in the sequence of type unicode raises
C{TypeError}.
c                    < V w  rpSP                  \        VP                  P                  R .4      pSP	                  \        V4      R4       VP                  P                  4        R# )zUnicode is not kosherzData must be bytesN)r  	TypeErrorr  r   r   r)  rO  )r  rf   r   ri   excrq   s   &    rZ   rc  WWriteSequenceTestsMixin.test_writeSequenceWithUnicodeRaisesException.<locals>.connected@  s]    #, FD##6++99<S;TC SX';<++-rY   r  Nr  r  s   f   rZ   ,test_writeSequenceWithUnicodeRaisesExceptionDWriteSequenceTestsMixin.test_writeSequenceWithUnicodeRaisesException:  sX    		. ##%,,Wk6>>R	i 	SWW rY   c                ~  a a \        \        4       ! R R4      4       pV! 4       oVV 3R lpS P                  4       pS P                  VR\        P
                  4      pVP                  V4       VP                  \        P                  4       S P                  V4       S P                  SP                  RR.4       R# )zc
C{writeSequence} pauses its streaming producer if too much data is
buffered, and then resumes it.
c                   @   a  ] tR tRt o RtRtR tR tR tR t	Rt
V tR# )JWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProduceriW  Nc                    . V n         R # rW   actionsr   s   &rZ   rr   SWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProducer.__init__\  	    !rY   c                <    V P                   P                  R 4       R# )pauseNr  r~   r   s   &rZ   rB  YWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProducer.pauseProducing_  s    ##G,rY   c                    V P                   P                  R 4       V P                  P                  P	                  4        V P
                  P                  P                  4        R# )r  N)r  r~   rf   r  unregisterProducerr   rO  r   s   &rZ   rC  ZWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProducer.resumeProducingb  sB    ##H-%%88:
 %%446rY   c                <    V P                   P                  R 4       R# rg  Nr  r   s   &rZ   stopProducingXWriteSequenceTestsMixin.test_streamingProducer.<locals>.SaveActionProducer.stopProducingl      ##F+rY   r  )r   r   r   r   rf   r   rr   rB  rC  r  r   r   r   s   @rZ   SaveActionProducerr  W  s(     FF"-7, ,rY   r  c                 b  < V R ,          w  rVSn         VSn        VP                  P                  SR4       SP	                  SP
                  . 4       SP                  VP                  R4       VP                  P                  R.^,          4       SP	                  SP
                  R.4       R# )rx  T  r  N2   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)rf   r   r  registerProducerr   r  r  r   )r  rf   r   producerrq   s   &  rZ   rc  AWriteSequenceTestsMixin.test_streamingProducer.<locals>.connectedq  s    &r]NF$HO$HO --h=X--r2##F$4$4c:**I;+;<X--y9rY   r  r  r  N)r   r'   rj  r  rc   r  rl  rn  rG   ro  rp  r   r  )rq   r  rc  r   ry  r  s   f    @rZ   test_streamingProducer.WriteSequenceTestsMixin.test_streamingProducerQ  s     
]	#	, 	, 
$	,. &'
	: ##%,,Wk6>>R	i 	SWW  	))GX+>?rY   c                  a aa S o\        \        4       ! V3R lR4      4       pV! 4       oVV 3R lpS P                  4       pS P                  VR\        P
                  4      pVP                  V4       VP                  \        P                  4       S P                  V4       S P                  SP                  RR.4       R# )zi
C{writeSequence} pauses its producer if too much data is buffered only
if this is a streaming producer.
c                   >   <a  ] tR tRt o RtR tV3R ltR tRtV t	R# )MWriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.SaveActionProduceri  Nc                    . V n         R # rW   r  r   s   &rZ   rr   VWriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.SaveActionProducer.__init__  r  rY   c                p  < V P                   P                  R 4       V P                   P                  R 4      ^8X  d'   V P                  P                  P                  4        R# SP                  V P                  P                  R4       V P                  P                  P                  R.^,          4       R# )r  r  Nr  )r  r~   r   rf   r  stopConsumingr  r   )rq   r  s   &rZ   rC  ]WriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.SaveActionProducer.resumeProducing  s{    ##H-<<%%h/14KK))779++DKK,A,A3GKK))77b8HIrY   c                <    V P                   P                  R 4       R# r  r  r   s   &rZ   r  [WriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.SaveActionProducer.stopProducing  r  rY   r  )
r   r   r   r   rf   rr   rC  r  r   r   )r   r  s   @rZ   r  r    s     F"J, ,rY   r  c                    < V ^ ,          pVSn         VP                  P                  SR4       SP                  SP                  R.4       R# )r   Fr  N)rf   r  r  r   r  )r  rf   r  rq   s   & rZ   rc  DWriteSequenceTestsMixin.test_nonStreamingProducer.<locals>.connected  sC    q\F$HO --h>X--z:rY   r  r  N)r   r&   rj  r  rc   r  rl  rn  rG   ro  rp  r   r  )rq   r  rc  r   ry  r  r  s   f    @@rZ   test_nonStreamingProducer1WriteSequenceTestsMixin.test_nonStreamingProducer  s    
 	]	#	, 	, 
$	," &'	; ##%,,Wk6>>R	i 	SWW  	))Hh+?@rY   c                V   < V ^8  d   Qh/ S[ S[S[S[,          ,          ,          ;R&   # r/  r0  )r*  r   s   "rZ   r+  $WriteSequenceTestsMixin.__annotate__  r2  rY   rX   N)r   r   r   r   r   r*   r  r  r  r  r  r  r0  r   r   r   s   @rZ   r  r    s:      @Kn)!.!.3@j*Ai  rY   r  c                   T   a  ] tR tRt o RtR tR tR t]! ]	]
4      R 4       tRtV tR# )	"TCPTransportServerAddressTestMixini  z=
Test mixing for TCP server address building and log prefix.
c                    \        4       h)z|
Helper method returnine a L{Deferred} firing with a tuple of a client
protocol, a server protocol, and a running TCP port.
)NotImplementedError)rq   r   r  r  s   &&&&rZ   r  >TCPTransportServerAddressTestMixin.getConnectedClientAndServer  s    
 "##rY   c                   a aa VVV 3R lpS P                  4       pS P                  VSV4      pVP                  V4       VP                  \        P
                  4       S P                  V4       R# )zD
Helper method to test TCP server addresses on either IPv4 or IPv6.
c                   < V w  rp SP                  R VP                  P                  : RVP                  4       P                  : R2\        VP                  4      4       SP                  RVP                  P                  : RS: 2VP                  P                  4       VP                  P                  w  pSP                  VS4       SP                  RVP                  4       SP                  SVP                  4       VP                  P                  4        R#   TP                  P                  4        i ; i)z<AccumulatingProtocol #z on >zAccumulatingProtocol,,r  N)r   r  	sessionnor=  ri   r)  logstrrF  peerAddressesr  r  rh   rO  )r  rf   r   ri   r$  adressClassr  rq   s   &    rZ   rc  HTCPTransportServerAddressTestMixin._testServerAddress.<locals>.connected  s    #, FD2  ''114<<>3F3FH(()   ''119>$$++ !' < <%%k;?  (8(89  K,<,<=   //1  //1s   C>D" "D>N)rj  r  rl  rn  rG   ro  rp  )rq   r  r  r  rc  r   ry  s   ff&f   rZ   _testServerAddress5TCPTransportServerAddressTestMixin._testServerAddress  sT    
	2. ##%,,WiO	i 	SWW rY   c                L    V P                  R\        P                  \        4      # )z
L{Server} instances have a string representation indicating on which
port they're running, and the connected address is stored on the
C{peerAddresses} attribute of the factory.
r  )r
  rc   r  r   r   s   &rZ   test_serverAddressTCP49TCPTransportServerAddressTestMixin.test_serverAddressTCP4  s     &&{FNNKPPrY   c                \    V P                  \        4       \        P                  \        4      # )z
IPv6 L{Server} instances have a string representation indicating on
which port they're running, and the connected address is stored on the
C{peerAddresses} attribute of the factory.
)r
  r_   rc   r  r   r   s   &rZ   test_serverAddressTCP69TCPTransportServerAddressTestMixin.test_serverAddressTCP6  s%     &&#%v
 	
rY   rX   N)r   r   r   r   r   r  r
  r  r   r3  r4  r  r   r   r   s   @rZ   r  r    s6     $ !DQ Hn%
 &
rY   r  c                   *   a  ] tR tRt o RtR tRtV tR# )TCPTransportTestsBuilderi  zL
Test standard L{ITCPTransport}s built with C{listenTCP} and C{connectTCP}.
c                  aa
a \        4       p\        4       Vn        \        4       Vn        \	        4       p\        4       Vn        \        4       Vn        SP                  ^ WBR7      o\        VP                  VP                  .4      pV3R lpVP                  V4       \        VP                  VP                  .4      p\        4       o
V
V3R lp	VP                  V	4       SP                  VSP                  4       P                  V4       S
# )zy
Return a L{Deferred} firing with a L{MyClientFactory} and
L{MyServerFactory} connected pair, and the listening C{Port}.
r  c                 (   < SP                  4        V # rW   rf  r   r   s   &rZ   rg  BTCPTransportTestsBuilder.getConnectedClientAndServer.<locals>.stop	  s    LLNMrY   c                    < V w  r\         P                  ! R V,          4       \         P                  ! RV,          4       SP                  WS34       R# zclient connected %szserver connected %sNrG   r  rE  r  rf   r   r{  ri   s   &  rZ   startCTCPTransportTestsBuilder.getConnectedClientAndServer.<locals>.start	  A    &NFGG)F23GG)F23vt45rY   )rM   r   ry  rk  rL   rD  r   r  rl  rJ  r=  ri   )rq   r   r  r  r   rf   lostDeferredrg  startDeferredr  r{  ri   s   &f&&      @@rZ   r  4TCPTransportTestsBuilder.getConnectedClientAndServer  s    
 !"(0
%(0
% "(0
%(0
%  F @$**F,I,IJ
	 	T"%**F,I,IJ
 :	6 	!!%(9dlln&9&96BrY   rX   N)r   r   r   r   r   r  r   r   r   s   @rZ   r  r    s     ) )rY   r  c                   2   a  ] tR tRt o Rt]]3tR tRt	V t
R# )!AdoptStreamConnectionTestsBuilderi(	  z>
Test server transports built using C{adoptStreamConnection}.
c                  aaaaa \        4       p\        4       Vn        \        4       o\        4       Sn        \        4       Sn        \	        4       p\        4       Vn        \        4       Vn        SP                  ^ WBR7      oVVV3R lpVP                  P                  V4       \        VP                  SP                  .4      pV3R lpVP                  V4       \        4       oSP                  V4       \        VP                  SP                  .4      p	VV3R lp
V	P                  V
4       SP                  VSP                  4       P                  V4       S# )a  
Return a L{Deferred} firing with a L{MyClientFactory} and
L{MyServerFactory} connected pair, and the listening C{Port}. The
particularity is that the server protocol has been obtained after doing
a C{adoptStreamConnection} against the original server connection.
r  c                    < SP                  V P                  4       SP                  V P                  4       SP                  V P                  P	                  4       SS4       R # rW   )r   r  r   adoptStreamConnectionr   )r  r  r   r   s   &rZ   firtServerConnectedZAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.firtServerConnectedE	  sI      1  1))&&(-rY   c                 L   < SP                   '       d   SP                  4        V # rW   )r  rg  r  s   &rZ   rg  KAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.stopR	  s    MrY   c                    < V w  r\         P                  ! R V,          4       \         P                  ! RV,          4       SP                  WS34       R# r  r  r  s   &  rZ   r  LAdoptStreamConnectionTestsBuilder.getConnectedClientAndServer.<locals>.start`	  r  rY   )rM   r   ry  rk  rL   rD  rl  r   r  rn  rJ  r=  ri   )rq   r   r  r  firstServerrf   r'  r  rg  r   r  r{  ri   r   s   &f&f       @@@rZ   r  =AdoptStreamConnectionTestsBuilder.getConnectedClientAndServer1	  s    &'-5Z* "(0
%(0
% "(0
%(0
%  K E	 	**667JK$**F,I,IJ
	
 	T":D!%**F,I,IJ
	6 	!!%(9dlln&9&96BrY   rX   N)r   r   r   r   r   r(   r)   r  r  r   r   r   s   @rZ   r#  r#  (	  s!      (88 8rY   r#  c                   *   a  ] tR tRt o RtR tRtV tR# )ServerAbortsTwiceiw	  z
Call abortConnection() twice.
c                n    V P                   P                  4        V P                   P                  4        R # rW   )r  abortConnectionrp   s   &&rZ   r   ServerAbortsTwice.dataReceived|	  s"    &&(&&(rY   rX   Nr   r   s   @rZ   r0  r0  w	       ) )rY   r0  c                   *   a  ] tR tRt o RtR tRtV tR# )ServerAbortsThenLosesi	  z6
Call abortConnection() followed by loseConnection().
c                n    V P                   P                  4        V P                   P                  4        R # rW   )r  r2  rO  rp   s   &&rZ   r   "ServerAbortsThenLoses.dataReceived	  s"    &&(%%'rY   rX   Nr   r   s   @rZ   r6  r6  	       ( (rY   r6  c                   *   a  ] tR tRt o RtR tRtV tR# )AbortServerWritingProtocoli	  z,
Protocol that writes data upon connection.
c                <    V P                   P                  R4       R# )zG
Tell the client that the connection is set up and it's time to abort.
s   readyNr  r   r   s   &rZ   r?  )AbortServerWritingProtocol.connectionMade	  s     	X&rY   rX   Nr   r   r   r   r   r?  r   r   r   s   @rZ   r;  r;  	  s     ' 'rY   r;  c                   *   a  ] tR tRt o RtR tRtV tR# )ReadAbortServerProtocoli	  z
Server that should never receive any data, except 'X's which are written
by the other side of the connection before abortConnection, and so might
possibly arrive.
c                L    VP                  R R4      '       d   \        R4      hR# )   XrY   zUnexpectedly received data.N)replacer   rp   s   &&rZ   r   $ReadAbortServerProtocol.dataReceived	  s$    <<c""9:: #rY   rX   Nr   r   s   @rZ   rA  rA  	  s     ; ;rY   rA  c                   *   a  ] tR tRt o RtR tRtV tR# )NoReadServeri	  z
Stop reading immediately on connection.

This simulates a lost connection that will cause the other side to time
out, and therefore call abortConnection().
c                :    V P                   P                  4        R # rW   )r  stopReadingr   s   &rZ   r?  NoReadServer.connectionMade	  s    ""$rY   rX   Nr?  r   s   @rZ   rG  rG  	  s     % %rY   rG  c                   D   a  ] tR tRt o RtRtRtR tR tR t	R t
RtV tR	# )
EventualNoReadServeri	  z
Like NoReadServer, except we Wait until some bytes have been delivered
before stopping reading. This means TLS handshake has finished, where
applicable.
Fc                    V P                   '       gA   R V n         V P                  P                  V R4       V P                  P                  R4       R# R# )TF   helloN)gotDatar  r  r   rp   s   &&rZ   r   !EventualNoReadServer.dataReceived	  s=    |||DLNN++D%8NN  * rY   c                p    V P                   '       d   R # RV n         V P                  P                  4        R # )NT)stoppedReadingr  rI  r   s   &rZ   rC  $EventualNoReadServer.resumeProducing	  s)    """$rY   c                    R # rW   rX   r   s   &rZ   rB  #EventualNoReadServer.pauseProducing	      rY   c                    R # rW   rX   r   s   &rZ   r  "EventualNoReadServer.stopProducing	  rV  rY   )rO  rR  N)r   r   r   r   r   rO  rR  r   rC  rB  r  r   r   r   s   @rZ   rL  rL  	  s/      GN+% rY   rL  c                   .   a  ] tR tRt o RtRtR tRtV tR# )BaseAbortingClienti	  z'
Base class for abort-testing clients.
Fc                l    V P                   '       d   \        R 4      h\        P                  ! W4       R# )z,BUG: connectionLost was called re-entrantly!N)inReactorMethodRuntimeErrorr9   r   r  s   &&rZ   r   !BaseAbortingClient.connectionLost	  s(    MNN**48rY   rX   N)	r   r   r   r   r   r\  r   r   r   r   s   @rZ   rZ  rZ  	  s      O9 9rY   rZ  c                   *   a  ] tR tRt o RtR tRtV tR# )WritingButNotAbortingClienti	  z
Write data, but don't abort.
c                <    V P                   P                  R 4       R# )rN  Nr=  r   s   &rZ   r?  *WritingButNotAbortingClient.connectionMade	  s    X&rY   rX   Nr?  r   s   @rZ   r`  r`  	  s     ' 'rY   r`  c                   0   a  ] tR tRt o RtR tR tRtV tR# )AbortingClienti	  z1
Call abortConnection() after writing some data.
c                B    RV n         V P                  4        RV n         R# )z6
Some data was received, so the connection is set up.
TFN)r\  writeAndAbortrp   s   &&rZ   r   AbortingClient.dataReceived	  s       $$rY   c                    V P                   P                  R R,          4       V P                   P                  4        V P                   P                  RR,          4       R# )rC  i'     YN)r  r   r2  r   s   &rZ   rf  AbortingClient.writeAndAbort	  s@     	TE\*&&(TE\*rY   )r\  N)	r   r   r   r   r   r   rf  r   r   r   s   @rZ   rd  rd  	  s     %+ +rY   rd  c                   *   a  ] tR tRt o RtR tRtV tR# )AbortingTwiceClienti	  z8
Call abortConnection() twice, after writing some data.
c                d    \         P                  V 4       V P                  P                  4        R # rW   )rd  rf  r  r2  r   s   &rZ   rf  !AbortingTwiceClient.writeAndAbort	  s     $$T*&&(rY   rX   Nr   r   r   r   r   rf  r   r   r   s   @rZ   rl  rl  	  r4  rY   rl  c                   *   a  ] tR tRt o RtR tRtV tR# )AbortingThenLosingClienti
  z3
Call abortConnection() and then loseConnection().
c                d    \         P                  V 4       V P                  P                  4        R # rW   )rd  rf  r  rO  r   s   &rZ   rf  &AbortingThenLosingClient.writeAndAbort
  s     $$T*%%'rY   rX   Nro  r   s   @rZ   rq  rq  
  r9  rY   rq  c                   J   a  ] tR tRt o RtRtRtR tR tR t	R t
R	 tR
tV tR# )ProducerAbortingClienti
  z9
Call abortConnection from doWrite, via resumeProducing.
TFc                    V P                   P                  R R,          4       RV n        V P                   P                  V R4       RV n        R# )s   lalalai TFN)r  r   inRegisterProducerr  r   s   &rZ   r   ProducerAbortingClient.write
  s=    Y/0"&''e4"'rY   c                &    V P                  4        R # rW   r   r   s   &rZ   r?  %ProducerAbortingClient.connectionMade
      

rY   c                z    R V n         V P                  '       g   V P                  P                  4        RV n         R# )TFN)r\  rw  r  r2  r   s   &rZ   rC  &ProducerAbortingClient.resumeProducing
  s.    #&&&NN**,$rY   c                    R V n         R# rn  )producerStoppedr   s   &rZ   r  $ProducerAbortingClient.stopProducing$
  s
    #rY   c                    V P                   '       g   \        R 4      hV P                  '       d   \        R4      h\        P                  ! W4       R# )z&BUG: stopProducing() was never called.z(BUG: connectionLost called re-entrantly!N)r  r]  r\  r9   r   r  s   &&rZ   r   %ProducerAbortingClient.connectionLost'
  s@    ###GHHIJJ**48rY   )r\  rw  r  N)r   r   r   r   r   r\  r  r   r?  rC  r  r   r   r   r   s   @rZ   ru  ru  
  s4      OO(%$9 9rY   ru  c                   Z   a  ] tR tRt o RtRt^ tRtR tR t	R t
R tR tR	 tR
 tRtV tR# )StreamingProducerClienti/
  a  
Call abortConnection() when the other side has stopped reading.

In particular, we want to call abortConnection() only once our local
socket hits a state where it is no longer writeable. This helps emulate
the most common use case for abortConnection(), closing a connection after
a timeout, with write buffers being full.

Since it's very difficult to know when this actually happens, we just
write a lot of data, and assume at that point no more writes will happen.
Fc                &    V P                  4        R # rW   rz  r   s   &rZ   r?  &StreamingProducerClient.connectionMade@
  r|  rY   c                    V P                   P                  V R4       \        ^d4       F%  pV P                   P                  RR,          4       K'  	  R# )zP
Write large amount to transport, then wait for a while for buffers to
fill up.
Ts
   1234567890i }  N)r  r  ranger   )rq   is   & rZ   r   StreamingProducerClient.writeC
  s=    
 	''d3sANN  !67 rY   c                    R V n         R# )FN)r  r   s   &rZ   rC  'StreamingProducerClient.resumeProducingL
  s	    rY   c                    R # rW   rX   r   s   &rZ   r  %StreamingProducerClient.stopProducingO
  rV  rY   c                    V P                   '       d   R# RV n         V P                  P                  RV P                  4       R# )a  
Called when local buffer fills up.

The goal is to hit the point where the local file descriptor is not
writeable (or the moral equivalent). The fact that pauseProducing has
been called is not sufficient, since that can happen when Twisted's
buffers fill up but OS hasn't gotten any writes yet. We want to be as
close as possible to every buffer (including OS buffers) being full.

So, we wait a bit more after this for Twisted to write out a few
chunks, then abortConnection.
NTg{Gz?)r  r   rz  doAbortr   s   &rZ   rB  &StreamingProducerClient.pauseProducingR
  s1     ;;; 	tT\\2rY   c                    V P                   '       g    \        P                  ! \        R 4      4       RV n        V P
                  P                  4        RV n        R# )z&BUG: We should be paused a this point.TFN)r  rG   ro  r]  r\  r  r2  r   s   &rZ   r  StreamingProducerClient.doAbortg
  s=    {{{GGL!IJK#&&($rY   c                z    V P                   P                  P                  4        \        P                  ! W4       R # rW   )otherProtocolr  startReadingr9   r   r  s   &&rZ   r   &StreamingProducerClient.connectionLostn
  s(    $$113**48rY   )r\  r  N)r   r   r   r   r   r  extraWritesr\  r?  r   rC  r  rB  r  r   r   r   r   s   @rZ   r  r  /
  sC     
 FKO83*%9 9rY   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )StreamingProducerClientLaterit
  zL
Call abortConnection() from dataReceived, after bytes have been
exchanged.
c                J    V P                   P                  R 4       RV n        R# )rN  FN)r  r   rO  r   s   &rZ   r?  +StreamingProducerClientLater.connectionMadez
  s    X&rY   c                \    V P                   '       g   R V n         V P                  4        R# R# rn  )rO  r   rp   s   &&rZ   r   )StreamingProducerClientLater.dataReceived~
  s     |||DLJJL rY   )rO  N	r   r   r   r   r   r?  r   r   r   r   s   @rZ   r  r  t
  s     
 rY   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )ProducerAbortingClientLateri
  z
Call abortConnection from doWrite, via resumeProducing.

Try to do so after some bytes have already been exchanged, so we
don't interrupt SSL handshake.
c                    R # rW   rX   r   s   &rZ   r?  *ProducerAbortingClientLater.connectionMade
  s    rY   c                &    V P                  4        R # rW   rz  rp   s   &&rZ   r   (ProducerAbortingClientLater.dataReceived
  r|  rY   rX   Nr  r   s   @rZ   r  r  
  s      rY   r  c                   *   a  ] tR tRt o RtR tRtV tR# )DataReceivedRaisingClienti
  zF
Call abortConnection(), and then throw exception, from dataReceived.
c                L    V P                   P                  4        \        R 4      h)ONO)r  r2  ZeroDivisionErrorrp   s   &&rZ   r   &DataReceivedRaisingClient.dataReceived
  s    &&(&&rY   rX   Nr   r   s   @rZ   r  r  
  s     ' 'rY   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )ResumeThrowsClienti
  zD
Call abortConnection() and throw exception from resumeProducing().
c                t    V P                   '       g&   V P                  P                  4        \        R 4      hR# )zono!N)rw  r  r2  r  r   s   &rZ   rC  "ResumeThrowsClient.resumeProducing
  s.    &&&NN**,#F++ 'rY   c                2    \         P                  ! W4       R # rW   )r9   r   r  s   &&rZ   r   !ResumeThrowsClient.connectionLost
  s     	**48rY   rX   N)	r   r   r   r   r   rC  r   r   r   r   s   @rZ   r  r  
  s     ,
9 9rY   r  c                     a  ] tR tRt o RtRtRR ltR tR tR t	R t
R	 t]! ]P                  P                  R
R4      P!                  4       R8H  ;'       d    ]P$                  ! 4       R4      R 4       t]! ]P                  P                  R
R4      P!                  4       R8H  ;'       d    ]P$                  ! 4       R4      R 4       tR tR tR tR tV 3R ltRtV tR# )AbortConnectionMixini
  z/
Unit tests for L{ITransport.abortConnection}.
Nc                   \         \        3p\        \        3p\        '       d1   V\        P
                  3,           pV\        P
                  3,           pV! 4       pV! 4       pWvn        Wgn        \        WW`P                  4      pV P                  VP                  4       . 4       V P                  VP                  4       . 4       Ve0   V P                  VP                  P                  V3V,           4       M&V P                  VP                  P                  V4       V P                  VP                  P                  V4       R# )z
A test runner utility function, which hooks up a matched pair of client
and server protocols.

We then run the reactor until both sides have disconnected, and then
verify that the right exception resulted.
N)r   r   r   r  rQ   Errorr  r@   rA  r   r   getDelayedCallsr  disconnectReasonr  )	rq   clientClassserverClassclientConnectionLostReasonclientExpectedExceptionsserverExpectedExceptionsrf   r   r   s	   &&&&     rZ   runAbortTest!AbortConnectionMixin.runAbortTest
  s    %6~#F $2N#C  6'?399,'N$'?399,'N$%%)$O 	**,b1002B7%1!!''--+-0HH
 !!''--/G 	f55;;=UVrY   c                6    V P                  \        \        4      # )z
abortConnection() is called in dataReceived. The protocol should be
disconnected, but connectionLost should not be called re-entrantly.
)r  rd  rA  r   s   &rZ   test_dataReceivedAbort+AbortConnectionMixin.test_dataReceivedAbort
  s    
   1HIIrY   c                6    V P                  \        \        4      # )zq
abortConnection() is called twice by client.

No exception should be thrown, and the connection will be closed.
)r  rl  rA  r   s   &rZ    test_clientAbortsConnectionTwice5AbortConnectionMixin.test_clientAbortsConnectionTwice
  s       !46MNNrY   c                6    V P                  \        \        4      # )z
Client calls abortConnection(), followed by loseConnection().

No exception should be thrown, and the connection will be closed.
)r  rq  rA  r   s   &rZ   .test_clientAbortsConnectionThenLosesConnectionCAbortConnectionMixin.test_clientAbortsConnectionThenLosesConnection
  s       !9;RSSrY   c                B    V P                  \        \        \        R7      # )zq
abortConnection() is called twice by server.

No exception should be thrown, and the connection will be closed.
r  )r  r`  r0  r   r   s   &rZ    test_serverAbortsConnectionTwice5AbortConnectionMixin.test_serverAbortsConnectionTwice
  s%       ''5 ! 
 	
rY   c                B    V P                  \        \        \        R7      # )z
Server calls abortConnection(), followed by loseConnection().

No exception should be thrown, and the connection will be closed.
r  )r  r`  r6  r   r   s   &rZ   .test_serverAbortsConnectionThenLosesConnectionCAbortConnectionMixin.test_serverAbortsConnectionThenLosesConnection
  s%       '!'5 ! 
 	
rY   CIrS   truezFlaky on macOS on Azure.c                :    V P                  \        \        4       R# )z
abortConnection() is called in resumeProducing, before any bytes have
been exchanged. The protocol should be disconnected, but
connectionLost should not be called re-entrantly.
N)r  ru  r9   r   s   &rZ   test_resumeProducingAbort.AbortConnectionMixin.test_resumeProducingAbort  s     	02EFrY   c                6    V P                  \        \        4      # )z|
abortConnection() is called in resumeProducing, after some
bytes have been exchanged. The protocol should be disconnected.
)r  r  r;  r   s   &rZ   test_resumeProducingAbortLater3AbortConnectionMixin.test_resumeProducingAbortLater  s       ')C
 	
rY   c                :    V P                  \        \        4       R# )aC  
abortConnection() triggered by the write buffer being full.

In particular, the server side stops reading. This is supposed
to simulate a realistic timeout scenario where the client
notices the server is no longer accepting data.

The protocol should be disconnected, but connectionLost should not be
called re-entrantly.
N)r  r  rG  r   s   &rZ   test_fullWriteBuffer)AbortConnectionMixin.test_fullWriteBuffer(  s     	1<@rY   c                6    V P                  \        \        4      # )z
abortConnection() is triggered by a write buffer being full.

However, this buffer is filled after some bytes have been exchanged,
allowing a TLS handshake if we're testing TLS. The connection will
then be lost.
)r  r  rL  r   s   &rZ   %test_fullWriteBufferAfterByteExchange:AbortConnectionMixin.test_fullWriteBufferAfterByteExchange5  s       !=?STTrY   c                    V P                  \        \        \        R7       V P	                  \        4      pV P                  \        V4      ^4       R# )a  
dataReceived calls abortConnection(), and then raises an exception.

The connection will be lost, with the thrown exception
(C{ZeroDivisionError}) as the reason on the client. The idea here is
that bugs should not be masked by abortConnection, in particular
unexpected exceptions.
r  N)r  r  r;  r  flushLoggedErrorsr   r   rq   errorss   & rZ   test_dataReceivedThrows,AbortConnectionMixin.test_dataReceivedThrows?  sG     	%&'8 	 	

 ''(9:Va(rY   c                    V P                  \        \        \        R7       V P	                  \        4      pV P                  \        V4      ^4       R# )a  
resumeProducing calls abortConnection(), and then raises an exception.

The connection will be lost, with the thrown exception
(C{ZeroDivisionError}) as the reason on the client. The idea here is
that bugs should not be masked by abortConnection, in particular
unexpected exceptions.
r  N)r  r  r9   r  r  r   r   r  s   & rZ   test_resumeProducingThrows/AbortConnectionMixin.test_resumeProducingThrowsP  sG     	'8 	 	

 ''(9:Va(rY   c                6   < V ^8  d   Qh/ S[ S[,          ;R&   # )r'  rA  )r   r;   )r*  r   s   "rZ   r+  !AbortConnectionMixin.__annotate__
  s      (/ rY   rX   rW   )r   r   r   r   r   rA  r  r  r  r  r  r  r   r  environgetlowerrI   isMacOSXr  r  r  r  r  r  r0  r   r   r   s   @rZ   r  r  
  s     
 ,0I#WJJOT



 


tR &&(F2JJx7H7H7J"G	G 


tR &&(F2JJx7H7H7J"
	
AU)")C  rY   r  c                   .    ] tR tRtRt]3t]! 4       tRt	R# )AbortConnectionTestsib  z-
TCP-specific L{AbortConnectionMixin} tests.
rX   N)
r   r   r   r   r   r*   r  r  rA  r   rX   rY   rZ   r  r  b  s     &IrY   r  c                   l   a  ] tR tRt o RtR t]! ]P                  ! 4       R4      R 4       t	R t
RtV tR# )	SimpleUtilityTestsio  zB
Simple, direct tests for helpers within L{twisted.internet.tcp}.
c                    V P                  \        P                  \        R^4      pV P	                  VP
                  ^ ,          \        P                  4       R# )z
L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when
invoked with a non-numeric host.  (In other words, it is passing
L{socket.AI_NUMERICHOST} to L{socket.getaddrinfo} and will not
accidentally block if it receives bad input.)
	localhostNr  rc   gaierrorr7   r   r   
EAI_NONAMErq   ro  s   & rZ   test_resolveNumericHost*SimpleUtilityTests.test_resolveNumericHostu  s<     {AN!f&7&78rY   z@The AI_NUMERICSERV flag is not supported by Microsoft providers.c                    V P                  \        P                  \        RR4      pV P	                  VP
                  ^ ,          \        P                  4       R# )z
L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when
invoked with a non-numeric port.  (In other words, it is passing
L{socket.AI_NUMERICSERV} to L{socket.getaddrinfo} and will not
accidentally block if it receives bad input.)
r  httpNr  r  s   & rZ   test_resolveNumericService-SimpleUtilityTests.test_resolveNumericService  s<     ufM!f&7&78rY   c                    \        R^4      pV P                  \        V4      ^4       V P                  V^,          \        4       V P                  V^,          \        4       V P                  VR,          R4       R# )zJ
L{_resolveIPv6} discovers the flow info and scope ID of an IPv6
address.
r  rx  N)r  r'  )r7   r   r   r  r4  r   s   & rZ   test_resolveIPv6#SimpleUtilityTests.test_resolveIPv6  sd    
 eQ'Va(
 	fQi-fQi- 	Z0rY   rX   N)r   r   r   r   r   r  r   rI   rt  r  r  r   r   r   s   @rZ   r  r  o  sA     9 J
9
91 1rY   r  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	BuffersLogsTestsi  z
Tests for L{_BuffersLogs}.
c                    R V n         . V n        \        V P                   V P                  P                  4      V n        R# )z
name.spaceN)	namespacer  r3   r~   	logBufferr   s   &rZ   r   BuffersLogsTests.setUp  s,    %%dnndkk6H6HIrY   c                    V P                   ;_uu_ 4       pVP                  R4       V P                  V P                  4       RRR4       R#   + '       g   i     R# ; i)zR
The context manager's logger does not log to provided observer
inside the block.
An eventN)r  r  r	  r  )rq   loggers   & rZ   test_buffersInBlock$BuffersLogsTests.test_buffersInBlock  s9    
 ^^^vKK
#T[[) ^^^s   -AA	c                   V P                   ;_uu_ 4       pVP                  R4       V P                  V P                  4       RRR4       V P	                  ^\        V P                  4      4       V P                  w  pV P	                  VR,          R4       V P	                  VR,          V P                  4       R#   + '       g   i     L; i)z_
The context manager flushes its buffered logs when the block
terminates without an exception.
r  N
log_formatlog_namespace)r  r  r	  r  r   r   r  )rq   r  events   &  rZ   test_flushesOnExit#BuffersLogsTests.test_flushesOnExit  s    
 ^^^vKK
#T[[)  	C,-++|,j9/@ ^s   -B;;C	c           	     &    ! R R\         4      pV P                  V4      ;_uu_ 4        V P                  ;_uu_ 4       pVP                  R4       V P	                  V P
                  4       V! 4       h  + '       g   i     M; i RRR4       M  + '       g   i     M; iT P                  ^\        T P
                  4      4       T P
                  w  pT P                  TR,          R4       T P                  TR,          T P                  4       R# )zb
The context manager flushes its buffered logs when the block
terminates because of an exception.
c                       ] tR tRtRtRtR# )GBuffersLogsTests.test_flushesOnExitWithException.<locals>.TestExceptioni  z(
An exception only raised by this test.
rX   Nr   r   r   r   r   r   rX   rY   rZ   TestExceptionr        rY   r  r  Nr  r  )	r   r  r  r  r	  r  r   r   r  )rq   r  r  r  s   &   rZ   test_flushesOnExitWithException0BuffersLogsTests.test_flushesOnExitWithException  s    	I 	
 }--6J'  -#o%   .--- 	C,-++|,j9/@s   B4A2	2B=BB	)r  r  r  N)r   r   r   r   r   r   r	  r  r  r   r   r   s   @rZ   r  r    s'     J
*AA ArY   r  c                   `   a  ] tR tRt o Rt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# )FileDescriptorReservationTestsi  z*
Tests for L{_FileDescriptorReservation}.
c                l   a  . S n         S P                  4       S n        V 3R  lp\        V4      S n        R# )c                     < S P                   P                  \        S P                  R 4      4       S P                   R,          # )wr  )reservedFileObjectsr~   r8  tempfiler   s   rZ   fakeFileFactory=FileDescriptorReservationTests.setUp.<locals>.fakeFileFactory  s3    $$++D,DE++B//rY   N)r  mktempr  r4   
reservedFD)rq   r   s   f rZ   r   $FileDescriptorReservationTests.setUp  s+    #% 	0 5_ErY   c                :    \        \        V P                  4       R# )zQ
L{_FileDescriptorReservation} instances provide
L{_IFileDescriptorReservation}.
N)r   r5   r#  r   s   &rZ   r=  5FileDescriptorReservationTests.test_providesInterface  s    
 	0$//BrY   c                J   V P                  \        V P                  4      ^ 4       \        ^
4       Fn  pV P                  P                  4        V P                  \        V P                  4      ^4       V P                  V P                  ^ ,          P                  4       Kp  	  R# )zP
Multiple acquisitions without releases open the reservation
file exactly once.
N)r   r   r  r  r#  reserver	  r  )rq   r  s   & rZ   test_reserveOpensFileOnce8FileDescriptorReservationTests.test_reserveOpensFileOnce  sw    
 	T556:rAOO##%S!9!9:A>T55a8??@ rY   c                (   \        4       pV P                  VP                  4       VP                  4        V P	                  V P
                  P                  4       4       V P
                  P                  4        V P	                  V P
                  P                  4       4       V P                  \        \        4      pV P                  \        V4      ^4       V P                  V^ ,          P                  P                  \        P                  4       R# )z
If reserving the file descriptor fails because of C{EMFILE},
the exception is suppressed but logged and the reservation
remains unavailable.
N)r  r  r  r  r	  r#  	availabler(  r  r  rD  r   r   r  r  r  )rq   r5  r  s   &  rZ   test_reserveEMFILELogged7FileDescriptorReservationTests.test_reserveEMFILELogged  s     -.		))*2245!2245''9Va(..=rY   c                    \         \        \        3 F/  pV3R lp\        V4      pV P	                  WP
                  4       K1  	  R# )z
Any exception raised while opening the reserve file that is
not an L{OSError} or L{IOError} whose errno is C{EMFILE} is
allowed through to the caller.
c                 >    V ! \         P                  ^,           R4      h)r  r   )r  r  )
errorClasss   &rZ   	failsWithWFileDescriptorReservationTests.test_reserveRaisesNonEMFILEExceptions.<locals>.failsWith  s     !19==rY   N)r  rD  r  r4   r  r(  )rq   r1  r2  	reserveFDs   &   rZ   %test_reserveRaisesNonEMFILEExceptionsDFileDescriptorReservationTests.test_reserveRaisesNonEMFILEExceptions  s?     #GZ8J &0 > 39=Ij*;*;< 9rY   c                    V P                  V P                  P                  4       4       V P                  P                  4        V P	                  V P                  P                  4       4       R# )zE
The reservation is available after the file descriptor is
reserved.
N)r	  r#  r,  r(  r  r   s   &rZ   test_available-FileDescriptorReservationTests.test_available  sH    
 	2245!1134rY   c           	         V P                  \        4      ;_uu_ 4        V P                  ;_uu_ 4         RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)zX
A reservation without an open file used as a context manager
raises a L{RuntimeError}.
N)r  r]  r#  r   s   &rZ   test_enterFailsWithoutFile9FileDescriptorReservationTests.test_enterFailsWithoutFile$  s@    
 |,,< ! -,  -,,s!   AA	AAAA+	c                   V P                   P                  4        V P                  V P                   P                  4       4       V P                   ;_uu_ 4        V P	                  V P                   P                  4       4       RRR4       V P                  V P                   P                  4       4       R#   + '       g   i     L;; i)zY
Entering a reservation closes its file for the duration of the
context manager's block.
N)r#  r(  r  r,  r	  r   s   &rZ   !test_enterClosesFileExitOpensFile@FileDescriptorReservationTests.test_enterClosesFileExitOpensFile-  sw    
 	!1134___T__6689 1134 _s   *B55C	c           	     $    ! R R\         4      pV P                  P                  4        V P                  V4      ;_uu_ 4        V P                  ;_uu_ 4        V! 4       h  + '       g   i     M; i RRR4       R#   + '       g   i     R# ; i)zq
An exception raised within a reservation context manager's
block does not prevent the file from being reopened.
c                       ] tR tRtRtRtR# )SFileDescriptorReservationTests.test_exitOpensFileOnException.<locals>.TestExceptioni>  z&
An exception only used by this test.
rX   Nr  rX   rY   rZ   r  rB  >  r  rY   r  N)r   r#  r(  r  )rq   r  s   & rZ   test_exitOpensFileOnException<FileDescriptorReservationTests.test_exitOpensFileOnException8  s[    	I 	
 	!}--#o% ! .---s   A>A 	 A0+A>>B	c           	       aa  ! R R\         4      p ! R R\         4      oR.oVV3R lp\        V4      pVP                  4        V P                  VP	                  4       4       V P                  V4      ;_uu_ 4        T;_uu_ 4        V! 4       h  + '       g   i     M; i RRR4       M  + '       g   i     M; iT P                  S4      pT P                  \        T4      ^4       R# )z
An exception raised while re-opening the reserve file exiting
a reservation's context manager block is suppressed but
logged, allowing an exception raised within the block through.
c                       ] tR tRtRtRtR# )`FileDescriptorReservationTests.test_exitSuppressesReservationException.<locals>.AllowedExceptioniO  z)
The exception allowed out of the block.
rX   Nr  rX   rY   rZ   AllowedExceptionrG  O  r  rY   rH  c                       ] tR tRtRtRtR# )cFileDescriptorReservationTests.test_exitSuppressesReservationException.<locals>.SuppressedExceptioniT  z5
An exception raised by the file descriptor factory.
rX   Nr  rX   rY   rZ   SuppressedExceptionrJ  T  r  rY   rK  Fc                  d   < S^ ,          '       d   S ! 4       hRS^ &   \         P                  ! 4       # )r   T)ioBytesIO)rK  calleds   rZ   +failsWithSuppressedExceptionAfterSecondOpen{FileDescriptorReservationTests.test_exitSuppressesReservationException.<locals>.failsWithSuppressedExceptionAfterSecondOpen[  s*    ayy)++ q	zz|#rY   N)	r   r4   r(  r  r,  r  r  r   r   )rq   rH  rP  r#  r  rK  rO  s   &    @@rZ   'test_exitSuppressesReservationExceptionFFileDescriptorReservationTests.test_exitSuppressesReservationExceptionH  s    	y 	
	) 	
 	$ 07

 	
,,.//00&((  1000 ''(;<Va(s   >B.	B	B!B..B>	)r#  r  r  N)r   r   r   r   r   r   r=  r)  r-  r5  r8  r;  r>  rC  rR  r   r   r   s   @rZ   r  r    sD     FC
A>$=5=	5& &) &)rY   r  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	"NullFileDescriptorReservationTestsiq  z.
Tests for L{_NullFileDescriptorReservation}.
c                $    \        4       V n        R # rW   )r6   nullReservedFDr   s   &rZ   r   (NullFileDescriptorReservationTests.setUpv  s    <>rY   c                :    \        \        V P                  4       R# )zL
L{_NullFileDescriptorReservation} provides
L{_IFileDescriptorReservation}.
N)r   r5   rW  r   s   &rZ   r=  9NullFileDescriptorReservationTests.test_providesInterfacey  s    
 	0$2E2EFrY   c                X    V P                  V P                  P                  4       4       R# )z7
The null reserved file descriptor is never available.
Nr	  rW  r,  r   s   &rZ   r8  1NullFileDescriptorReservationTests.test_available  s!     	,,6689rY   c                \   V P                  V P                  P                  4       4       V P                  ;_uu_ 4        V P                  V P                  P                  4       4       RRR4       V P                  V P                  P                  4       4       R#   + '       g   i     L;; i)z>
The null reserved file descriptor is a null context manager.
Nr\  r   s   &rZ   test_contextManager6NullFileDescriptorReservationTests.test_contextManager  su     	,,6689   T00::<= !,,6689 ! s   *BB+	)rW  N)r   r   r   r   r   r   r=  r8  r_  r   r   r   s   @rZ   rU  rU  q  s$     ?G:: :rY   rU  )r  r   )r   r  r  rM  r  rc   	functoolsr   typingr   r   r   r   r   r	   r
   unittestr   zope.interfacer   r   zope.interface.verifyr   r   r-  twisted.internet.addressr   r   twisted.internet.deferr   r   r   r   r   r   twisted.internet.endpointsr   r   twisted.internet.errorr   r   r   r   r   r   r    r!   r"   twisted.internet.interfacesr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   twisted.internet.protocolr.   r/   r0   twisted.internet.tcpr1   r2   r3   r4   r5   r6   r7   &twisted.internet.test.connectionmixinsr8   r9   r:   r;   r<   r=   r>   r?   r@   #twisted.internet.test.reactormixinsrA   rB   rC   twisted.internet.testingrD   rE   twisted.loggerrF   twisted.pythonrG   twisted.python.failurerH   twisted.python.runtimerI   twisted.test.test_tcprJ   rK   rL   rM   twisted.trial.unittestrN   rO   rP   OpenSSLrQ   twisted.internet.sslrR   r  ImportErrorsr  r  r  r3  r4  r  r"  r   rt  twisted.internet.testrT   win32GetLinkLocalIPv6Addressesr]   r  rU   posixGetLinkLocalIPv6Addressesr_   re   rl   r   r   r   r   r   r  r  r%  r:  r  r  r  r  r  r  r  r  r3  r  r  r  r  r  r  r  r6  r:  r<  rY  r^  ra  rc  r  r  r  r#  globalsupdatemakeTestCaseClassesr0  r6  r;  rA  rG  rL  rZ  r`  rd  rl  rq  ru  r  r  r  r  r  r  r  r  r  r  rU  rX   rY   rZ   <module>r     s    	 	 	   N N N  1 ;  =  N
 
 
    M L  
 
 
 
 D !  * +  K J :Ffoov'9'9:AFF:
 HN=GGI 2 , K KKP6 %1$O$O!K:"$9 9x3h 32
8 
 ])# )# )#X M, -11X 11h-" -"`O O,3* 3$ _N N N.MH)=?U MH`
/ 
 .!7/ 7 "7,p:~ p:f 8  .!3 8 3 "3"	 : &'TD* D*  (D*N PQN6#6 N6 RN6bYx PQI/$7 I/ RI/XA
 0 A
HM MB	E. 	E"F. "FJGO GOT						2x 26!H/402aR aRH^A ^AB?
 ?
D0&(?0fA&(?AH 	  ';;= > 	  ';;= > 	  $88: ; 	  &::< = 	  *>>@ A 	  *>>@ A 	  *>>@ A 	  )==? @ 	  2FFH I)+ )(/ (	'!4 	'	;8 	;	%& 	%. <
9, 
9'"4 '+' +,). )(~ (90 9DB91 B9J#:  "8  ' '9/ 9"p) p)f>+?  	  %99; < .!-1 -1 "-1`4A* 4An PQV)%8 V) RV)r:)< :]`  F  0H+A3/N0&  /$.!/s<   X+ 8X; Y +	X87X8;YYY
Y%$Y%