Ϫf$dZddlZddlZddlmZddlmZddlmZddl m Z m Z ddl m Z mZddlmZdd lmZGd d e ZGd d e ZGdde ZGdde Zej1ej3ej1ej3ej1ej3ej1ej3y)aD Tests for implementations of L{IReactorSocket}. Generally only tests for failure cases are found here. Success cases for this interface are tested elsewhere. For example, the success case for I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should behave exactly the same as L{IReactorTCP.listenTCP}. N)verify)UnsupportedAddressFamily)IReactorSocket)DatagramProtocol ServerFactory)ReactorBuilderneedsRunningReactor)err)platformceZdZdZegZdZy)&IReactorSocketVerificationTestsBuilderaO Builder for testing L{IReactorSocket} implementations for required methods and method signatures. L{ReactorBuilder} already runs L{IReactorSocket.providedBy} to ensure that these tests will only be run on reactor classes that claim to implement L{IReactorSocket}. These tests ensure that reactors which claim to provide the L{IReactorSocket} interface actually have all the required methods and that those methods have the expected number of arguments. These tests will be skipped for reactors which do not claim to provide L{IReactorSocket}. cv|j}|jtjt|y)zf The reactor instance returned by C{buildReactor} provides L{IReactorSocket}. N) buildReactor assertTruer verifyObjectr)selfreactors C/usr/lib/python3/dist-packages/twisted/internet/test/test_socket.py test_providerz4IReactorSocketVerificationTestsBuilder.test_provider-s+ ##% ++NGDEN)__name__ __module__ __qualname____doc__rrequiredInterfacesrrrr r s ))Frr c(eZdZdZegZdZdZdZy)!AdoptStreamPortErrorsTestsBuilderas Builder for testing L{IReactorSocket.adoptStreamPort} implementations. Generally only tests for failure cases are found here. Success cases for this interface are tested elsewhere. For example, the success case for I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should behave exactly the same as L{IReactorTCP.listenTCP}. c|j}tj}|j}|j|j tj |j |tjt}tjr.|j|jdtjy|j|jdtjy)z An implementation of L{IReactorSocket.adoptStreamPort} raises L{socket.error} if passed an integer which is not associated with a socket. rN)rsocketfilenoclose assertRaiseserroradoptStreamPortAF_INETrr isWindows assertEqualargserrno WSAENOTSOCKEBADFrrprober!excs rtest_invalidDescriptorz8AdoptStreamPortErrorsTestsBuilder.test_invalidDescriptorBs ##%   LL  # #  NN O         SXXa[%*;*; <   SXXa[%++ 6rc<|j}tj}|jd|jd|j |j d}|j t|j|j|ty)z An implementation of L{IReactorSocket.adoptStreamPort} raises L{UnsupportedAddressFamily} if passed an address family it does not support. z 127.0.0.1rN) rr bindlisten addCleanupr"r#rr%r!rrrport arbitrarys rtest_invalidAddressFamilyz;AdoptStreamPortErrorsTestsBuilder.test_invalidAddressFamilyZsu ##%}} "# A  #   $  # # KKM  O  rcjtjjjj dj dj djjjt}|jfd}j|jtdtfdj!y)a9 When the L{IListeningPort} returned by L{IReactorSocket.adoptStreamPort} is stopped using C{stopListening}, the underlying socket is closed but not shutdown. This allows another process which still has a reference to it to continue accepting connections over it. r2r3Fc8jtjj}t j r.j |jdtjyj |jdtjy)Nr) r#r r$acceptr r'r(r)r*WSAEWOULDBLOCKEAGAINignoredr/ portSocketrs rstoppedzFAdoptStreamPortErrorsTestsBuilder.test_stopOnlyCloses..stoppedsg##FLL*2C2CDC!!#  !e.B.BC  !ell;rz"Failed to accept on original port.c,jfdS)Nc$jSNstoprBrs rzYAdoptStreamPortErrorsTestsBuilder.test_stopOnlyCloses.... 7<<>r addCallbackdrsrrKzGAdoptStreamPortErrorsTestsBuilder.test_stopOnlyCloses..Q]]+IJrN)rr r7r"r5r6 setblockingr%r!familyr stopListeningrN addErrbackr r runrr9rDrPrCrs` @@@rtest_stopOnlyClosesz5AdoptStreamPortErrorsTestsBuilder.test_stopOnlyClosesqs##%]]_   (()()!u%&&    !2!2MO      < g S>? J   rN rrrrrrr0r;rXrrrrr6s!))70 .(rrceZdZdZegZdZy)'AdoptStreamConnectionErrorsTestsBuildera} Builder for testing L{IReactorSocket.adoptStreamConnection} implementations. Generally only tests for failure cases are found here. Success cases for this interface are tested elsewhere. For example, the success case for I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should behave exactly the same as L{IReactorTCP.listenTCP}. c|j}tj}|j|jd}|j t |j |j|ty)z An implementation of L{IReactorSocket.adoptStreamConnection} raises L{UnsupportedAddressFamily} if passed an address family it does not support. r4N) rr r7r"r#radoptStreamConnectionr!r)rr connectionr:s rr;zAAdoptStreamConnectionErrorsTestsBuilder.test_invalidAddressFamilysb ##%]]_   (()   $  ) )      O  rN)rrrrrrr;rrrr[r[s)) rr[c(eZdZdZegZdZdZdZy)#AdoptDatagramPortErrorsTestsBuilderzR Builder for testing L{IReactorSocket.adoptDatagramPort} implementations. c|j}tj}|j}|j|j tj |j |tjt}tjr.|j|jdtjy|j|jdtjy)z An implementation of L{IReactorSocket.adoptDatagramPort} raises L{socket.error} if passed an integer which is not associated with a socket. rN)rr r!r"r#r$adoptDatagramPortr&rr r'r(r)r*r+r,r-s rr0z:AdoptDatagramPortErrorsTestsBuilder.test_invalidDescriptors ##%   LL  % %  NN           SXXa[%*;*; <   SXXa[%++ 6rc4|j}tjtjtj}|j |j d}|j t|j|j|ty)z An implementation of L{IReactorSocket.adoptDatagramPort} raises L{UnsupportedAddressFamily} if passed an address family it does not support. r4N) rr r& SOCK_DGRAMr7r"r#rrbr!rr8s rr;z=AdoptDatagramPortErrorsTestsBuilder.test_invalidAddressFamilysm ##%}}V^^V->->?  #   $  % % KKM     rc*jtjtjtjj j j djdjjjt}|jfd}j|jtdt!fdj#y)a7 When the L{IListeningPort} returned by L{IReactorSocket.adoptDatagramPort} is stopped using C{stopListening}, the underlying socket is closed but not shutdown. This allows another process which still has a reference to it to continue reading and writing to it. r2Fc:jtjjd}t j r.j |jdtjyj |jdtjy)Nr3r) r#r r$recvfromr r'r(r)r*r?r@rAs rrDzHAdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses..stopped si##FLL*2E2EqIC!!#  !e.B.BC  !ell;rz Failed to read on original port.c,jfdS)Nc$jSrGrHrJs rrKz[AdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses....rLrrMrOsrrKzIAdoptDatagramPortErrorsTestsBuilder.test_stopOnlyCloses..rQrN)rr r&rdr7r"r5rRrbr!rSrrTrNrUr r rVrWs` @@@rrXz7AdoptDatagramPortErrorsTestsBuilder.test_stopOnlyClosess##%]]6>>63D3DE   (()()u%((    !2!24D4F      < g S<= J   rNrYrrrr`r`s!))70 *&rr`)rr*r zope.interfacertwisted.internet.errorrtwisted.internet.interfacesrtwisted.internet.protocolrr#twisted.internet.test.reactormixinsrr twisted.python.logr twisted.python.runtimer r rr[r`globalsupdatemakeTestCaseClassesrrrrts !;6ES"+F^F8ccL  n  FZ.Zz 7KKMN 2FFHI 8LLNO 4HHJKr