Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r14741 - in main/branches/2.1.7/pym: _emerge portage portage/elog
Date: Tue, 27 Oct 2009 22:55:56
Message-Id: E1N2uxG-0003tl-S5@stork.gentoo.org
1 Author: zmedico
2 Date: 2009-10-27 22:55:54 +0000 (Tue, 27 Oct 2009)
3 New Revision: 14741
4
5 Modified:
6 main/branches/2.1.7/pym/_emerge/JobStatusDisplay.py
7 main/branches/2.1.7/pym/portage/elog/messages.py
8 main/branches/2.1.7/pym/portage/output.py
9 main/branches/2.1.7/pym/portage/util.py
10 Log:
11 Bug #290625 - Manually encode output to stdout in python3, in order to avoid
12 potential UnicodeEncodeError exceptions. (trunk r14734)
13
14 Modified: main/branches/2.1.7/pym/_emerge/JobStatusDisplay.py
15 ===================================================================
16 --- main/branches/2.1.7/pym/_emerge/JobStatusDisplay.py 2009-10-27 22:55:37 UTC (rev 14740)
17 +++ main/branches/2.1.7/pym/_emerge/JobStatusDisplay.py 2009-10-27 22:55:54 UTC (rev 14741)
18 @@ -17,6 +17,7 @@
19 from portage import os
20 from portage import _encodings
21 from portage import _unicode_decode
22 +from portage import _unicode_encode
23 from portage.output import xtermTitle
24
25 from _emerge.getloadavg import getloadavg
26 @@ -75,11 +76,14 @@
27 return sys.stdout
28
29 def _write(self, s):
30 - if sys.hexversion < 0x3000000 and isinstance(s, unicode):
31 - # avoid potential UnicodeEncodeError
32 - s = s.encode(_encodings['stdio'], 'backslashreplace')
33 - self.out.write(s)
34 - self.out.flush()
35 + # avoid potential UnicodeEncodeError
36 + s = _unicode_encode(s,
37 + encoding=_encodings['stdio'], errors='backslashreplace')
38 + out = self.out
39 + if sys.hexversion >= 0x3000000:
40 + out = out.buffer
41 + out.write(s)
42 + out.flush()
43
44 def _init_term(self):
45 """
46
47 Modified: main/branches/2.1.7/pym/portage/elog/messages.py
48 ===================================================================
49 --- main/branches/2.1.7/pym/portage/elog/messages.py 2009-10-27 22:55:37 UTC (rev 14740)
50 +++ main/branches/2.1.7/pym/portage/elog/messages.py 2009-10-27 22:55:54 UTC (rev 14741)
51 @@ -96,11 +96,12 @@
52
53 formatted_msg = colorize(color, " * ") + msg + "\n"
54
55 - if sys.hexversion < 0x3000000 and \
56 - out in (sys.stdout, sys.stderr) and isinstance(formatted_msg, unicode):
57 - # avoid potential UnicodeEncodeError
58 - formatted_msg = formatted_msg.encode(
59 - _encodings['stdio'], 'backslashreplace')
60 + # avoid potential UnicodeEncodeError
61 + if out in (sys.stdout, sys.stderr):
62 + formatted_msg = _unicode_encode(formatted_msg,
63 + encoding=_encodings['stdio'], errors='backslashreplace')
64 + if sys.hexversion >= 0x3000000:
65 + out = out.buffer
66
67 out.write(formatted_msg)
68
69
70 Modified: main/branches/2.1.7/pym/portage/output.py
71 ===================================================================
72 --- main/branches/2.1.7/pym/portage/output.py 2009-10-27 22:55:37 UTC (rev 14740)
73 +++ main/branches/2.1.7/pym/portage/output.py 2009-10-27 22:55:54 UTC (rev 14741)
74 @@ -251,12 +251,16 @@
75 mystr = mystr[:_max_xtermTitle_len]
76 if not raw:
77 mystr = '\x1b]0;%s\x07' % mystr
78 - if sys.hexversion < 0x3000000 and isinstance(mystr, unicode):
79 - # avoid potential UnicodeEncodeError
80 - mystr = mystr.encode(_encodings['stdio'], 'backslashreplace')
81 - sys.stderr.write(mystr)
82 - sys.stderr.flush()
83
84 + # avoid potential UnicodeEncodeError
85 + mystr = _unicode_encode(mystr,
86 + encoding=_encodings['stdio'], errors='backslashreplace')
87 + f = sys.stderr
88 + if sys.hexversion >= 0x3000000:
89 + f = f.buffer
90 + f.write(mystr)
91 + f.flush()
92 +
93 default_xterm_title = None
94
95 def xtermTitleReset():
96 @@ -374,11 +378,12 @@
97 self._write(self.write_listener, s)
98
99 def _write(self, f, s):
100 - if sys.hexversion < 0x3000000 and \
101 - isinstance(s, unicode) and \
102 - f in (sys.stdout, sys.stderr):
103 - # avoid potential UnicodeEncodeError
104 - s = s.encode(_encodings['stdio'], 'backslashreplace')
105 + # avoid potential UnicodeEncodeError
106 + if f in (sys.stdout, sys.stderr):
107 + s = _unicode_encode(s,
108 + encoding=_encodings['stdio'], errors='backslashreplace')
109 + if sys.hexversion >= 0x3000000:
110 + f = f.buffer
111 f.write(s)
112
113 def writelines(self, lines):
114 @@ -484,9 +489,12 @@
115 sys.stderr.flush()
116
117 def _write(self, f, s):
118 - if sys.hexversion < 0x3000000 and isinstance(s, unicode):
119 - # avoid potential UnicodeEncodeError
120 - s = s.encode(_encodings['stdio'], 'backslashreplace')
121 + # avoid potential UnicodeEncodeError
122 + s = _unicode_encode(s,
123 + encoding=_encodings['stdio'], errors='backslashreplace')
124 + f = sys.stderr
125 + if sys.hexversion >= 0x3000000:
126 + f = f.buffer
127 f.write(s)
128 f.flush()
129
130
131 Modified: main/branches/2.1.7/pym/portage/util.py
132 ===================================================================
133 --- main/branches/2.1.7/pym/portage/util.py 2009-10-27 22:55:37 UTC (rev 14740)
134 +++ main/branches/2.1.7/pym/portage/util.py 2009-10-27 22:55:54 UTC (rev 14741)
135 @@ -67,10 +67,11 @@
136 if fd is None:
137 fd = sys.stderr
138 if noiselevel <= noiselimit:
139 - if sys.hexversion < 0x3000000:
140 - # avoid potential UnicodeEncodeError
141 - mystr = _unicode_encode(mystr,
142 - encoding=_encodings['stdio'], errors='backslashreplace')
143 + # avoid potential UnicodeEncodeError
144 + mystr = _unicode_encode(mystr,
145 + encoding=_encodings['stdio'], errors='backslashreplace')
146 + if sys.hexversion >= 0x3000000:
147 + fd = fd.buffer
148 fd.write(mystr)
149 fd.flush()