changeset 34040:d5b2beca16c0

python3: wrap all uses of <exception>.strerror with strtolocal Our string literals are bytes, and we mostly want to %-format a strerror into a one of those literals, so this fixes a ton of issues.
author Augie Fackler <raf@durin42.com>
date Tue, 22 Aug 2017 20:03:07 -0400
parents 31a2eb0f74e5
children ba479850c9c7
files hgext/convert/common.py hgext/mq.py mercurial/cmdutil.py mercurial/dirstate.py mercurial/dispatch.py mercurial/hgweb/common.py mercurial/hgweb/hgwebdir_mod.py mercurial/scmutil.py mercurial/subrepo.py mercurial/vfs.py mercurial/win32.py mercurial/windows.py
diffstat 12 files changed, 35 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/common.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/hgext/convert/common.py	Tue Aug 22 20:03:07 2017 -0400
@@ -15,6 +15,7 @@
 
 from mercurial.i18n import _
 from mercurial import (
+    encoding,
     error,
     phases,
     util,
@@ -475,8 +476,9 @@
             try:
                 self.fp = open(self.path, 'a')
             except IOError as err:
-                raise error.Abort(_('could not open map file %r: %s') %
-                                 (self.path, err.strerror))
+                raise error.Abort(
+                    _('could not open map file %r: %s') %
+                    (self.path, encoding.strtolocal(err.strerror)))
         self.fp.write('%s %s\n' % (key, value))
         self.fp.flush()
         super(mapfile, self).__setitem__(key, value)
--- a/hgext/mq.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/hgext/mq.py	Tue Aug 22 20:03:07 2017 -0400
@@ -80,6 +80,7 @@
     cmdutil,
     commands,
     dirstateguard,
+    encoding,
     error,
     extensions,
     hg,
@@ -1206,7 +1207,7 @@
                 p = self.opener(patchfn, "w")
             except IOError as e:
                 raise error.Abort(_('cannot write patch "%s": %s')
-                                 % (patchfn, e.strerror))
+                                 % (patchfn, encoding.strtolocal(e.strerror)))
             try:
                 defaultmsg = "[mq]: %s" % patchfn
                 editor = cmdutil.getcommiteditor(editform=editform)
--- a/mercurial/cmdutil.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/cmdutil.py	Tue Aug 22 20:03:07 2017 -0400
@@ -777,7 +777,7 @@
                 message = '\n'.join(util.readfile(logfile).splitlines())
         except IOError as inst:
             raise error.Abort(_("can't read commit message '%s': %s") %
-                             (logfile, inst.strerror))
+                             (logfile, encoding.strtolocal(inst.strerror)))
     return message
 
 def mergeeditform(ctxorbool, baseformname):
@@ -1099,7 +1099,7 @@
                     srcexists = False
                 else:
                     ui.warn(_('%s: cannot copy - %s\n') %
-                            (relsrc, inst.strerror))
+                            (relsrc, encoding.strtolocal(inst.strerror)))
                     return True # report a failure
 
         if ui.verbose or not exact:
--- a/mercurial/dirstate.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/dirstate.py	Tue Aug 22 20:03:07 2017 -0400
@@ -982,7 +982,7 @@
                             matchedir(nf)
                         notfoundadd(nf)
                     else:
-                        badfn(ff, inst.strerror)
+                        badfn(ff, encoding.strtolocal(inst.strerror))
 
         # Case insensitive filesystems cannot rely on lstat() failing to detect
         # a case-only rename.  Prune the stat object for any file that does not
@@ -1088,7 +1088,8 @@
                     entries = listdir(join(nd), stat=True, skip=skip)
                 except OSError as inst:
                     if inst.errno in (errno.EACCES, errno.ENOENT):
-                        match.bad(self.pathto(nd), inst.strerror)
+                        match.bad(self.pathto(nd),
+                                  encoding.strtolocal(inst.strerror))
                         continue
                     raise
                 for f, kind, st in entries:
--- a/mercurial/dispatch.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/dispatch.py	Tue Aug 22 20:03:07 2017 -0400
@@ -88,7 +88,8 @@
             status = -1
     if util.safehasattr(req.ui, 'ferr'):
         if err is not None and err.errno != errno.EPIPE:
-            req.ui.ferr.write('abort: %s\n' % err.strerror)
+            req.ui.ferr.write('abort: %s\n' %
+                              encoding.strtolocal(err.strerror))
         req.ui.ferr.flush()
     sys.exit(status & 255)
 
@@ -676,7 +677,7 @@
             wd = pycompat.getcwd()
         except OSError as e:
             raise error.Abort(_("error getting current working directory: %s") %
-                              e.strerror)
+                              encoding.strtolocal(e.strerror))
     path = cmdutil.findrepo(wd) or ""
     if not path:
         lui = ui
--- a/mercurial/hgweb/common.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/hgweb/common.py	Tue Aug 22 20:03:07 2017 -0400
@@ -178,7 +178,8 @@
         if err.errno == errno.ENOENT:
             raise ErrorResponse(HTTP_NOT_FOUND)
         else:
-            raise ErrorResponse(HTTP_SERVER_ERROR, err.strerror)
+            raise ErrorResponse(HTTP_SERVER_ERROR,
+                                encoding.strtolocal(err.strerror))
 
 def paritygen(stripecount, offset=0):
     """count parity of horizontal stripes for easier reading"""
--- a/mercurial/hgweb/hgwebdir_mod.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/hgweb/hgwebdir_mod.py	Tue Aug 22 20:03:07 2017 -0400
@@ -289,7 +289,7 @@
                         repo = hg.repository(self.ui.copy(), real)
                         return hgweb_mod.hgweb(repo).run_wsgi(req)
                     except IOError as inst:
-                        msg = inst.strerror
+                        msg = encoding.strtolocal(inst.strerror)
                         raise ErrorResponse(HTTP_SERVER_ERROR, msg)
                     except error.RepoError as inst:
                         raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
--- a/mercurial/scmutil.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/scmutil.py	Tue Aug 22 20:03:07 2017 -0400
@@ -163,7 +163,8 @@
             ui.warn(_("(lock might be very busy)\n"))
     except error.LockUnavailable as inst:
         ui.warn(_("abort: could not lock %s: %s\n") %
-               (inst.desc or inst.filename, inst.strerror))
+               (inst.desc or inst.filename,
+                encoding.strtolocal(inst.strerror)))
     except error.OutOfBandError as inst:
         if inst.args:
             msg = _("abort: remote error:\n")
@@ -226,16 +227,18 @@
             pass
         elif getattr(inst, "strerror", None):
             if getattr(inst, "filename", None):
-                ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
+                ui.warn(_("abort: %s: %s\n") % (
+                    encoding.strtolocal(inst.strerror), inst.filename))
             else:
-                ui.warn(_("abort: %s\n") % inst.strerror)
+                ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
         else:
             raise
     except OSError as inst:
         if getattr(inst, "filename", None) is not None:
-            ui.warn(_("abort: %s: '%s'\n") % (inst.strerror, inst.filename))
+            ui.warn(_("abort: %s: '%s'\n") % (
+                encoding.strtolocal(inst.strerror), inst.filename))
         else:
-            ui.warn(_("abort: %s\n") % inst.strerror)
+            ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
     except MemoryError:
         ui.warn(_("abort: out of memory\n"))
     except SystemExit as inst:
--- a/mercurial/subrepo.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/subrepo.py	Tue Aug 22 20:03:07 2017 -0400
@@ -1346,7 +1346,8 @@
             genericerror = _("error executing git for subrepo '%s': %s")
             notfoundhint = _("check git is installed and in your PATH")
             if e.errno != errno.ENOENT:
-                raise error.Abort(genericerror % (self._path, e.strerror))
+                raise error.Abort(genericerror % (
+                    self._path, encoding.strtolocal(e.strerror)))
             elif pycompat.osname == 'nt':
                 try:
                     self._gitexecutable = 'git.cmd'
@@ -1358,7 +1359,7 @@
                             hint=notfoundhint)
                     else:
                         raise error.Abort(genericerror % (self._path,
-                            e2.strerror))
+                            encoding.strtolocal(e2.strerror)))
             else:
                 raise error.Abort(_("couldn't find git for subrepo '%s'")
                     % self._path, hint=notfoundhint)
--- a/mercurial/vfs.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/vfs.py	Tue Aug 22 20:03:07 2017 -0400
@@ -16,6 +16,7 @@
 
 from .i18n import _
 from . import (
+    encoding,
     error,
     pathutil,
     pycompat,
@@ -434,7 +435,8 @@
                 os.symlink(src, linkname)
             except OSError as err:
                 raise OSError(err.errno, _('could not symlink to %r: %s') %
-                              (src, err.strerror), linkname)
+                              (src, encoding.strtolocal(err.strerror)),
+                              linkname)
         else:
             self.write(dst, src)
 
--- a/mercurial/win32.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/win32.py	Tue Aug 22 20:03:07 2017 -0400
@@ -286,7 +286,8 @@
     if code > 0x7fffffff:
         code -= 2**32
     err = ctypes.WinError(code=code)
-    raise OSError(err.errno, '%s: %s' % (name, err.strerror))
+    raise OSError(err.errno, '%s: %s' % (name,
+                                         encoding.strtolocal(err.strerror)))
 
 def _getfileinfo(name):
     fh = _kernel32.CreateFileA(name, 0,
--- a/mercurial/windows.py	Wed Aug 30 14:04:55 2017 -0700
+++ b/mercurial/windows.py	Tue Aug 22 20:03:07 2017 -0400
@@ -137,7 +137,8 @@
         return fp
     except WindowsError as err:
         # convert to a friendlier exception
-        raise IOError(err.errno, '%s: %s' % (name, err.strerror))
+        raise IOError(err.errno, '%s: %s' % (
+            name, encoding.strtolocal(err.strerror)))
 
 # may be wrapped by win32mbcs extension
 listdir = osutil.listdir