Skip to content

Commit c4d45ee

Browse files
bpo-42427: Use the errno attribute of OSError instead of args[0] (pythonGH-23449)
1 parent bd8c22e commit c4d45ee

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Lib/asyncore.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def readwrite(obj, flags):
113113
if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
114114
obj.handle_close()
115115
except OSError as e:
116-
if e.args[0] not in _DISCONNECTED:
116+
if e.errno not in _DISCONNECTED:
117117
obj.handle_error()
118118
else:
119119
obj.handle_close()
@@ -236,7 +236,7 @@ def __init__(self, sock=None, map=None):
236236
try:
237237
self.addr = sock.getpeername()
238238
except OSError as err:
239-
if err.args[0] in (ENOTCONN, EINVAL):
239+
if err.errno in (ENOTCONN, EINVAL):
240240
# To handle the case where we got an unconnected
241241
# socket.
242242
self.connected = False
@@ -346,7 +346,7 @@ def accept(self):
346346
except TypeError:
347347
return None
348348
except OSError as why:
349-
if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN):
349+
if why.errno in (EWOULDBLOCK, ECONNABORTED, EAGAIN):
350350
return None
351351
else:
352352
raise
@@ -358,9 +358,9 @@ def send(self, data):
358358
result = self.socket.send(data)
359359
return result
360360
except OSError as why:
361-
if why.args[0] == EWOULDBLOCK:
361+
if why.errno == EWOULDBLOCK:
362362
return 0
363-
elif why.args[0] in _DISCONNECTED:
363+
elif why.errno in _DISCONNECTED:
364364
self.handle_close()
365365
return 0
366366
else:
@@ -378,7 +378,7 @@ def recv(self, buffer_size):
378378
return data
379379
except OSError as why:
380380
# winsock sometimes raises ENOTCONN
381-
if why.args[0] in _DISCONNECTED:
381+
if why.errno in _DISCONNECTED:
382382
self.handle_close()
383383
return b''
384384
else:
@@ -393,7 +393,7 @@ def close(self):
393393
try:
394394
self.socket.close()
395395
except OSError as why:
396-
if why.args[0] not in (ENOTCONN, EBADF):
396+
if why.errno not in (ENOTCONN, EBADF):
397397
raise
398398

399399
# log and log_info may be overridden to provide more sophisticated
@@ -557,7 +557,7 @@ def close_all(map=None, ignore_all=False):
557557
try:
558558
x.close()
559559
except OSError as x:
560-
if x.args[0] == EBADF:
560+
if x.errno == EBADF:
561561
pass
562562
elif not ignore_all:
563563
raise

Lib/smtpd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __init__(self, server, conn, addr, data_size_limit=DATA_SIZE_DEFAULT,
163163
# a race condition may occur if the other end is closing
164164
# before we can get the peername
165165
self.close()
166-
if err.args[0] != errno.ENOTCONN:
166+
if err.errno != errno.ENOTCONN:
167167
raise
168168
return
169169
print('Peer:', repr(self.peer), file=DEBUGSTREAM)

Lib/socket.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def readinto(self, b):
706706
self._timeout_occurred = True
707707
raise
708708
except error as e:
709-
if e.args[0] in _blocking_errnos:
709+
if e.errno in _blocking_errnos:
710710
return None
711711
raise
712712

@@ -722,7 +722,7 @@ def write(self, b):
722722
return self._sock.send(b)
723723
except error as e:
724724
# XXX what about EINTR?
725-
if e.args[0] in _blocking_errnos:
725+
if e.errno in _blocking_errnos:
726726
return None
727727
raise
728728

0 commit comments

Comments
 (0)