summaryrefslogtreecommitdiffhomepage
path: root/demos/forward.py
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2014-03-13 21:08:55 -0700
committerJeff Forcier <jeff@bitprophet.org>2014-03-13 21:08:55 -0700
commit0424f2c4c9cb5bccb0509f285f512c6cb3254c91 (patch)
tree6cf0e5b3f565b54e1b4239656f034128c854e9bf /demos/forward.py
parentbd61c7c0a9a4a2020d0acfb6a01e9ec85bb43b8e (diff)
parenta4645b0c9c44311b0e3a58bce6e827e6c7047383 (diff)
Merge pull request #276 from paramiko/python3
Merged-to-master Python 3 branch
Diffstat (limited to 'demos/forward.py')
-rw-r--r--demos/forward.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/demos/forward.py b/demos/forward.py
index 5048c775..96e1700d 100644
--- a/demos/forward.py
+++ b/demos/forward.py
@@ -30,7 +30,11 @@ import getpass
import os
import socket
import select
-import SocketServer
+try:
+ import SocketServer
+except ImportError:
+ import socketserver as SocketServer
+
import sys
from optparse import OptionParser
@@ -54,7 +58,7 @@ class Handler (SocketServer.BaseRequestHandler):
chan = self.ssh_transport.open_channel('direct-tcpip',
(self.chain_host, self.chain_port),
self.request.getpeername())
- except Exception, e:
+ except Exception as e:
verbose('Incoming request to %s:%d failed: %s' % (self.chain_host,
self.chain_port,
repr(e)))
@@ -98,7 +102,7 @@ def forward_tunnel(local_port, remote_host, remote_port, transport):
def verbose(s):
if g_verbose:
- print s
+ print(s)
HELP = """\
@@ -165,8 +169,8 @@ def main():
try:
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
look_for_keys=options.look_for_keys, password=password)
- except Exception, e:
- print '*** Failed to connect to %s:%d: %r' % (server[0], server[1], e)
+ except Exception as e:
+ print('*** Failed to connect to %s:%d: %r' % (server[0], server[1], e))
sys.exit(1)
verbose('Now forwarding port %d to %s:%d ...' % (options.port, remote[0], remote[1]))
@@ -174,7 +178,7 @@ def main():
try:
forward_tunnel(options.port, remote[0], remote[1], client.get_transport())
except KeyboardInterrupt:
- print 'C-c: Port forwarding stopped.'
+ print('C-c: Port forwarding stopped.')
sys.exit(0)