[PATCH 1 of 7] python3: wrap all uses of <exception>.strerror with unitolocal
Yuya Nishihara
yuya at tcha.org
Thu Aug 31 13:56:52 UTC 2017
On Tue, 29 Aug 2017 11:21:58 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf at durin42.com>
> # Date 1503446587 14400
> # Tue Aug 22 20:03:07 2017 -0400
> # Node ID fd4664b32ec7cae6dbfdd6292c04e7f1a4888da2
> # Parent 2ad028635ccd4d47e565c5d59af98ca32165eb3e
> python3: wrap all uses of <exception>.strerror with unitolocal
>
> 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.
s/unitolocal/strtolocal/g and queued 1-4 and 6, thanks.
strerror is byte string on Python 2.x.
> --- a/mercurial/lock.py
> +++ b/mercurial/lock.py
> @@ -148,8 +148,9 @@ class lock(object):
> self.vfs.join(self.f), self.desc,
> locker)
> else:
> - raise error.LockUnavailable(why.errno, why.strerror,
> - why.filename, self.desc)
> + raise error.LockUnavailable(
> + why.errno, encoding.unitolocal(why.strerror),
> + why.filename, self.desc)
LockUnavailable is a subclass of IOError, which should keep strerror as
a unicode string. Dropped this change.
> diff --git a/mercurial/vfs.py b/mercurial/vfs.py
> --- a/mercurial/vfs.py
> +++ b/mercurial/vfs.py
> @@ -16,6 +16,7 @@ import threading
>
> from .i18n import _
> from . import (
> + encoding,
> error,
> pathutil,
> pycompat,
> @@ -434,7 +435,8 @@ class vfs(abstractvfs):
> os.symlink(src, linkname)
> except OSError as err:
> raise OSError(err.errno, _('could not symlink to %r: %s') %
> - (src, err.strerror), linkname)
> + (src, encoding.unitolocal(err.strerror)),
> + linkname)
Perhaps we'll have to convert the message back to unicode by strfromlocal().
More information about the Mercurial-devel
mailing list