summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-17 00:25:58 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-17 00:25:58 +0000
commit9b102ea58429d8ef28214f890b07bca735c14e68 (patch)
treef27f8ca744275c67aa83718fc62160dbf84beedd
parentcb0f273297db79c47d38df235bcf18378126e9eb (diff)
downloadportage-9b102ea58429d8ef28214f890b07bca735c14e68.tar.gz
portage-9b102ea58429d8ef28214f890b07bca735c14e68.tar.bz2
portage-9b102ea58429d8ef28214f890b07bca735c14e68.zip
When _unicode_func_wrapper() decodes a string in a returned list (typically
from os.listdir), discard values with invalid encoding. This insures that all names returned from all os.listdir() calls are valid. svn path=/main/trunk/; revision=14073
-rw-r--r--pym/portage/__init__.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 4815cc074..0ecb6085a 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -168,11 +168,20 @@ class _unicode_func_wrapper(object):
if isinstance(rval, (basestring, list, tuple)):
if isinstance(rval, basestring):
rval = _unicode_decode(rval, encoding=encoding)
- elif isinstance(rval, list):
- rval = [_unicode_decode(x, encoding=encoding) for x in rval]
- elif isinstance(rval, tuple):
- rval = tuple(_unicode_decode(x, encoding=encoding) \
- for x in rval)
+ else:
+ decoded_rval = []
+ for x in rval:
+ try:
+ x = _unicode_decode(x, encoding=encoding, errors='strict')
+ except UnicodeDecodeError:
+ pass
+ else:
+ decoded_rval.append(x)
+
+ if isinstance(rval, tuple):
+ rval = tuple(decoded_rval)
+ else:
+ rval = decoded_rval
return rval