diff options
Diffstat (limited to 'examples/proxy.py')
-rw-r--r-- | examples/proxy.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/examples/proxy.py b/examples/proxy.py index 3be26f9..946942e 100644 --- a/examples/proxy.py +++ b/examples/proxy.py @@ -8,6 +8,8 @@ # # $Id: proxy.py,v 1.2 2004/07/22 12:01:25 martin Exp $ +from __future__ import print_function + import sys import socket import string @@ -16,9 +18,9 @@ from OpenSSL import SSL def usage(exit_code=0): - print "Usage: %s server[:port] proxy[:port]" % sys.argv[0] - print " Connects SSL to the specified server (port 443 by default)" - print " using the specified proxy (port 8080 by default)" + print("Usage: %s server[:port] proxy[:port]" % sys.argv[0]) + print(" Connects SSL to the specified server (port 443 by default)") + print(" using the specified proxy (port 8080 by default)") sys.exit(exit_code) @@ -44,13 +46,13 @@ def run(server, proxy): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(proxy) - except socket.error, e: - print "Unable to connect to %s:%s %s" % (proxy[0], proxy[1], str(e)) + except socket.error as e: + print("Unable to connect to %s:%s %s" % (proxy[0], proxy[1], str(e))) sys.exit(-1) # Use the CONNECT method to get a connection to the actual server s.send("CONNECT %s:%s HTTP/1.0\n\n" % (server[0], server[1])) - print "Proxy response: %s" % string.strip(s.recv(1024)) + print("Proxy response: %s" % string.strip(s.recv(1024))) ctx = SSL.Context(SSL.SSLv23_METHOD) conn = SSL.Connection(ctx, s) @@ -61,8 +63,8 @@ def run(server, proxy): # start using HTTP conn.send("HEAD / HTTP/1.0\n\n") - print "Sever response:" - print "-" * 40 + print("Sever response:") + print("-" * 40) while 1: try: buff = conn.recv(4096) @@ -70,7 +72,7 @@ def run(server, proxy): # we're done break - print buff, + print(buff, end="") if __name__ == '__main__': |