def stapling(f):
    print 'Sending Client Hello...'
    f.write(make_hello())

    print 'Waiting for Server Hello Done...'
    while True:
        record = read_tls_record(f)

        # Look for server hello message.
        if record.content_type() == TLSRecord.Handshake:
            message = HandshakeMessage.from_bytes(record.message())
            if message.message_type() == HandshakeMessage.ServerHelloDone:
                print 'Got server hello done without status...'
                break
            elif message.message_type() == HandshakeMessage.CertificateStatus:
                print 'Got certificate status...'
                print 'Status type:', message.status_type()
                print_ocsp(message.response())
                break
        elif record.content_type() == TLSRecord.Alert:
            alert = AlertMessage.from_bytes(record.message())
            print alert
            if alert.alert_level() == AlertMessage.Fatal:
                raise IOError('Server sent a fatal alert')
        else:
            print 'Record received type %d' % (record.content_type())
dataset/ETHPy150Open WestpointLtd/pytls/stapling.py/stapling/original