diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -76,7 +76,6 @@ import email.encoders as emailencoders import email.mime.base as emimebase import email.mime.multipart as emimemultipart import email.utils as eutil -import errno import os import socket @@ -984,9 +983,8 @@ def email(ui, repo, *revs, **opts): try: generator.flatten(m, False) ui.write(b'\n') - except IOError as inst: - if inst.errno != errno.EPIPE: - raise + except BrokenPipeError: + pass else: if not sendmail: sendmail = mail.connect(ui, mbox=mbox) diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py --- a/mercurial/commandserver.py +++ b/mercurial/commandserver.py @@ -6,7 +6,6 @@ # GNU General Public License version 2 or any later version. -import errno import gc import os import random @@ -494,9 +493,8 @@ def _serverequest(ui, repo, conn, create # known exceptions are caught by dispatch. except error.Abort as inst: ui.error(_(b'abort: %s\n') % inst.message) - except IOError as inst: - if inst.errno != errno.EPIPE: - raise + except BrokenPipeError: + pass except KeyboardInterrupt: pass finally: @@ -514,9 +512,8 @@ def _serverequest(ui, repo, conn, create fin.close() try: fout.close() # implicit flush() may cause another EPIPE - except IOError as inst: - if inst.errno != errno.EPIPE: - raise + except BrokenPipeError: + pass class unixservicehandler: diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -290,9 +290,8 @@ def _rundispatch(req): # maybe pager would quit without consuming all the output, and # SIGPIPE was raised. we cannot print anything in this case. pass - except IOError as inst: - if inst.errno != errno.EPIPE: - raise + except BrokenPipeError: + pass ret = -1 finally: duration = util.timer() - starttime diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py +++ b/mercurial/hgweb/server.py @@ -115,9 +115,8 @@ class _httprequesthandler(httpservermod. def do_write(self): try: self.do_hgweb() - except socket.error as inst: - if inst.errno != errno.EPIPE: - raise + except BrokenPipeError: + pass def do_POST(self): try: diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py --- a/mercurial/keepalive.py +++ b/mercurial/keepalive.py @@ -84,7 +84,6 @@ EXTRA ATTRIBUTES AND METHODS import collections -import errno import hashlib import socket import sys @@ -657,14 +656,14 @@ def safesend(self, str): else: self.sock.sendall(str) self.sentbytescount += len(str) - except socket.error as v: - reraise = True - if v.args[0] == errno.EPIPE: # Broken pipe - if self._HTTPConnection__state == httplib._CS_REQ_SENT: - self._broken_pipe_resp = None - self._broken_pipe_resp = self.getresponse() - reraise = False - self.close() + except BrokenPipeError: + if self._HTTPConnection__state == httplib._CS_REQ_SENT: + self._broken_pipe_resp = None + self._broken_pipe_resp = self.getresponse() + reraise = False + else: + reraise = True + self.close() if reraise: raise