Skip to content

Commit 1c760fa

Browse files
author
Dan
committed
Updated exception handling syntax. Added wheel configuration
1 parent fe12a3d commit 1c760fa

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

embedded_server/embedded_server.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def check_channel_direct_tcpip_request(self, chanid, origin, destination):
104104
try:
105105
tunnel = Tunneler(destination, self.transport, chanid)
106106
tunnel.start()
107-
except Exception, ex:
107+
except Exception as ex:
108108
logger.error("Error creating proxy connection to %s - %s",
109109
destination, ex,)
110110
return paramiko.OPEN_FAILED_CONNECT_FAILED
@@ -144,7 +144,7 @@ def make_socket(listen_ip, port=0):
144144
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
145145
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
146146
sock.bind((listen_ip, port))
147-
except Exception, e:
147+
except Exception as e:
148148
logger.error('Failed to bind to address - %s' % (str(e),))
149149
traceback.print_exc()
150150
return
@@ -166,7 +166,7 @@ def listen(sock, fail_auth=False, ssh_exception=False,
166166
sock.listen(100)
167167
logger.info('Listening for connection on %s:%s..', listen_ip,
168168
listen_port)
169-
except Exception, e:
169+
except Exception as e:
170170
logger.error('*** Listen failed: %s' % (str(e),))
171171
traceback.print_exc()
172172
return
@@ -185,7 +185,7 @@ def _handle_ssh_connection(transport, fail_auth=False,
185185
fail_auth=fail_auth, ssh_exception=ssh_exception)
186186
try:
187187
transport.start_server(server=server)
188-
except paramiko.SSHException, e:
188+
except paramiko.SSHException as e:
189189
logger.exception('SSH negotiation failed')
190190
return
191191
except Exception:
@@ -216,7 +216,7 @@ def handle_ssh_connection(sock,
216216
transport = paramiko.Transport(conn)
217217
_handle_ssh_connection(transport, fail_auth=fail_auth,
218218
ssh_exception=ssh_exception)
219-
except Exception, e:
219+
except Exception as e:
220220
logger.error('*** Caught exception: %s: %s' % (str(e.__class__), str(e),))
221221
traceback.print_exc()
222222
try:

embedded_server/tunnel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ def run(self):
6666
self.transport.get_username())
6767
try:
6868
self.tunnel(self.socket, channel)
69-
except Exception, ex:
69+
except Exception as ex:
7070
logger.exception("Got exception creating tunnel - %s", ex,)
7171
logger.debug("Finished tunneling")

pssh/pssh_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,11 @@ def get_output(self, cmd, output):
616616
"""
617617
try:
618618
(channel, host, stdout, stderr, stdin) = cmd.get()
619-
except Exception, ex:
619+
except Exception as ex:
620620
exc = sys.exc_info()
621621
try:
622622
host = ex.args[1]
623-
except IndexError, _ex:
623+
except IndexError as _ex:
624624
logger.error("Got exception with no host argument - "
625625
"cannot update output data with %s", _ex)
626626
raise exc[1], None, exc[2]

pssh/ssh_client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def _connect_tunnel(self):
147147
'direct-tcpip', (self.host, self.port,), ('127.0.0.1', 0))
148148
sleep(0)
149149
return self._connect(self.client, self.host, self.port, sock=proxy_channel)
150-
except ChannelException, ex:
150+
except ChannelException as ex:
151151
error_type = ex.args[1] if len(ex.args) > 1 else ex.args[0]
152152
raise ConnectionErrorException("Error connecting to host '%s:%s' - %s",
153153
self.host, self.port,
@@ -168,7 +168,7 @@ def _connect(self, client, host, port, sock=None, retries=1,
168168
port=port, pkey=pkey if pkey else self.pkey,
169169
sock=sock, timeout=self.timeout,
170170
allow_agent=self.allow_agent)
171-
except sock_gaierror, ex:
171+
except sock_gaierror as ex:
172172
logger.error("Could not resolve host '%s' - retry %s/%s",
173173
host, retries, self.num_retries)
174174
while retries < self.num_retries:
@@ -178,7 +178,7 @@ def _connect(self, client, host, port, sock=None, retries=1,
178178
raise UnknownHostException("Unknown host %s - %s - retry %s/%s",
179179
host, str(ex.args[1]), retries,
180180
self.num_retries)
181-
except sock_error, ex:
181+
except sock_error as ex:
182182
logger.error("Error connecting to host '%s:%s' - retry %s/%s",
183183
self.host, self.port, retries, self.num_retries)
184184
while retries < self.num_retries:
@@ -189,12 +189,12 @@ def _connect(self, client, host, port, sock=None, retries=1,
189189
raise ConnectionErrorException("Error connecting to host '%s:%s' - %s - retry %s/%s",
190190
self.host, self.port,
191191
str(error_type), retries, self.num_retries,)
192-
except paramiko.AuthenticationException, ex:
192+
except paramiko.AuthenticationException as ex:
193193
msg = "Authentication error while connecting to %s:%s."
194194
raise AuthenticationException(msg, host, port)
195195
# SSHException is more general so should be below other types
196196
# of SSH failure
197-
except paramiko.SSHException, ex:
197+
except paramiko.SSHException as ex:
198198
msg = "General SSH error - %s" % (ex,)
199199
logger.error(msg)
200200
raise SSHException(msg, host, port)
@@ -289,7 +289,7 @@ def _mkdir(self, sftp, directory):
289289
"""
290290
try:
291291
sftp.mkdir(directory)
292-
except IOError, error:
292+
except IOError as error:
293293
msg = "Error occured creating directory %s on %s - %s"
294294
logger.error(msg, directory, self.host, error)
295295
raise IOError(msg, directory, self.host, error)
@@ -372,7 +372,7 @@ def copy_file(self, local_file, remote_file, recurse=False):
372372
sftp.chdir()
373373
try:
374374
sftp.put(local_file, remote_file)
375-
except Exception, error:
375+
except Exception as error:
376376
logger.error("Error occured copying file %s to remote destination %s:%s - %s",
377377
local_file, self.host, remote_file, error)
378378
raise error

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ VCS = git
33
style = pep440
44
versionfile_source = pssh/_version.py
55
tag_prefix = ''
6+
7+
[bdist_wheel]
8+
universal = 0

0 commit comments

Comments
 (0)