From 4964fb10003bc8e06e546b62431e2a38a1f4a180 Mon Sep 17 00:00:00 2001 From: Craig Rodrigues Date: Fri, 13 Nov 2015 05:46:46 -0800 Subject: Use print as a function for Python 3. [PEP 3105] For Python 2 compatibility, import print_function from the __future__ module. This works as far back as Python 2.6.0a2: https://docs.python.org/2/library/__future__.html --- contrib/SimpleX509create.py | 13 +++++++------ contrib/dispatcher.py | 11 +++++++---- contrib/isaac.httpslib.py | 6 ++++-- 3 files changed, 18 insertions(+), 12 deletions(-) (limited to 'contrib') diff --git a/contrib/SimpleX509create.py b/contrib/SimpleX509create.py index 7f5fc67..3a7c83c 100644 --- a/contrib/SimpleX509create.py +++ b/contrib/SimpleX509create.py @@ -2,6 +2,7 @@ # #vim: ts=4 sw=4 nowrap # +from __future__ import print_function """PKI demo by Peter Teniz """ @@ -71,7 +72,7 @@ class Cert: self.X509Request.set_pubkey ( pkey=self.PKey ) self.X509Request.sign ( pkey=self.PKey, md='sha1' ) - #print X509Request.as_text () + #print(X509Request.as_text ()) @@ -119,8 +120,8 @@ class Cert: X509Name = self.X509Request.get_subject () - #print X509Name.entry_count () - #print X509Name.as_text () + #print(X509Name.entry_count ()) + #print(X509Name.as_text ()) self.X509Certificate.set_subject_name( X509Name ) @@ -139,8 +140,8 @@ class Cert: X509Name.add_entry_by_txt ( field='Email', type=MBSTRING_ASC, entry='admin@localhost', len=-1, loc=-1, set=0 ) # pkcs9 email address X509Name.add_entry_by_txt ( field='emailAddress', type=MBSTRING_ASC, entry='admin@localhost', len=-1, loc=-1, set=0 ) # pkcs9 email address - #print X509Name.entry_count () - #print X509Name.as_text () + #print(X509Name.entry_count ()) + #print(X509Name.as_text ()) self.X509Certificate.set_issuer_name( X509Name ) @@ -149,7 +150,7 @@ class Cert: # self.X509Certificate.sign( pkey=self.PKey, md='sha1' ) - print self.X509Certificate.as_text () + print(self.X509Certificate.as_text ()) diff --git a/contrib/dispatcher.py b/contrib/dispatcher.py index 6e7302d..6721d56 100644 --- a/contrib/dispatcher.py +++ b/contrib/dispatcher.py @@ -1,4 +1,7 @@ #!/usr/local/bin/python -O + +from __future__ import print_function + """ Implements a [hopefully] non-blocking SSL dispatcher on top of M2Crypto package. @@ -149,18 +152,18 @@ class dispatcher(asyncore.dispatcher_with_send): """Invoked on SSL connection establishment (whilst in client mode) """ - print 'Unhandled handle_ssl_connect()' + print('Unhandled handle_ssl_connect()') def handle_ssl_accept(self): """Invoked on SSL connection establishment (whilst in server mode) """ - print 'Unhandled handle_ssl_accept()' + print('Unhandled handle_ssl_accept()') def handle_ssl_read(self, data): """Invoked on new data arrival to SSL connection """ - print 'Unhandled handle_ssl_read event' + print('Unhandled handle_ssl_read event') def handle_ssl_close(self): """Invoked on SSL connection termination @@ -182,7 +185,7 @@ if __name__=='__main__': dispatcher.__init__(self, cert, key) def handle_ssl_read(self, data): - print data + print(data) self.ssl_write('test write') ssl = client('test.cert', 'test.key') diff --git a/contrib/isaac.httpslib.py b/contrib/isaac.httpslib.py index 627a8fd..a5ea5e2 100644 --- a/contrib/isaac.httpslib.py +++ b/contrib/isaac.httpslib.py @@ -1,3 +1,5 @@ +from __future__ import print_function + """M2Crypto support for Python 1.5.2 and Python 2.x's httplib. Copyright (c) 1999-2002 Ng Pheng Siong. All rights reserved.""" @@ -102,7 +104,7 @@ elif sys.version[:3] == '1.5': raise socket.error("nonnumeric port") if not port: port = HTTPS_PORT self.sock = SSL.Connection(self.ssl_ctx) - if self.debuglevel > 0: print 'connect:', (host, port) + if self.debuglevel > 0: print('connect:', (host, port)) self.sock.connect((host, port)) # ISS Added. @@ -257,7 +259,7 @@ class HTTPSProxyConnection(HTTPProxyConnection): # Fake the socket ssl = socket.ssl(self.sock, self.key_file, self.cert_file) self.sock = FakeSocket(self.sock, ssl) - if self.debuglevel > 0: print 'socket type:', self.sock + if self.debuglevel > 0: print('socket type:', self.sock) def putrequest(self, method, url): """Send a request to the server. -- cgit v1.2.1