Patchwork [4,of,5] py3: stop subscripting socket.error

login
register
mail settings
Submitter Matt Harbison
Date Dec. 10, 2018, 3:44 a.m.
Message ID <e5b7d60068537baa1ffe.1544413476@Envy>
Download mbox | patch
Permalink /patch/37045/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 10, 2018, 3:44 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1544402454 18000
#      Sun Dec 09 19:40:54 2018 -0500
# Node ID e5b7d60068537baa1ffeeca4e1a81f7498d0d48e
# Parent  8f35bbc97ab5ec0ab5072900b9a70cea8fe720d0
py3: stop subscripting socket.error

In 3.3 and later, this is now an alias for OSError.  I hacked up the server code
enough that I was able to trigger the exception handler in server.py from
test-http-bundle1.t.  Other instances of this either subscript through the
`args` member, or reference the errno or strerror attributes.

Note that on Windows, the errno value seems to reflect the Winsock error, so the
various tests for EPIPE seem like they would always fail.  But that seems to be
the case in py2 as well.

Patch

diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -94,7 +94,7 @@  class _httprequesthandler(httpservermod.
         try:
             self.do_hgweb()
         except socket.error as inst:
-            if inst[0] != errno.EPIPE:
+            if inst.errno != errno.EPIPE:
                 raise
 
     def do_POST(self):
diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py
--- a/mercurial/keepalive.py
+++ b/mercurial/keepalive.py
@@ -636,7 +636,7 @@  def safesend(self, str):
             self.sentbytescount += len(str)
     except socket.error as v:
         reraise = True
-        if v[0] == errno.EPIPE:      # Broken pipe
+        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()