def buildTLSProtocol(server=False, transport=None, fakeConnection=None):
 clientProtocol = AccumulatingProtocol(999999999999)
 clientFactory = ClientFactory()
 clientFactory.protocol = (lambda : clientProtocol)
 if fakeConnection:
  @implementer(IOpenSSLServerConnectionCreator, IOpenSSLClientConnectionCreator)
  class HardCodedConnection(object, ):
   def clientConnectionForTLS(self, tlsProtocol):
    return fakeConnection
   serverConnectionForTLS = clientConnectionForTLS
  contextFactory = HardCodedConnection()
 elif server:
  contextFactory = ServerTLSContext()
 else:
  contextFactory = ClientTLSContext()
 wrapperFactory = TLSMemoryBIOFactory(contextFactory, (not server), clientFactory)
 sslProtocol = wrapperFactory.buildProtocol(None)
 if (transport is None):
  transport = StringTransport()
 sslProtocol.makeConnection(transport)
 return (clientProtocol, sslProtocol)

def buildTLSProtocol ( server = False , transport = None , fakeConnection = None ) : clientProtocol = AccumulatingProtocol ( 999999999999 ) clientFactory = ClientFactory ( ) clientFactory . protocol = ( lambda : clientProtocol ) if fakeConnection : @ implementer ( IOpenSSLServerConnectionCreator , IOpenSSLClientConnectionCreator ) class HardCodedConnection ( object , ) : def clientConnectionForTLS ( self , tlsProtocol ) : return fakeConnection serverConnectionForTLS = clientConnectionForTLS contextFactory = HardCodedConnection ( ) elif server : contextFactory = ServerTLSContext ( ) else : contextFactory = ClientTLSContext ( ) wrapperFactory = TLSMemoryBIOFactory ( contextFactory , ( not server ) , clientFactory ) sslProtocol = wrapperFactory . buildProtocol ( None ) if ( transport is None ) : transport = StringTransport ( ) sslProtocol . makeConnection ( transport ) return ( clientProtocol , sslProtocol )
create a protocol hooked up to a tls transport hooked up to a stringtransport .