diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2017-05-31 18:02:09 -0700 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2017-05-31 18:02:16 -0700 |
commit | f95f0eb1fb82da7ead513dac352ec92712d68e24 (patch) | |
tree | bfe7257b1bed35776405ad5c28825c9af42559d3 | |
parent | 9d5760cf45619ce5aacb567fdc42849d678d93eb (diff) |
Seriously, folks? Refactor some silly crap.
-rw-r--r-- | paramiko/packet.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/paramiko/packet.py b/paramiko/packet.py index 2d36adc8..6f3cd4e2 100644 --- a/paramiko/packet.py +++ b/paramiko/packet.py @@ -46,6 +46,13 @@ class NeedRekeyException (Exception): pass +def first_arg(e): + arg = None + if type(e.args) is tuple and len(e.args) > 0: + arg = e.args[0] + return arg + + class Packetizer (object): """ Implementation of the base SSH packet protocol. @@ -271,11 +278,10 @@ class Packetizer (object): # on Linux, sometimes instead of socket.timeout, we get # EAGAIN. this is a bug in recent (> 2.6.9) kernels but # we need to work around it. - if (type(e.args) is tuple) and (len(e.args) > 0) and \ - (e.args[0] == errno.EAGAIN): + arg = first_arg(e) + if arg == errno.EAGAIN: got_timeout = True - elif (type(e.args) is tuple) and (len(e.args) > 0) and \ - (e.args[0] == errno.EINTR): + elif arg == errno.EINTR: # syscall interrupted; try again pass elif self.__closed: @@ -300,11 +306,10 @@ class Packetizer (object): except socket.timeout: retry_write = True except socket.error as e: - if (type(e.args) is tuple) and (len(e.args) > 0) and \ - (e.args[0] == errno.EAGAIN): + arg = first_arg(e) + if arg == errno.EAGAIN: retry_write = True - elif (type(e.args) is tuple) and (len(e.args) > 0) and \ - (e.args[0] == errno.EINTR): + elif arg == errno.EINTR: # syscall interrupted; try again retry_write = True else: @@ -522,8 +527,7 @@ class Packetizer (object): except socket.timeout: pass except EnvironmentError as e: - if (type(e.args) is tuple and len(e.args) > 0 and - e.args[0] == errno.EINTR): + if first_arg(e) == errno.EINTR: pass else: raise |