diff -r d7909be3cd05 Lib/asyncore.py --- a/Lib/asyncore.py Sat Apr 06 18:55:31 2013 +0300 +++ b/Lib/asyncore.py Sun Apr 07 19:37:41 2013 +0300 @@ -353,11 +353,8 @@ conn, addr = self.socket.accept() except TypeError: return None - except OSError as why: - if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN): - return None - else: - raise + except (BlockingIOError, ConnectionAbortedError): + return None else: return conn, addr diff -r d7909be3cd05 Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py Sat Apr 06 18:55:31 2013 +0300 +++ b/Lib/distutils/dir_util.py Sun Apr 07 19:37:41 2013 +0300 @@ -68,8 +68,10 @@ if not dry_run: try: os.mkdir(head, mode) + except FileExistsError: + pass except OSError as exc: - if not (exc.errno == errno.EEXIST and os.path.isdir(head)): + if not os.path.isdir(head): raise DistutilsFileError( "could not create '%s': %s" % (head, exc.args[-1])) created_dirs.append(head) diff -r d7909be3cd05 Lib/distutils/spawn.py --- a/Lib/distutils/spawn.py Sat Apr 06 18:55:31 2013 +0300 +++ b/Lib/distutils/spawn.py Sun Apr 07 19:37:41 2013 +0300 @@ -121,10 +121,9 @@ while True: try: pid, status = os.waitpid(pid, 0) + except InterruptedError: + continue except OSError as exc: - import errno - if exc.errno == errno.EINTR: - continue raise DistutilsExecError( "command '%s' failed: %s" % (cmd[0], exc.args[-1])) if os.WIFSIGNALED(status): diff -r d7909be3cd05 Lib/mailbox.py --- a/Lib/mailbox.py Sat Apr 06 18:55:31 2013 +0300 +++ b/Lib/mailbox.py Sun Apr 07 19:37:41 2013 +0300 @@ -295,7 +295,7 @@ self._dump_message(message, tmp_file) except BaseException: tmp_file.close() - os.remove(tmp_file.name) + self._remove_tmp(tmp_file) raise _sync_close(tmp_file) if isinstance(message, MaildirMessage): @@ -311,16 +311,16 @@ try: if hasattr(os, 'link'): os.link(tmp_file.name, dest) - os.remove(tmp_file.name) + self._remove_tmp(tmp_file) else: os.rename(tmp_file.name, dest) - except OSError as e: - os.remove(tmp_file.name) - if e.errno == errno.EEXIST: - raise ExternalClashError('Name clash with existing message: %s' - % dest) - else: - raise + except FileExistsError: + self._remove_tmp(tmp_file) + raise ExternalClashError('Name clash with existing message: %s' + % dest) + except OSError: + self._remove_tmp(tmp_file) + raise if isinstance(message, MaildirMessage): os.utime(dest, (os.path.getatime(dest), message.get_date())) return uniq @@ -501,6 +501,9 @@ raise ExternalClashError('Name clash prevented file creation: %s' % path) + def _remove_tmp(tmp_file): + os.remove(tmp_file.name) + def _refresh(self): """Update table of contents mapping.""" # If it has been less than two seconds since the last _refresh() call, @@ -572,13 +575,15 @@ Mailbox.__init__(self, path, factory, create) try: f = open(self._path, 'rb+') + except FileNotFoundError: + if create: + f = open(self._path, 'wb+') + else: + raise NoSuchMailboxError(self._path) + except PermissionError: + f = open(self._path, 'rb') except OSError as e: - if e.errno == errno.ENOENT: - if create: - f = open(self._path, 'wb+') - else: - raise NoSuchMailboxError(self._path) - elif e.errno in (errno.EACCES, errno.EROFS): + if e.errno == errno.EROFS: f = open(self._path, 'rb') else: raise @@ -972,11 +977,8 @@ path = os.path.join(self._path, str(key)) try: f = open(path, 'rb+') - except OSError as e: - if e.errno == errno.ENOENT: - raise KeyError('No message with key: %s' % key) - else: - raise + except FileNotFoundError: + raise KeyError('No message with key: %s' % key) else: f.close() os.remove(path) @@ -986,11 +988,8 @@ path = os.path.join(self._path, str(key)) try: f = open(path, 'rb+') - except OSError as e: - if e.errno == errno.ENOENT: - raise KeyError('No message with key: %s' % key) - else: - raise + except FileNotFoundError: + raise KeyError('No message with key: %s' % key) try: if self._locked: _lock_file(f) @@ -1012,11 +1011,8 @@ f = open(os.path.join(self._path, str(key)), 'rb+') else: f = open(os.path.join(self._path, str(key)), 'rb') - except OSError as e: - if e.errno == errno.ENOENT: - raise KeyError('No message with key: %s' % key) - else: - raise + except FileNotFoundError: + raise KeyError('No message with key: %s' % key) with f: if self._locked: _lock_file(f) @@ -1037,11 +1033,8 @@ f = open(os.path.join(self._path, str(key)), 'rb+') else: f = open(os.path.join(self._path, str(key)), 'rb') - except OSError as e: - if e.errno == errno.ENOENT: - raise KeyError('No message with key: %s' % key) - else: - raise + except FileNotFoundError: + raise KeyError('No message with key: %s' % key) with f: if self._locked: _lock_file(f) @@ -1055,11 +1048,8 @@ """Return a file-like representation or raise a KeyError.""" try: f = open(os.path.join(self._path, str(key)), 'rb') - except OSError as e: - if e.errno == errno.ENOENT: - raise KeyError('No message with key: %s' % key) - else: - raise + except FileNotFoundError: + raise KeyError('No message with key: %s' % key) return _ProxyFile(f) def iterkeys(self): @@ -2048,8 +2038,11 @@ if fcntl: try: fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB) + except (BlockingIOError, PermissionError): + raise ExternalClashError('lockf: lock unavailable: %s' % + f.name) except OSError as e: - if e.errno in (errno.EAGAIN, errno.EACCES, errno.EROFS): + if e.errno == errno.EROFS: raise ExternalClashError('lockf: lock unavailable: %s' % f.name) else: @@ -2058,8 +2051,10 @@ try: pre_lock = _create_temporary(f.name + '.lock') pre_lock.close() + except PermissionError: + return # Without write access, just skip dotlocking. except OSError as e: - if e.errno in (errno.EACCES, errno.EROFS): + if e.errno == errno.EROFS: return # Without write access, just skip dotlocking. else: raise diff -r d7909be3cd05 Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py Sat Apr 06 18:55:31 2013 +0300 +++ b/Lib/multiprocessing/connection.py Sun Apr 07 19:37:41 2013 +0300 @@ -15,7 +15,6 @@ import select import socket import struct -import errno import time import tempfile import itertools @@ -896,9 +895,8 @@ while True: try: return _poll(object_list, timeout) - except OSError as e: - if e.errno != errno.EINTR: - raise + except InterruptedError: + pass if timeout is not None: timeout = deadline - time.time() diff -r d7909be3cd05 Lib/multiprocessing/forking.py --- a/Lib/multiprocessing/forking.py Sat Apr 06 18:55:31 2013 +0300 +++ b/Lib/multiprocessing/forking.py Sun Apr 07 19:37:41 2013 +0300 @@ -12,7 +12,6 @@ import pickle import sys import signal -import errno from multiprocessing import util, process @@ -124,9 +123,9 @@ while True: try: pid, sts = os.waitpid(self.pid, flag) + except InterruptedError: + continue except OSError as e: - if e.errno == errno.EINTR: - continue # Child process not yet created. See #1731717 # e.errno == errno.ECHILD == 10 return None diff -r d7909be3cd05 Lib/socketserver.py --- a/Lib/socketserver.py Sat Apr 06 18:55:31 2013 +0300 +++ b/Lib/socketserver.py Sun Apr 07 19:37:41 2013 +0300 @@ -133,7 +133,6 @@ import select import sys import os -import errno try: import threading except ImportError: @@ -153,9 +152,8 @@ while True: try: return func(*args) - except OSError as e: - if e.errno != errno.EINTR: - raise + except InterruptedError: + pass class BaseServer: diff -r d7909be3cd05 Lib/telnetlib.py --- a/Lib/telnetlib.py Sat Apr 06 18:55:31 2013 +0300 +++ b/Lib/telnetlib.py Sun Apr 07 19:37:41 2013 +0300 @@ -34,7 +34,6 @@ # Imported modules -import errno import sys import socket import select @@ -313,13 +312,11 @@ while i < 0 and not self.eof: try: ready = poller.poll(call_timeout) - except OSError as e: - if e.errno == errno.EINTR: - if timeout is not None: - elapsed = time() - time_start - call_timeout = timeout-elapsed - continue - raise + except InterruptedError: + if timeout is not None: + elapsed = time() - time_start + call_timeout = timeout-elapsed + continue for fd, mode in ready: if mode & poll_in_or_priority_flags: i = max(0, len(self.cookedq)-n) @@ -683,13 +680,11 @@ while not m and not self.eof: try: ready = poller.poll(call_timeout) - except OSError as e: - if e.errno == errno.EINTR: - if timeout is not None: - elapsed = time() - time_start - call_timeout = timeout-elapsed - continue - raise + except InterruptedError: + if timeout is not None: + elapsed = time() - time_start + call_timeout = timeout-elapsed + continue for fd, mode in ready: if mode & poll_in_or_priority_flags: self.fill_rawq() diff -r d7909be3cd05 Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py Sat Apr 06 18:55:31 2013 +0300 +++ b/Lib/xmlrpc/client.py Sun Apr 07 19:37:41 2013 +0300 @@ -135,7 +135,6 @@ import urllib.parse from xml.parsers import expat import socket -import errno from io import BytesIO try: import gzip @@ -1130,11 +1129,8 @@ for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) - except OSError as e: - if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, - errno.EPIPE): - raise - except http.client.BadStatusLine: #close after we sent request + except (ConnectionResetError, ConnectionAbortedError, + BrokenPipeError, http.client.BadStatusLine): if i: raise