From: Zac Medico Date: Mon, 17 Aug 2009 00:25:58 +0000 (-0000) Subject: When _unicode_func_wrapper() decodes a string in a returned list (typically X-Git-Tag: v2.2_rc39~49 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9b102ea58429d8ef28214f890b07bca735c14e68;p=portage.git 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 --- 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