summaryrefslogtreecommitdiffstats
path: root/pym/portage/env
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-17 00:15:11 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-17 00:15:11 +0000
commitcb0f273297db79c47d38df235bcf18378126e9eb (patch)
tree4c97c131a8bf370145f504f9d6148076bda324c1 /pym/portage/env
parent95b6068670e0248feb5bf86593f840ae81a4c757 (diff)
downloadportage-cb0f273297db79c47d38df235bcf18378126e9eb.tar.gz
portage-cb0f273297db79c47d38df235bcf18378126e9eb.tar.bz2
portage-cb0f273297db79c47d38df235bcf18378126e9eb.zip
Use _content_encoding and _fs_encoding for unicode encoding/decoding.
svn path=/main/trunk/; revision=14072
Diffstat (limited to 'pym/portage/env')
-rw-r--r--pym/portage/env/loaders.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/pym/portage/env/loaders.py b/pym/portage/env/loaders.py
index 854304125..e878ba449 100644
--- a/pym/portage/env/loaders.py
+++ b/pym/portage/env/loaders.py
@@ -4,8 +4,13 @@
# $Id$
import codecs
-import os
+import errno
import stat
+from portage import os
+from portage import _content_encoding
+from portage import _fs_encoding
+from portage import _unicode_decode
+from portage import _unicode_encode
from portage.localization import _
class LoaderError(Exception):
@@ -40,11 +45,6 @@ def RecursiveFileLoader(filename):
@returns: List of files to process
"""
- if isinstance(filename, unicode):
- # Avoid UnicodeDecodeError raised from
- # os.path.join when called by os.walk.
- filename = filename.encode('utf_8', 'replace')
-
try:
st = os.stat(filename)
except OSError:
@@ -55,6 +55,11 @@ def RecursiveFileLoader(filename):
if d[:1] == '.' or d == 'CVS':
dirs.remove(d)
for f in files:
+ try:
+ f = _unicode_decode(f,
+ encoding=_fs_encoding, errors='strict')
+ except UnicodeDecodeError:
+ continue
if f[:1] == '.' or f[-1:] == '~':
continue
yield os.path.join(root, f)
@@ -145,9 +150,18 @@ class FileLoader(DataLoader):
# once, which may be expensive due to digging in child classes.
func = self.lineParser
for fn in RecursiveFileLoader(self.fname):
- f = codecs.open(fn, mode='r', encoding='utf_8', errors='replace')
+ try:
+ f = codecs.open(_unicode_encode(fn,
+ encoding=_fs_encoding, errors='strict'), mode='r',
+ encoding=_content_encoding, errors='replace')
+ except EnvironmentError, e:
+ if e.errno not in (errno.ENOENT, errno.ESTALE):
+ raise
+ del e
+ continue
for line_num, line in enumerate(f):
func(line, line_num, data, errors)
+ f.close()
return (data, errors)
def lineParser(self, line, line_num, data, errors):