Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH v3] dispatch-conf: fix unicode handling (bug 545270)
Date: Wed, 01 Apr 2015 23:17:57
Message-Id: 1427930251-30901-1-git-send-email-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] dispatch_conf: use portage.os unicode wrapper (bug 545270) by Zac Medico
1 This avoids UnicodeDecodeError problems by using UTF-8 encoding
2 regardless of the locale.
3
4 X-Gentoo-Bug: 545270
5 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=545270
6 ---
7 [PATCH v3] adds related fixes in bin/dispatch-conf
8
9 bin/dispatch-conf | 9 +++++----
10 pym/portage/dispatch_conf.py | 4 +---
11 2 files changed, 6 insertions(+), 7 deletions(-)
12
13 diff --git a/bin/dispatch-conf b/bin/dispatch-conf
14 index b679910..678a66d 100755
15 --- a/bin/dispatch-conf
16 +++ b/bin/dispatch-conf
17 @@ -11,12 +11,11 @@
18 # dialog menus
19 #
20
21 -from __future__ import print_function
22 +from __future__ import print_function, unicode_literals
23
24 import atexit
25 import io
26 import re
27 -import shutil
28 import sys
29
30 from stat import ST_GID, ST_MODE, ST_UID
31 @@ -27,7 +26,7 @@ if osp.isfile(osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), ".porta
32 sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym"))
33 import portage
34 portage._internal_caller = True
35 -from portage import os
36 +from portage import os, shutil
37 from portage import _encodings, _unicode_decode
38 from portage.dispatch_conf import diffstatusoutput, diff_mixed_wrapper
39 from portage.process import find_binary, spawn
40 @@ -403,7 +402,9 @@ class dispatch:
41 newconfigs.sort ()
42
43 for nconf in newconfigs:
44 - nconf = nconf.rstrip ()
45 + # Use strict mode here, because we want to know if it fails,
46 + # and portage only merges files with valid UTF-8 encoding.
47 + nconf = _unicode_decode(nconf, errors='strict').rstrip()
48 conf = re.sub (r'\._cfg\d+_', '', nconf)
49 dirname = os.path.dirname(nconf)
50 conf_map = {
51 diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py
52 index 790eacb..98939fd 100644
53 --- a/pym/portage/dispatch_conf.py
54 +++ b/pym/portage/dispatch_conf.py
55 @@ -10,15 +10,13 @@ from __future__ import print_function, unicode_literals
56
57 import io
58 import functools
59 -import os
60 -import shutil
61 import stat
62 import subprocess
63 import sys
64 import tempfile
65
66 import portage
67 -from portage import _encodings
68 +from portage import _encodings, os, shutil
69 from portage.env.loaders import KeyValuePairFileLoader
70 from portage.localization import _
71 from portage.util import shlex_split, varexpand
72 --
73 2.3.1