Make all of the examples py3 syntax friendly (#816)
diff --git a/examples/sni/client.py b/examples/sni/client.py
index 428525b..d4a751f 100644
--- a/examples/sni/client.py
+++ b/examples/sni/client.py
@@ -1,6 +1,8 @@
# Copyright (C) Jean-Paul Calderone
# See LICENSE for details.
+from __future__ import print_function
+
from sys import argv, stdout
from socket import socket
@@ -13,21 +15,21 @@
by argv[1], of it.
"""
if len(argv) < 2:
- print 'Usage: %s <hostname>' % (argv[0],)
+ print('Usage: %s <hostname>' % (argv[0],))
return 1
client = socket()
- print 'Connecting...',
+ print('Connecting...', end="")
stdout.flush()
client.connect(('127.0.0.1', 8443))
- print 'connected', client.getpeername()
+ print('connected', client.getpeername())
client_ssl = Connection(Context(TLSv1_METHOD), client)
client_ssl.set_connect_state()
client_ssl.set_tlsext_host_name(argv[1])
client_ssl.do_handshake()
- print 'Server subject is', client_ssl.get_peer_certificate().get_subject()
+ print('Server subject is', client_ssl.get_peer_certificate().get_subject())
client_ssl.close()
diff --git a/examples/sni/server.py b/examples/sni/server.py
index e0c159a..891c6c5 100644
--- a/examples/sni/server.py
+++ b/examples/sni/server.py
@@ -1,6 +1,8 @@
# Copyright (C) Jean-Paul Calderone
# See LICENSE for details.
+from __future__ import print_function
+
from sys import stdout
from socket import SOL_SOCKET, SO_REUSEADDR, socket
@@ -29,10 +31,10 @@
port.bind(('', 8443))
port.listen(3)
- print 'Accepting...',
+ print('Accepting...', end="")
stdout.flush()
server, addr = port.accept()
- print 'accepted', addr
+ print('accepted', addr)
server_context = Context(TLSv1_METHOD)
server_context.set_tlsext_servername_callback(pick_certificate)