1 |
Author: grobian |
2 |
Date: 2009-08-24 09:34:26 +0000 (Mon, 24 Aug 2009) |
3 |
New Revision: 14141 |
4 |
|
5 |
Modified: |
6 |
main/branches/prefix/pym/_emerge/actions.py |
7 |
main/branches/prefix/pym/portage/__init__.py |
8 |
main/branches/prefix/pym/portage/cvstree.py |
9 |
main/branches/prefix/pym/portage/dbapi/vartree.py |
10 |
main/branches/prefix/pym/portage/getbinpkg.py |
11 |
main/branches/prefix/pym/portage/glsa.py |
12 |
main/branches/prefix/pym/portage/mail.py |
13 |
main/branches/prefix/pym/repoman/checks.py |
14 |
main/branches/prefix/pym/repoman/utilities.py |
15 |
Log: |
16 |
Merged from trunk -r14087:14097 |
17 |
|
18 |
| 14088 | Use _content_encoding where appropriate. | |
19 |
| zmedico | | |
20 |
|
21 |
| 14089 | Use the new portage.output._init(config_root) function. | |
22 |
| zmedico | | |
23 |
|
24 |
| 14090 | Use _content_encoding and _fs_encoding, and use strict | |
25 |
| zmedico | unicode exceptions where appropriate. | |
26 |
|
27 |
| 14091 | Replace the _{content,fs,merge}_encoding attributes with an | |
28 |
| zmedico | _encodings dict. | |
29 |
|
30 |
| 14092 | Use errors='backslashreplace' instead of 'replace' for the | |
31 |
| zmedico | default _unicode_encode() argument ('replace' substitutes | |
32 |
| | '?', which is not as useful). | |
33 |
|
34 |
| 14093 | Use portage.os and _encodings['fs'] where appropriate. | |
35 |
| zmedico | | |
36 |
|
37 |
| 14094 | Use portage.os and _encodings where appropriate. | |
38 |
| zmedico | | |
39 |
|
40 |
| 14095 | Use portage.os and _encodings where appropriate. | |
41 |
| zmedico | | |
42 |
|
43 |
| 14096 | Remove unused os import. | |
44 |
| zmedico | | |
45 |
|
46 |
| 14097 | Use portage.os and _encodings where appropriate. | |
47 |
| zmedico | | |
48 |
|
49 |
|
50 |
Modified: main/branches/prefix/pym/_emerge/actions.py |
51 |
=================================================================== |
52 |
--- main/branches/prefix/pym/_emerge/actions.py 2009-08-24 09:32:56 UTC (rev 14140) |
53 |
+++ main/branches/prefix/pym/_emerge/actions.py 2009-08-24 09:34:26 UTC (rev 14141) |
54 |
@@ -2644,7 +2644,7 @@ |
55 |
|
56 |
mtimedbfile = os.path.join("/", portage.CACHE_PATH.lstrip(os.path.sep), "mtimedb") |
57 |
mtimedb = portage.MtimeDB(mtimedbfile) |
58 |
- |
59 |
+ portage.output._init(config_root=settings['PORTAGE_CONFIGROOT']) |
60 |
return settings, trees, mtimedb |
61 |
|
62 |
def chk_updated_cfg_files(target_root, config_protect): |
63 |
|
64 |
Modified: main/branches/prefix/pym/portage/__init__.py |
65 |
=================================================================== |
66 |
--- main/branches/prefix/pym/portage/__init__.py 2009-08-24 09:32:56 UTC (rev 14140) |
67 |
+++ main/branches/prefix/pym/portage/__init__.py 2009-08-24 09:34:26 UTC (rev 14141) |
68 |
@@ -119,20 +119,26 @@ |
69 |
sys.stderr.write(" "+str(e)+"\n\n") |
70 |
raise |
71 |
|
72 |
-# Assume utf_8 encoding for content of all files. |
73 |
-_content_encoding = 'utf_8' |
74 |
+# Assume utf_8 fs encoding everywhere except in merge code, where the |
75 |
+# user's locale is respected. |
76 |
+_encodings = { |
77 |
+ 'content' : 'utf_8', |
78 |
+ 'fs' : 'utf_8', |
79 |
+ 'merge' : sys.getfilesystemencoding(), |
80 |
+} |
81 |
|
82 |
-# Assume utf_8 fs encoding everywhere except in merge code. |
83 |
-_fs_encoding = 'utf_8' |
84 |
+# Deprecated attributes. Instead use _encodings directly. |
85 |
+_content_encoding = _encodings['content'] |
86 |
+_fs_encoding = _encodings['fs'] |
87 |
+_merge_encoding = _encodings['merge'] |
88 |
|
89 |
-_merge_encoding = sys.getfilesystemencoding() |
90 |
- |
91 |
-def _unicode_encode(s, encoding=_content_encoding, errors='replace'): |
92 |
+def _unicode_encode(s, encoding=_encodings['content'], |
93 |
+ errors='backslashreplace'): |
94 |
if isinstance(s, unicode): |
95 |
s = s.encode(encoding, errors) |
96 |
return s |
97 |
|
98 |
-def _unicode_decode(s, encoding=_content_encoding, errors='replace'): |
99 |
+def _unicode_decode(s, encoding=_encodings['content'], errors='replace'): |
100 |
if not isinstance(s, unicode): |
101 |
if sys.hexversion < 0x3000000: |
102 |
if isinstance(s, basestring): |
103 |
@@ -155,7 +161,7 @@ |
104 |
""" |
105 |
__slots__ = ('_func', '_encoding') |
106 |
|
107 |
- def __init__(self, func, encoding='utf_8'): |
108 |
+ def __init__(self, func, encoding=_encodings['fs']): |
109 |
self._func = func |
110 |
self._encoding = encoding |
111 |
|
112 |
@@ -201,7 +207,7 @@ |
113 |
""" |
114 |
__slots__ = ('_mod', '_encoding', '_overrides') |
115 |
|
116 |
- def __init__(self, mod, encoding='utf_8', overrides=None): |
117 |
+ def __init__(self, mod, encoding=_encodings['fs'], overrides=None): |
118 |
object.__setattr__(self, '_mod', mod) |
119 |
object.__setattr__(self, '_encoding', encoding) |
120 |
object.__setattr__(self, '_overrides', overrides) |
121 |
@@ -233,12 +239,12 @@ |
122 |
} |
123 |
|
124 |
os = _unicode_module_wrapper(_os, overrides=_os_overrides, |
125 |
- encoding=_fs_encoding) |
126 |
+ encoding=_encodings['fs']) |
127 |
_os_merge = _unicode_module_wrapper(_os, |
128 |
- encoding=_merge_encoding, overrides=_os_overrides) |
129 |
+ encoding=_encodings['merge'], overrides=_os_overrides) |
130 |
|
131 |
import shutil as _shutil |
132 |
-shutil = _unicode_module_wrapper(_shutil, encoding=_fs_encoding) |
133 |
+shutil = _unicode_module_wrapper(_shutil, encoding=_encodings['fs']) |
134 |
|
135 |
# Imports below this point rely on the above unicode wrapper definitions. |
136 |
_selinux = None |
137 |
@@ -246,8 +252,10 @@ |
138 |
_selinux_merge = None |
139 |
try: |
140 |
import portage._selinux |
141 |
- selinux = _unicode_module_wrapper(_selinux, encoding=_fs_encoding) |
142 |
- _selinux_merge = _unicode_module_wrapper(_selinux, encoding=_merge_encoding) |
143 |
+ selinux = _unicode_module_wrapper(_selinux, |
144 |
+ encoding=_encodings['fs']) |
145 |
+ _selinux_merge = _unicode_module_wrapper(_selinux, |
146 |
+ encoding=_encodings['merge']) |
147 |
except OSError, e: |
148 |
sys.stderr.write("!!! SELinux not loaded: %s\n" % str(e)) |
149 |
del e |
150 |
@@ -1007,8 +1015,9 @@ |
151 |
|
152 |
ldsoconf_path = os.path.join(target_root, EPREFIX_LSTRIP, "etc", "ld.so.conf") |
153 |
try: |
154 |
- myld = codecs.open(_unicode_encode(ldsoconf_path), mode='r', |
155 |
- encoding='utf_8', errors='replace') |
156 |
+ myld = codecs.open(_unicode_encode(ldsoconf_path, |
157 |
+ encoding=_encodings['fs'], errors='strict'), |
158 |
+ mode='r', encoding=_encodings['content'], errors='replace') |
159 |
myldlines=myld.readlines() |
160 |
myld.close() |
161 |
oldld=[] |
162 |
@@ -1189,8 +1198,9 @@ |
163 |
lines = [] |
164 |
pathname = os.path.join(base_dir, 'Makefile') |
165 |
try: |
166 |
- f = codecs.open(_unicode_encode(pathname), mode='r', |
167 |
- encoding='utf_8', errors='replace') |
168 |
+ f = codecs.open(_unicode_encode(pathname, |
169 |
+ encoding=_encodings['fs'], errors='strict'), mode='r', |
170 |
+ encoding=_encodings['content'], errors='replace') |
171 |
except OSError, details: |
172 |
return (None, str(details)) |
173 |
except IOError, details: |
174 |
@@ -1652,8 +1662,9 @@ |
175 |
parentsFile = os.path.join(currentPath, "parent") |
176 |
eapi_file = os.path.join(currentPath, "eapi") |
177 |
try: |
178 |
- eapi = codecs.open(_unicode_encode(eapi_file), |
179 |
- mode='r', encoding='utf_8', errors='replace' |
180 |
+ eapi = codecs.open(_unicode_encode(eapi_file, |
181 |
+ encoding=_encodings['fs'], errors='strict'), |
182 |
+ mode='r', encoding=_encodings['content'], errors='replace' |
183 |
).readline().strip() |
184 |
except IOError: |
185 |
pass |
186 |
@@ -2001,8 +2012,10 @@ |
187 |
try: |
188 |
repo_conf_parser.readfp( |
189 |
codecs.open( |
190 |
- _unicode_encode(self._local_repo_conf_path), mode='r', |
191 |
- encoding='utf_8', errors='replace')) |
192 |
+ _unicode_encode(self._local_repo_conf_path, |
193 |
+ encoding=_encodings['fs'], errors='strict'), |
194 |
+ mode='r', encoding=_encodings['content'], errors='replace') |
195 |
+ ) |
196 |
except EnvironmentError, e: |
197 |
if e.errno != errno.ENOENT: |
198 |
raise |
199 |
@@ -4879,8 +4892,9 @@ |
200 |
if (mystat[stat.ST_SIZE]<100000) and (len(myfile)>4) and not ((myfile[-5:]==".html") or (myfile[-4:]==".htm")): |
201 |
html404=re.compile("<title>.*(not found|404).*</title>",re.I|re.M) |
202 |
if html404.search(codecs.open( |
203 |
- _unicode_encode(myfile_path), mode='r', |
204 |
- encoding='utf_8', errors='replace' |
205 |
+ _unicode_encode(myfile_path, |
206 |
+ encoding=_encodings['fs'], errors='strict'), |
207 |
+ mode='r', encoding=_encodings['content'], errors='replace' |
208 |
).read()): |
209 |
try: |
210 |
os.unlink(mysettings["DISTDIR"]+"/"+myfile) |
211 |
@@ -5307,13 +5321,13 @@ |
212 |
for parent, dirs, files in os.walk(filesdir): |
213 |
try: |
214 |
parent = _unicode_decode(parent, |
215 |
- encoding=_fs_encoding, errors='strict') |
216 |
+ encoding=_encodings['fs'], errors='strict') |
217 |
except UnicodeDecodeError: |
218 |
parent = _unicode_decode(parent, |
219 |
- encoding=_fs_encoding, errors='replace') |
220 |
+ encoding=_encodings['fs'], errors='replace') |
221 |
writemsg(_("!!! Path contains invalid " |
222 |
"character(s) for encoding '%s': '%s'") \ |
223 |
- % (_fs_encoding, parent), noiselevel=-1) |
224 |
+ % (_encodings['fs'], parent), noiselevel=-1) |
225 |
if strict: |
226 |
return 0 |
227 |
continue |
228 |
@@ -5323,16 +5337,16 @@ |
229 |
for f in files: |
230 |
try: |
231 |
f = _unicode_decode(f, |
232 |
- encoding=_fs_encoding, errors='strict') |
233 |
+ encoding=_encodings['fs'], errors='strict') |
234 |
except UnicodeDecodeError: |
235 |
f = _unicode_decode(f, |
236 |
- encoding=_fs_encoding, errors='replace') |
237 |
+ encoding=_encodings['fs'], errors='replace') |
238 |
if f.startswith("."): |
239 |
continue |
240 |
f = os.path.join(parent, f)[len(filesdir) + 1:] |
241 |
writemsg(_("!!! File name contains invalid " |
242 |
"character(s) for encoding '%s': '%s'") \ |
243 |
- % (_fs_encoding, f), noiselevel=-1) |
244 |
+ % (_encodings['fs'], f), noiselevel=-1) |
245 |
if strict: |
246 |
return 0 |
247 |
continue |
248 |
@@ -5455,8 +5469,9 @@ |
249 |
if logfile is None: |
250 |
return |
251 |
try: |
252 |
- f = codecs.open(_unicode_encode(logfile), mode='r', |
253 |
- encoding='utf_8', errors='replace') |
254 |
+ f = codecs.open(_unicode_encode(logfile, |
255 |
+ encoding=_encodings['fs'], errors='strict'), |
256 |
+ mode='r', encoding=_encodings['content'], errors='replace') |
257 |
except EnvironmentError: |
258 |
return |
259 |
|
260 |
@@ -5603,14 +5618,14 @@ |
261 |
for parent, dirs, files in os.walk(destdir): |
262 |
try: |
263 |
parent = _unicode_decode(parent, |
264 |
- encoding=_merge_encoding, errors='strict') |
265 |
+ encoding=_encodings['merge'], errors='strict') |
266 |
except UnicodeDecodeError: |
267 |
new_parent = _unicode_decode(parent, |
268 |
- encoding=_merge_encoding, errors='replace') |
269 |
+ encoding=_encodings['merge'], errors='replace') |
270 |
new_parent = _unicode_encode(new_parent, |
271 |
- encoding=_merge_encoding, errors='backslashreplace') |
272 |
+ encoding=_encodings['merge'], errors='backslashreplace') |
273 |
new_parent = _unicode_decode(new_parent, |
274 |
- encoding=_merge_encoding, errors='replace') |
275 |
+ encoding=_encodings['merge'], errors='replace') |
276 |
os.rename(parent, new_parent) |
277 |
unicode_error = True |
278 |
unicode_errors.append(new_parent[len(destdir):]) |
279 |
@@ -5619,16 +5634,16 @@ |
280 |
for fname in chain(dirs, files): |
281 |
try: |
282 |
fname = _unicode_decode(fname, |
283 |
- encoding=_merge_encoding, errors='strict') |
284 |
+ encoding=_encodings['merge'], errors='strict') |
285 |
except UnicodeDecodeError: |
286 |
fpath = _os.path.join( |
287 |
- parent.encode(_merge_encoding), fname) |
288 |
+ parent.encode(_encodings['merge']), fname) |
289 |
new_fname = _unicode_decode(fname, |
290 |
- encoding=_merge_encoding, errors='replace') |
291 |
+ encoding=_encodings['merge'], errors='replace') |
292 |
new_fname = _unicode_encode(new_fname, |
293 |
- encoding=_merge_encoding, errors='backslashreplace') |
294 |
+ encoding=_encodings['merge'], errors='backslashreplace') |
295 |
new_fname = _unicode_decode(new_fname, |
296 |
- encoding=_merge_encoding, errors='replace') |
297 |
+ encoding=_encodings['merge'], errors='replace') |
298 |
new_fpath = os.path.join(parent, new_fname) |
299 |
os.rename(fpath, new_fpath) |
300 |
unicode_error = True |
301 |
@@ -5653,7 +5668,7 @@ |
302 |
if mystat.st_gid == portage_gid: |
303 |
mygid = inst_gid |
304 |
apply_secpass_permissions( |
305 |
- _unicode_encode(fpath, encoding=_merge_encoding), |
306 |
+ _unicode_encode(fpath, encoding=_encodings['merge']), |
307 |
uid=myuid, gid=mygid, |
308 |
mode=mystat.st_mode, stat_cached=mystat, |
309 |
follow_links=False) |
310 |
@@ -5685,7 +5700,7 @@ |
311 |
msg = _("This package installs one or more file names containing " |
312 |
"characters that do not match your current locale " |
313 |
"settings. The current setting for filesystem encoding is '%s'.") \ |
314 |
- % _merge_encoding |
315 |
+ % _encodings['merge'] |
316 |
lines.extend(wrap(msg, 72)) |
317 |
|
318 |
lines.append("") |
319 |
@@ -5693,7 +5708,7 @@ |
320 |
lines.extend("\t" + x for x in errors) |
321 |
lines.append("") |
322 |
|
323 |
- if _merge_encoding.lower().replace('_', '').replace('-', '') != 'utf8': |
324 |
+ if _encodings['merge'].lower().replace('_', '').replace('-', '') != 'utf8': |
325 |
msg = _("For best results, UTF-8 encoding is recommended. See " |
326 |
"the Gentoo Linux Localization Guide for instructions " |
327 |
"about how to configure your locale for UTF-8 encoding:") |
328 |
@@ -5934,8 +5949,9 @@ |
329 |
pass |
330 |
elif 'parse-eapi-ebuild-head' in mysettings.features: |
331 |
eapi = _parse_eapi_ebuild_head( |
332 |
- codecs.open(_unicode_encode(ebuild_path), |
333 |
- mode='r', encoding='utf_8', errors='replace')) |
334 |
+ codecs.open(_unicode_encode(ebuild_path, |
335 |
+ encoding=_encodings['fs'], errors='strict'), |
336 |
+ mode='r', encoding=_encodings['content'], errors='replace')) |
337 |
|
338 |
if eapi is not None: |
339 |
if not eapi_is_supported(eapi): |
340 |
@@ -6101,8 +6117,9 @@ |
341 |
|
342 |
if background and log_path is not None: |
343 |
try: |
344 |
- log_file = codecs.open(_unicode_encode(log_path), mode='a', |
345 |
- encoding='utf_8', errors='replace') |
346 |
+ log_file = codecs.open(_unicode_encode(log_path, |
347 |
+ encoding=_encodings['fs'], errors='strict'), |
348 |
+ mode='a', encoding=_encodings['content'], errors='replace') |
349 |
except IOError: |
350 |
def write(msg): |
351 |
pass |
352 |
@@ -7151,7 +7168,7 @@ |
353 |
"mv '%s' '%s'" % (src, dest)) |
354 |
|
355 |
def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
356 |
- hardlink_candidates=None, encoding=_fs_encoding): |
357 |
+ hardlink_candidates=None, encoding=_encodings['fs']): |
358 |
"""moves a file from src to dest, preserving all permissions and attributes; mtime will |
359 |
be preserved even when moving across filesystems. Returns true on success and false on |
360 |
failure. Move is atomic.""" |
361 |
@@ -8470,8 +8487,9 @@ |
362 |
DEPRECATED_PROFILE_FILE.lstrip(os.sep)) |
363 |
if not os.access(deprecated_profile_file, os.R_OK): |
364 |
return False |
365 |
- dcontent = codecs.open(_unicode_encode(deprecated_profile_file), |
366 |
- mode='r', encoding='utf_8', errors='replace').readlines() |
367 |
+ dcontent = codecs.open(_unicode_encode(deprecated_profile_file, |
368 |
+ encoding=_encodings['fs'], errors='strict'), |
369 |
+ mode='r', encoding=_encodings['content'], errors='replace').readlines() |
370 |
writemsg(colorize("BAD", _("\n!!! Your current profile is " |
371 |
"deprecated and not supported anymore.")) + "\n", noiselevel=-1) |
372 |
if not dcontent: |
373 |
@@ -8867,6 +8885,7 @@ |
374 |
break |
375 |
|
376 |
root = settings["ROOT"] |
377 |
+ output._init(config_root=settings['PORTAGE_CONFIGROOT']) |
378 |
|
379 |
|
380 |
# ======================================================================== |
381 |
|
382 |
Modified: main/branches/prefix/pym/portage/cvstree.py |
383 |
=================================================================== |
384 |
--- main/branches/prefix/pym/portage/cvstree.py 2009-08-24 09:32:56 UTC (rev 14140) |
385 |
+++ main/branches/prefix/pym/portage/cvstree.py 2009-08-24 09:34:26 UTC (rev 14141) |
386 |
@@ -3,9 +3,13 @@ |
387 |
# Distributed under the terms of the GNU General Public License v2 |
388 |
# $Id$ |
389 |
|
390 |
+import codecs |
391 |
+import re |
392 |
+import time |
393 |
|
394 |
-import os,time,sys,re |
395 |
-from stat import * |
396 |
+from portage import os |
397 |
+from portage import _encodings |
398 |
+from portage import _unicode_encode |
399 |
|
400 |
# [D]/Name/Version/Date/Flags/Tags |
401 |
|
402 |
@@ -43,7 +47,10 @@ |
403 |
filename=os.path.basename(path) |
404 |
|
405 |
try: |
406 |
- myfile=open(basedir+"/CVS/Entries","r") |
407 |
+ myfile = codecs.open( |
408 |
+ _unicode_encode(os.path.join(basedir, 'CVS', 'Entries'), |
409 |
+ encoding=_encodings['fs'], errors='strict'), |
410 |
+ mode='r', encoding=_encodings['content'], errors='strict') |
411 |
except IOError: |
412 |
return 0 |
413 |
mylines=myfile.readlines() |
414 |
@@ -194,7 +201,9 @@ |
415 |
if not os.path.exists(mydir): |
416 |
return entries |
417 |
try: |
418 |
- myfile=open(myfn, "r") |
419 |
+ myfile = codecs.open(_unicode_encode(myfn, |
420 |
+ encoding=_encodings['fs'], errors='strict'), |
421 |
+ mode='r', encoding=_encodings['content'], errors='strict') |
422 |
mylines=myfile.readlines() |
423 |
myfile.close() |
424 |
except SystemExit, e: |
425 |
@@ -269,7 +278,7 @@ |
426 |
if file=="digest-framerd-2.4.3": |
427 |
print "stat'ing" |
428 |
mystat=os.stat(mydir+"/"+file) |
429 |
- mytime=time.asctime(time.gmtime(mystat[ST_MTIME])) |
430 |
+ mytime = time.asctime(time.gmtime(long(mystat.st_mtime))) |
431 |
if "status" not in entries["files"][file]: |
432 |
if file=="digest-framerd-2.4.3": |
433 |
print "status not set" |
434 |
|
435 |
Modified: main/branches/prefix/pym/portage/dbapi/vartree.py |
436 |
=================================================================== |
437 |
--- main/branches/prefix/pym/portage/dbapi/vartree.py 2009-08-24 09:32:56 UTC (rev 14140) |
438 |
+++ main/branches/prefix/pym/portage/dbapi/vartree.py 2009-08-24 09:34:26 UTC (rev 14141) |
439 |
@@ -38,6 +38,7 @@ |
440 |
|
441 |
# This is a special version of the os module, wrapped for unicode support. |
442 |
from portage import os |
443 |
+from portage import _content_encoding |
444 |
from portage import _fs_encoding |
445 |
from portage import _merge_encoding |
446 |
from portage import _os_merge |
447 |
@@ -1537,7 +1538,8 @@ |
448 |
counter, = self.aux_get(cpv, aux_keys) |
449 |
except KeyError: |
450 |
continue |
451 |
- h.update(counter) |
452 |
+ h.update(_unicode_encode(counter, |
453 |
+ encoding=_content_encoding, errors='replace')) |
454 |
return h.hexdigest() |
455 |
|
456 |
def cpv_inject(self, mycpv): |
457 |
@@ -1949,8 +1951,10 @@ |
458 |
results.append(long(st.st_mtime)) |
459 |
continue |
460 |
try: |
461 |
- myf = codecs.open(_unicode_encode(os.path.join(mydir, x)), |
462 |
- mode='r', encoding='utf_8', errors='replace') |
463 |
+ myf = codecs.open( |
464 |
+ _unicode_encode(os.path.join(mydir, x), |
465 |
+ encoding=_fs_encoding, errors='strict'), |
466 |
+ mode='r', encoding=_content_encoding, errors='replace') |
467 |
try: |
468 |
myd = myf.read() |
469 |
finally: |
470 |
@@ -2018,8 +2022,10 @@ |
471 |
new_vdb = False |
472 |
counter = -1 |
473 |
try: |
474 |
- cfile = codecs.open(_unicode_encode(self._counter_path), mode='r', |
475 |
- encoding='utf_8', errors='replace') |
476 |
+ cfile = codecs.open( |
477 |
+ _unicode_encode(self._counter_path, |
478 |
+ encoding=_fs_encoding, errors='strict'), |
479 |
+ mode='r', encoding=_content_encoding, errors='replace') |
480 |
except EnvironmentError, e: |
481 |
new_vdb = not bool(self.cpv_all()) |
482 |
if not new_vdb: |
483 |
@@ -2154,7 +2160,8 @@ |
484 |
h = self._new_hash() |
485 |
# Always use a constant utf_8 encoding here, since |
486 |
# the "default" encoding can change. |
487 |
- h.update(portage._unicode_encode(s)) |
488 |
+ h.update(_unicode_encode(s, |
489 |
+ encoding=_content_encoding, errors='replace')) |
490 |
h = h.hexdigest() |
491 |
h = h[-self._hex_chars:] |
492 |
h = int(h, 16) |
493 |
@@ -2602,8 +2609,9 @@ |
494 |
return self.contentscache |
495 |
pkgfiles = {} |
496 |
try: |
497 |
- myc = codecs.open(_unicode_encode(contents_file), mode='r', |
498 |
- encoding='utf_8', errors='replace') |
499 |
+ myc = codecs.open(_unicode_encode(contents_file, |
500 |
+ encoding=_content_encoding, errors='strict'), |
501 |
+ mode='r', encoding=_content_encoding, errors='replace') |
502 |
except EnvironmentError, e: |
503 |
if e.errno != errno.ENOENT: |
504 |
raise |
505 |
@@ -3938,8 +3946,10 @@ |
506 |
for var_name in ('CHOST', 'SLOT'): |
507 |
try: |
508 |
val = codecs.open(_unicode_encode( |
509 |
- os.path.join(inforoot, var_name)), mode='r', |
510 |
- encoding='utf_8', errors='replace').readline().strip() |
511 |
+ os.path.join(inforoot, var_name), |
512 |
+ encoding=_fs_encoding, errors='strict'), |
513 |
+ mode='r', encoding=_content_encoding, errors='replace' |
514 |
+ ).readline().strip() |
515 |
except EnvironmentError, e: |
516 |
if e.errno != errno.ENOENT: |
517 |
raise |
518 |
@@ -4285,8 +4295,9 @@ |
519 |
|
520 |
# open CONTENTS file (possibly overwriting old one) for recording |
521 |
outfile = codecs.open(_unicode_encode( |
522 |
- os.path.join(self.dbtmpdir, 'CONTENTS')), |
523 |
- mode='w', encoding='utf_8', errors='replace') |
524 |
+ os.path.join(self.dbtmpdir, 'CONTENTS'), |
525 |
+ encoding=_fs_encoding, errors='strict'), |
526 |
+ mode='w', encoding=_content_encoding, errors='replace') |
527 |
|
528 |
self.updateprotect() |
529 |
|
530 |
@@ -4884,8 +4895,11 @@ |
531 |
"returns contents of a file with whitespace converted to spaces" |
532 |
if not os.path.exists(self.dbdir+"/"+name): |
533 |
return "" |
534 |
- mydata = codecs.open(_unicode_encode(os.path.join(self.dbdir, name)), |
535 |
- mode='r', encoding='utf_8', errors='replace').read().split() |
536 |
+ mydata = codecs.open( |
537 |
+ _unicode_encode(os.path.join(self.dbdir, name), |
538 |
+ encoding=_fs_encoding, errors='strict'), |
539 |
+ mode='r', encoding=_content_encoding, errors='replace' |
540 |
+ ).read().split() |
541 |
return " ".join(mydata) |
542 |
|
543 |
def copyfile(self,fname): |
544 |
@@ -4894,8 +4908,9 @@ |
545 |
def getfile(self,fname): |
546 |
if not os.path.exists(self.dbdir+"/"+fname): |
547 |
return "" |
548 |
- return codecs.open(_unicode_encode(os.path.join(self.dbdir, fname)), |
549 |
- mode='r', encoding='utf_8', errors='replace').read() |
550 |
+ return codecs.open(_unicode_encode(os.path.join(self.dbdir, fname), |
551 |
+ encoding=_fs_encoding, errors='strict'), |
552 |
+ mode='r', encoding=_content_encoding, errors='replace').read() |
553 |
|
554 |
def setfile(self,fname,data): |
555 |
mode = 'w' |
556 |
@@ -4907,8 +4922,9 @@ |
557 |
if not os.path.exists(self.dbdir+"/"+ename): |
558 |
return [] |
559 |
mylines = codecs.open(_unicode_encode( |
560 |
- os.path.join(self.dbdir, ename)), mode='r', |
561 |
- encoding='utf_8', errors='replace').readlines() |
562 |
+ os.path.join(self.dbdir, ename), |
563 |
+ encoding=_fs_encoding, errors='strict'), |
564 |
+ mode='r', encoding=_content_encoding, errors='replace').readlines() |
565 |
myreturn = [] |
566 |
for x in mylines: |
567 |
for y in x[:-1].split(): |
568 |
@@ -4917,8 +4933,9 @@ |
569 |
|
570 |
def setelements(self,mylist,ename): |
571 |
myelement = codecs.open(_unicode_encode( |
572 |
- os.path.join(self.dbdir, ename)), mode='w', |
573 |
- encoding='utf_8', errors='replace') |
574 |
+ os.path.join(self.dbdir, ename), |
575 |
+ encoding=_fs_encoding, errors='strict'), mode='w', |
576 |
+ encoding=_content_encoding, errors='replace') |
577 |
for x in mylist: |
578 |
myelement.write(x+"\n") |
579 |
myelement.close() |
580 |
|
581 |
Modified: main/branches/prefix/pym/portage/getbinpkg.py |
582 |
=================================================================== |
583 |
--- main/branches/prefix/pym/portage/getbinpkg.py 2009-08-24 09:32:56 UTC (rev 14140) |
584 |
+++ main/branches/prefix/pym/portage/getbinpkg.py 2009-08-24 09:34:26 UTC (rev 14141) |
585 |
@@ -7,9 +7,12 @@ |
586 |
from portage.cache.mappings import slot_dict_class |
587 |
from portage.localization import _ |
588 |
import portage |
589 |
+from portage import os |
590 |
+from portage import _encodings |
591 |
+from portage import _unicode_encode |
592 |
+ |
593 |
import HTMLParser |
594 |
import sys |
595 |
-import os |
596 |
import socket |
597 |
import time |
598 |
import tempfile |
599 |
@@ -487,7 +490,8 @@ |
600 |
|
601 |
out = sys.stdout |
602 |
try: |
603 |
- metadatafile = open(metadatafilename, 'rb') |
604 |
+ metadatafile = open(_unicode_encode(metadatafilename, |
605 |
+ encoding=_encodings['fs'], errors='strict'), 'rb') |
606 |
mypickle = pickle.Unpickler(metadatafile) |
607 |
try: |
608 |
mypickle.find_global = None |
609 |
@@ -582,7 +586,8 @@ |
610 |
sys.stderr.write("!!! "+str(e)+"\n") |
611 |
sys.stderr.flush() |
612 |
try: |
613 |
- metadatafile = open(metadatafilename, 'wb') |
614 |
+ metadatafile = open(_unicode_encode(metadatafilename, |
615 |
+ encoding=_encodings['fs'], errors='strict'), 'wb') |
616 |
pickle.dump(metadata, metadatafile, protocol=2) |
617 |
metadatafile.close() |
618 |
except SystemExit, e: |
619 |
@@ -674,11 +679,13 @@ |
620 |
try: |
621 |
if "modified" in metadata[baseurl] and metadata[baseurl]["modified"]: |
622 |
metadata[baseurl]["timestamp"] = int(time.time()) |
623 |
- metadatafile = open(metadatafilename, 'wb') |
624 |
+ metadatafile = open(_unicode_encode(metadatafilename, |
625 |
+ encoding=_encodings['fs'], errors='strict'), 'wb') |
626 |
pickle.dump(metadata, metadatafile, protocol=2) |
627 |
metadatafile.close() |
628 |
if makepickle: |
629 |
- metadatafile = open(makepickle, 'wb') |
630 |
+ metadatafile = open(_unicode_encode(makepickle, |
631 |
+ encoding=_encodings['fs'], errors='strict'), 'wb') |
632 |
pickle.dump(metadata[baseurl]["data"], metadatafile, protocol=2) |
633 |
metadatafile.close() |
634 |
except SystemExit, e: |
635 |
|
636 |
Modified: main/branches/prefix/pym/portage/glsa.py |
637 |
=================================================================== |
638 |
--- main/branches/prefix/pym/portage/glsa.py 2009-08-24 09:32:56 UTC (rev 14140) |
639 |
+++ main/branches/prefix/pym/portage/glsa.py 2009-08-24 09:34:26 UTC (rev 14141) |
640 |
@@ -2,12 +2,16 @@ |
641 |
# Distributed under the terms of the GNU General Public License v2 |
642 |
# $Id$ |
643 |
|
644 |
-import os |
645 |
+import codecs |
646 |
import sys |
647 |
import urllib |
648 |
import re |
649 |
import xml.dom.minidom |
650 |
|
651 |
+from portage import os |
652 |
+from portage import _encodings |
653 |
+from portage import _unicode_decode |
654 |
+from portage import _unicode_encode |
655 |
from portage.versions import pkgsplit, catpkgsplit, pkgcmp, best |
656 |
from portage.util import grabfile |
657 |
from portage.const import CACHE_PATH |
658 |
@@ -435,6 +439,8 @@ |
659 |
@type portdbapi: portage.dbapi.porttree.portdbapi |
660 |
@param portdbapi: ebuild repository |
661 |
""" |
662 |
+ myid = _unicode_decode(myid, |
663 |
+ encoding=_encodings['content'], errors='strict') |
664 |
if re.match(r'\d{6}-\d{2}', myid): |
665 |
self.type = "id" |
666 |
elif os.path.exists(myid): |
667 |
@@ -647,7 +653,11 @@ |
668 |
@returns: None |
669 |
""" |
670 |
if not self.isApplied(): |
671 |
- checkfile = open(os.path.join(os.sep, self.config["ROOT"], CACHE_PATH.lstrip(os.sep), "glsa"), "a+") |
672 |
+ checkfile = codecs.open( |
673 |
+ _unicode_encode(os.path.join(os.sep, self.config["ROOT"], |
674 |
+ CACHE_PATH.lstrip(os.sep), "glsa"), |
675 |
+ encoding=_encodings['fs'], errors='strict'), |
676 |
+ mode='a+', encoding=_encodings['content'], errors='strict') |
677 |
checkfile.write(self.nr+"\n") |
678 |
checkfile.close() |
679 |
return None |
680 |
|
681 |
Modified: main/branches/prefix/pym/portage/mail.py |
682 |
=================================================================== |
683 |
--- main/branches/prefix/pym/portage/mail.py 2009-08-24 09:32:56 UTC (rev 14140) |
684 |
+++ main/branches/prefix/pym/portage/mail.py 2009-08-24 09:34:26 UTC (rev 14141) |
685 |
@@ -3,24 +3,32 @@ |
686 |
# Distributed under the terms of the GNU General Public License v2 |
687 |
# $Id$ |
688 |
|
689 |
-import portage.exception, socket, smtplib, os, sys, time |
690 |
from email.MIMEText import MIMEText as TextMessage |
691 |
from email.MIMEMultipart import MIMEMultipart as MultipartMessage |
692 |
from email.MIMEBase import MIMEBase as BaseMessage |
693 |
from email.header import Header |
694 |
+import smtplib |
695 |
+import socket |
696 |
+import sys |
697 |
+import time |
698 |
+ |
699 |
+from portage import os |
700 |
+from portage import _content_encoding |
701 |
+from portage import _unicode_encode |
702 |
from portage.localization import _ |
703 |
+import portage |
704 |
|
705 |
def create_message(sender, recipient, subject, body, attachments=None): |
706 |
|
707 |
if sys.hexversion < 0x3000000: |
708 |
- if isinstance(sender, unicode): |
709 |
- sender = sender.encode('utf_8', 'replace') |
710 |
- if isinstance(recipient, unicode): |
711 |
- recipient = recipient.encode('utf_8', 'replace') |
712 |
- if isinstance(subject, unicode): |
713 |
- subject = subject.encode('utf_8', 'replace') |
714 |
- if isinstance(body, unicode): |
715 |
- body = body.encode('utf_8', 'replace') |
716 |
+ sender = _unicode_encode(sender, |
717 |
+ encoding=_content_encoding, errors='strict') |
718 |
+ recipient = _unicode_encode(recipient, |
719 |
+ encoding=_content_encoding, errors='strict') |
720 |
+ subject = _unicode_encode(subject, |
721 |
+ encoding=_content_encoding, errors='replace') |
722 |
+ body = _unicode_encode(body, |
723 |
+ encoding=_content_encoding, errors='replace') |
724 |
|
725 |
if attachments == None: |
726 |
mymessage = TextMessage(body) |
727 |
@@ -31,8 +39,9 @@ |
728 |
if isinstance(x, BaseMessage): |
729 |
mymessage.attach(x) |
730 |
elif isinstance(x, basestring): |
731 |
- if sys.hexversion < 0x3000000 and isinstance(x, unicode): |
732 |
- x = x.encode('utf_8', 'replace') |
733 |
+ if sys.hexversion < 0x3000000: |
734 |
+ x = _unicode_encode(x, |
735 |
+ encoding=_content_encoding, errors='replace') |
736 |
mymessage.attach(TextMessage(x)) |
737 |
else: |
738 |
raise portage.exception.PortageException(_("Can't handle type of attachment: %s") % type(x)) |
739 |
@@ -82,18 +91,18 @@ |
740 |
myfrom = message.get("From") |
741 |
|
742 |
if sys.hexversion < 0x3000000: |
743 |
- if isinstance(myrecipient, unicode): |
744 |
- myrecipient = myrecipient.encode('utf_8', 'replace') |
745 |
- if isinstance(mymailhost, unicode): |
746 |
- mymailhost = mymailhost.encode('utf_8', 'replace') |
747 |
- if isinstance(mymailport, unicode): |
748 |
- mymailport = mymailport.encode('utf_8', 'replace') |
749 |
- if isinstance(myfrom, unicode): |
750 |
- myfrom = myfrom.encode('utf_8', 'replace') |
751 |
- if isinstance(mymailuser, unicode): |
752 |
- mymailuser = mymailuser.encode('utf_8', 'replace') |
753 |
- if isinstance(mymailpasswd, unicode): |
754 |
- mymailpasswd = mymailpasswd.encode('utf_8', 'replace') |
755 |
+ myrecipient = _unicode_encode(myrecipient, |
756 |
+ encoding=_content_encoding, errors='strict') |
757 |
+ mymailhost = _unicode_encode(mymailhost, |
758 |
+ encoding=_content_encoding, errors='strict') |
759 |
+ mymailport = _unicode_encode(mymailport, |
760 |
+ encoding=_content_encoding, errors='strict') |
761 |
+ myfrom = _unicode_encode(myfrom, |
762 |
+ encoding=_content_encoding, errors='strict') |
763 |
+ mymailuser = _unicode_encode(mymailuser, |
764 |
+ encoding=_content_encoding, errors='strict') |
765 |
+ mymailpasswd = _unicode_encode(mymailpasswd, |
766 |
+ encoding=_content_encoding, errors='strict') |
767 |
|
768 |
# user wants to use a sendmail binary instead of smtp |
769 |
if mymailhost[0] == os.sep and os.path.exists(mymailhost): |
770 |
|
771 |
Modified: main/branches/prefix/pym/repoman/checks.py |
772 |
=================================================================== |
773 |
--- main/branches/prefix/pym/repoman/checks.py 2009-08-24 09:32:56 UTC (rev 14140) |
774 |
+++ main/branches/prefix/pym/repoman/checks.py 2009-08-24 09:34:26 UTC (rev 14141) |
775 |
@@ -6,7 +6,6 @@ |
776 |
"""This module contains functions used in Repoman to ascertain the quality |
777 |
and correctness of an ebuild.""" |
778 |
|
779 |
-import os |
780 |
import re |
781 |
import time |
782 |
import repoman.errors as errors |
783 |
|
784 |
Modified: main/branches/prefix/pym/repoman/utilities.py |
785 |
=================================================================== |
786 |
--- main/branches/prefix/pym/repoman/utilities.py 2009-08-24 09:32:56 UTC (rev 14140) |
787 |
+++ main/branches/prefix/pym/repoman/utilities.py 2009-08-24 09:34:26 UTC (rev 14141) |
788 |
@@ -18,16 +18,19 @@ |
789 |
"parse_metadata_use" |
790 |
] |
791 |
|
792 |
+import codecs |
793 |
import commands |
794 |
import errno |
795 |
import itertools |
796 |
import logging |
797 |
-import os |
798 |
import sys |
799 |
|
800 |
from xml.dom import minidom |
801 |
from xml.dom import NotFoundErr |
802 |
from xml.parsers.expat import ExpatError |
803 |
+from portage import os |
804 |
+from portage import _encodings |
805 |
+from portage import _unicode_encode |
806 |
from portage import output |
807 |
from portage.output import red, green |
808 |
from portage.process import find_binary |
809 |
@@ -282,7 +285,10 @@ |
810 |
if not (os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == os.EX_OK): |
811 |
return None |
812 |
try: |
813 |
- mylines = open(filename).readlines() |
814 |
+ mylines = codecs.open(_unicode_encode(filename, |
815 |
+ encoding=_encodings['fs'], errors='strict'), |
816 |
+ mode='r', encoding=_encodings['content'], errors='replace' |
817 |
+ ).readlines() |
818 |
except OSError, e: |
819 |
if e.errno != errno.ENOENT: |
820 |
raise |