Patchwork [1,of,4] py3: make sure encoding.encoding is a bytes variable

login
register
mail settings
Submitter Pulkit Goyal
Date Dec. 18, 2016, 12:01 p.m.
Message ID <af87471131e2fecc9e6e.1482062491@pulkit-goyal>
Download mbox | patch
Permalink /patch/17951/
State Accepted
Headers show

Comments

Pulkit Goyal - Dec. 18, 2016, 12:01 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1481999125 -19800
#      Sat Dec 17 23:55:25 2016 +0530
# Node ID af87471131e2fecc9e6edeb2a5c2e155953da4bb
# Parent  1c8efe62f1f36fdf1a1bd6fcc5924cf557141d4a
py3: make sure encoding.encoding is a bytes variable

encoding.encoding returns unicodes when locale.getpreferredencoding() is used
to get the preferred encoding. This patch fixes that.
Yuya Nishihara - Dec. 20, 2016, 1:48 p.m.
On Sun, 18 Dec 2016 17:31:31 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1481999125 -19800
> #      Sat Dec 17 23:55:25 2016 +0530
> # Node ID af87471131e2fecc9e6edeb2a5c2e155953da4bb
> # Parent  1c8efe62f1f36fdf1a1bd6fcc5924cf557141d4a
> py3: make sure encoding.encoding is a bytes variable

Looks good. Queued the series, thanks.

Patch

diff -r 1c8efe62f1f3 -r af87471131e2 mercurial/encoding.py
--- a/mercurial/encoding.py	Sat Dec 17 20:24:46 2016 +0530
+++ b/mercurial/encoding.py	Sat Dec 17 23:55:25 2016 +0530
@@ -93,7 +93,7 @@ 
 try:
     encoding = environ.get("HGENCODING")
     if not encoding:
-        encoding = locale.getpreferredencoding() or 'ascii'
+        encoding = locale.getpreferredencoding().encode('ascii') or 'ascii'
         encoding = _encodingfixers.get(encoding, lambda: encoding)()
 except locale.Error:
     encoding = 'ascii'