def handshakeProtocols(self, clientProtocols, serverProtocols):
        """
        Start handshake between TLS client and server.

        @param clientProtocols: The protocols the client will accept speaking
            after the TLS handshake is complete.
        @type clientProtocols: L{list} of L{bytes}

        @param serverProtocols: The protocols the server will accept speaking
            after the TLS handshake is complete.
        @type serverProtocols: L{list} of L{bytes}

        @return: A L{tuple} of four different items: the client L{Protocol},
            the server L{Protocol}, a L{Deferred} that fires when the client
            first receives bytes (and so the TLS connection is complete), and a
            L{Deferred} that fires when the server first receives bytes.
        @rtype: A L{tuple} of (L{Protocol}, L{Protocol}, L{Deferred},
            L{Deferred})
        """
        data = b'some bytes'

        class NotifyingSender(Protocol):
            def __init__(self, notifier):
                self.notifier = notifier

            def connectionMade(self):
                self.transport.writeSequence(list(iterbytes(data)))

            def dataReceived(self, data):
                if self.notifier is not None:
                    self.notifier.callback(self)
                    self.notifier = None


        clientDataReceived = Deferred()
        clientFactory = ClientNegotiationFactory(clientProtocols)
        clientFactory.protocol = lambda: NotifyingSender(
            clientDataReceived
        )

        clientContextFactory, _ = (
            HandshakeCallbackContextFactory.factoryAndDeferred())
        wrapperFactory = TLSMemoryBIOFactory(
            clientContextFactory, True, clientFactory)
        sslClientProtocol = wrapperFactory.buildProtocol(None)

        serverDataReceived = Deferred()
        serverFactory = ServerNegotiationFactory(serverProtocols)
        serverFactory.protocol = lambda: NotifyingSender(
            serverDataReceived
        )

        serverContextFactory = ServerTLSContext()
        wrapperFactory = TLSMemoryBIOFactory(
            serverContextFactory, False, serverFactory)
        sslServerProtocol = wrapperFactory.buildProtocol(None)

        loopbackAsync(
            sslServerProtocol, sslClientProtocol
        )
        return (sslClientProtocol, sslServerProtocol, clientDataReceived,
                serverDataReceived)

        Start handshake between TLS client and server.

        @param clientProtocols: The protocols the client will accept speaking
            after the TLS handshake is complete.
        @type clientProtocols: L{list} of L{bytes}

        @param serverProtocols: The protocols the server will accept speaking
            after the TLS handshake is complete.
        @type serverProtocols: L{list} of L{bytes}

        @return: A L{tuple} of four different items: the client L{Protocol},
            the server L{Protocol}, a L{Deferred} that fires when the client
            first receives bytes (and so the TLS connection is complete), and a
            L{Deferred} that fires when the server first receives bytes.
        @rtype: A L{tuple} of (L{Protocol}, L{Protocol}, L{Deferred},
            L{Deferred})
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/test/test_tls.py