[PATCH 04 of 10 STABLE] py3: decode encoding literal before passing to .decode()

Yuya Nishihara yuya at tcha.org
Fri Oct 25 08:05:46 EDT 2019


On Thu, 24 Oct 2019 17:30:35 +0200, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1571920100 -7200
> #      Thu Oct 24 14:28:20 2019 +0200
> # Branch stable
> # Node ID 0e2dd04f18a589180731471cc6a62a10f097bc59
> # Parent  3b9e9dfaf1e032307fa725c69b4c1dee4d92f53e
> py3: decode encoding literal before passing to .decode()
> 
> bytes.decode(<encoding>) wants an str as "encoding" parameter,
> it raises a TypeError if given a bytestring. encoding.encoding and
> encoding.fallbackencoding are bytes values.
> 
> diff --git a/mercurial/mail.py b/mercurial/mail.py
> --- a/mercurial/mail.py
> +++ b/mercurial/mail.py
> @@ -342,6 +342,7 @@ def _encode(ui, s, charsets):
>          s.decode('ascii')
>      except UnicodeDecodeError:
>          for ics in (encoding.encoding, encoding.fallbackencoding):
> +            ics = ics.decode()

Better to not rely on the default platform encoding. Use pycompat.sysstr()
instead.


More information about the Mercurial-devel mailing list