commit:     f9a2d7025e22f5e1711f39c4740a020f6f0d2c8f
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Apr  1 22:27:42 2015 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Apr  1 23:14:52 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=f9a2d702

dispatch-conf: fix unicode handling (bug 545270)

This avoids UnicodeDecodeError problems by using UTF-8 encoding
regardless of the locale.

X-Gentoo-Bug: 545270
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=545270

 bin/dispatch-conf            | 9 +++++----
 pym/portage/dispatch_conf.py | 4 +---
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/bin/dispatch-conf b/bin/dispatch-conf
index b679910..678a66d 100755
--- a/bin/dispatch-conf
+++ b/bin/dispatch-conf
@@ -11,12 +11,11 @@
 #  dialog menus
 #
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 import atexit
 import io
 import re
-import shutil
 import sys
 
 from stat import ST_GID, ST_MODE, ST_UID
@@ -27,7 +26,7 @@ if 
osp.isfile(osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), ".porta
        sys.path.insert(0, 
osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym"))
 import portage
 portage._internal_caller = True
-from portage import os
+from portage import os, shutil
 from portage import _encodings, _unicode_decode
 from portage.dispatch_conf import diffstatusoutput, diff_mixed_wrapper
 from portage.process import find_binary, spawn
@@ -403,7 +402,9 @@ class dispatch:
         newconfigs.sort ()
 
         for nconf in newconfigs:
-            nconf = nconf.rstrip ()
+            # Use strict mode here, because we want to know if it fails,
+            # and portage only merges files with valid UTF-8 encoding.
+            nconf = _unicode_decode(nconf, errors='strict').rstrip()
             conf  = re.sub (r'\._cfg\d+_', '', nconf)
             dirname   = os.path.dirname(nconf)
             conf_map  = {

diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py
index 790eacb..98939fd 100644
--- a/pym/portage/dispatch_conf.py
+++ b/pym/portage/dispatch_conf.py
@@ -10,15 +10,13 @@ from __future__ import print_function, unicode_literals
 
 import io
 import functools
-import os
-import shutil
 import stat
 import subprocess
 import sys
 import tempfile
 
 import portage
-from portage import _encodings
+from portage import _encodings, os, shutil
 from portage.env.loaders import KeyValuePairFileLoader
 from portage.localization import _
 from portage.util import shlex_split, varexpand

Reply via email to