def negotiateProtocol(serverProtocols, clientProtocols, clientOptions=None):
 (caCertificate, serverCertificate) = certificatesForAuthorityAndServer()
 trustRoot = sslverify.OpenSSLCertificateAuthorities([caCertificate.original])
 (sProto, cProto, pump) = loopbackTLSConnectionInMemory(trustRoot=trustRoot, privateKey=serverCertificate.privateKey.original, serverCertificate=serverCertificate.original, clientProtocols=clientProtocols, serverProtocols=serverProtocols, clientOptions=clientOptions)
 pump.flush()
 return (cProto.negotiatedProtocol, cProto.wrappedProtocol.lostReason)

def negotiateProtocol ( serverProtocols , clientProtocols , clientOptions = None ) : ( caCertificate , serverCertificate ) = certificatesForAuthorityAndServer ( ) trustRoot = sslverify . OpenSSLCertificateAuthorities ( [ caCertificate . original ] ) ( sProto , cProto , pump ) = loopbackTLSConnectionInMemory ( trustRoot = trustRoot , privateKey = serverCertificate . privateKey . original , serverCertificate = serverCertificate . original , clientProtocols = clientProtocols , serverProtocols = serverProtocols , clientOptions = clientOptions ) pump . flush ( ) return ( cProto . negotiatedProtocol , cProto . wrappedProtocol . lostReason )
create the tls connection and negotiate a next protocol .