py3: stop subscripting socket.error
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 09 Dec 2018 19:40:54 -0500
changeset 53639 348352658e4b0b0206e04c9bccd27a036edd5584
parent 53638 44378796c5e5eec7bc3bc3881a0399c8050ec712
child 53641 e7110f44ee2d0e14ce909ace35b39882dcc29f97
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
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.
mercurial/hgweb/server.py
mercurial/keepalive.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -89,17 +89,17 @@ class _httprequesthandler(httpservermod.
         self.log_message(r'"%s" %s %s%s',
                          self.requestline, str(code), str(size),
                          r''.join([r' %s:%s' % h for h in sorted(xheaders)]))
 
     def do_write(self):
         try:
             self.do_hgweb()
         except socket.error as inst:
-            if inst[0] != errno.EPIPE:
+            if inst.errno != errno.EPIPE:
                 raise
 
     def do_POST(self):
         try:
             self.do_write()
         except Exception:
             self._start_response(r"500 Internal Server Error", [])
             self._write(b"Internal Server Error")
--- a/mercurial/keepalive.py
+++ b/mercurial/keepalive.py
@@ -631,17 +631,17 @@ def safesend(self, str):
                 self.sock.sendall(data)
                 self.sentbytescount += len(data)
                 data = read(blocksize)
         else:
             self.sock.sendall(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()
                 reraise = False
             self.close()
         if reraise:
             raise