Skip to content

Commit

Permalink
Fix indexing exceptions (ex[0]) by using args (ex.args[0]), refs geve…
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Feb 9, 2014
1 parent b48db7d commit 0911fe3
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/geventsendfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def gevent_sendfile(out_fd, in_fd, offset, count):
#print('%s: sent %s [%d%%]' % (out_fd, sent, 100*total_sent/count))
total_sent += sent
except OSError as ex:
if ex[0] == EAGAIN:
if ex.args[0] == EAGAIN:
wait_write(out_fd)
else:
raise
Expand Down
2 changes: 1 addition & 1 deletion gevent/baseserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def serve_forever(self, stop_timeout=None):
Greenlet.spawn(self.stop, timeout=stop_timeout).join()

def is_fatal_error(self, ex):
return isinstance(ex, _socket.error) and ex[0] in self.fatal_errors
return isinstance(ex, _socket.error) and ex.args[0] in self.fatal_errors


def _extract_family(host):
Expand Down
4 changes: 2 additions & 2 deletions gevent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def do_read(self):
try:
client_socket, address = self.socket.accept()
except _socket.error as err:
if err[0] == EWOULDBLOCK:
if err.args[0] == EWOULDBLOCK:
return
raise
return socket(_sock=client_socket), address
Expand Down Expand Up @@ -131,7 +131,7 @@ def do_read(self):
try:
data, address = self._socket.recvfrom(8192)
except _socket.error as err:
if err[0] == EWOULDBLOCK:
if err.args[0] == EWOULDBLOCK:
return
raise
return data, address
Expand Down
2 changes: 1 addition & 1 deletion gevent/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def accept(self):
client_socket, address = sock.accept()
break
except error as ex:
if ex[0] != EWOULDBLOCK or self.timeout == 0.0:
if ex.args[0] != EWOULDBLOCK or self.timeout == 0.0:
raise
sys.exc_clear()
self._wait(self._read_event)
Expand Down
2 changes: 1 addition & 1 deletion gevent/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, sock, keyfile=None, certfile=None,
try:
socket.getpeername(self)
except socket_error as e:
if e[0] != errno.ENOTCONN:
if e.args[0] != errno.ENOTCONN:
raise
# no, no connection yet
self._sslobj = None
Expand Down
2 changes: 1 addition & 1 deletion greentest/test__socket_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test(self):
try:
sock.send('a', timeout=1)
except socket.error as ex:
if ex[0] != 9:
if ex.args[0] != 9:
raise


Expand Down
1 change: 0 additions & 1 deletion greentest/test__socket_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def test(self):
except socket.error as ex:
self.assertEqual(ex.args, ('timed out',))
self.assertEqual(str(ex), 'timed out')
self.assertEqual(ex[0], 'timed out')
finally:
sock.close()
finally:
Expand Down

0 comments on commit 0911fe3

Please sign in to comment.