<s> """<STR_LIT>""" <EOL> from twisted . internet import ssl , protocol , endpoints , task , defer <EOL> from twisted . python . filepath import FilePath <EOL> TARGET_HOST = u'<STR_LIT:localhost>' <EOL> TARGET_PORT = <NUM_LIT> <EOL> ACCEPTABLE_PROTOCOLS = [ b'<STR_LIT>' , b'<STR_LIT>' ] <EOL> TLS_TRIGGER_DATA = b'<STR_LIT>' <EOL> def main ( reactor ) : <EOL> certData = FilePath ( '<STR_LIT>' ) . getContent ( ) <EOL> serverCertificate = ssl . Certificate . loadPEM ( certData ) <EOL> options = ssl . optionsForClientTLS ( <EOL> hostname = TARGET_HOST , <EOL> trustRoot = serverCertificate , <EOL> acceptableProtocols = ACCEPTABLE_PROTOCOLS , <EOL> ) <EOL> class BasicH2Request ( protocol . Protocol ) : <EOL> def connectionMade ( self ) : <EOL> print ( "<STR_LIT>" ) <EOL> self . complete = defer . Deferred ( ) <EOL> self . transport . write ( TLS_TRIGGER_DATA ) <EOL> def dataReceived ( self , data ) : <EOL> print ( '<STR_LIT>' % self . transport . negotiatedProtocol ) <EOL> self . transport . loseConnection ( ) <EOL> if self . complete is not None : <EOL> self . complete . callback ( None ) <EOL> self . complete = None <EOL> def connectionLost ( self , reason ) : <EOL> if self . complete is not None : <EOL> print ( "<STR_LIT>" % ( reason , ) ) <EOL> self . complete . callback ( None ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> return endpoints . connectProtocol ( <EOL> endpoints . SSL4ClientEndpoint ( <EOL> reactor , <EOL> TARGET_HOST , <EOL> TARGET_PORT , <EOL> options <EOL> ) , <EOL> BasicH2Request ( ) <EOL> ) . addCallback ( lambda protocol : protocol . complete ) <EOL> task . react ( main ) </s>
