From d92e72f25bd2a3fbf60724439d34d1c91fcc6c7d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 17 Aug 2009 23:06:52 +0000 Subject: Enable error='strict' when encoding arguments inside _unicode_func_wrapper(), and document behavior. svn path=/main/trunk/; revision=14079 --- pym/portage/__init__.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'pym') diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 0ecb6085a..e097f02af 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -144,7 +144,13 @@ def _unicode_decode(s, encoding=_content_encoding, errors='replace'): class _unicode_func_wrapper(object): """ Wraps a function, converts arguments from unicode to bytes, - and return values to unicode from bytes. + and return values to unicode from bytes. Function calls + will raise UnicodeEncodeError if an argument fails to be + encoded with the required encoding. Return values that + are single strings are decoded with errors='replace'. Return + values that are lists of strings are decoded with errors='strict' + and elements that fail to be decoded are omitted from the returned + list. """ __slots__ = ('_func', '_encoding') @@ -155,10 +161,12 @@ class _unicode_func_wrapper(object): def __call__(self, *args, **kwargs): encoding = self._encoding - wrapped_args = [_unicode_encode(x) for x in args] + wrapped_args = [_unicode_encode(x, encoding=encoding, errors='strict') + for x in args] if kwargs: - wrapped_kwargs = dict((_unicode_encode(k, encoding=encoding), - _unicode_encode(v, encoding=encoding)) \ + wrapped_kwargs = dict( + (_unicode_encode(k, encoding=encoding, errors='strict'), + _unicode_encode(v, encoding=encoding, errors='strict')) for k, v in kwargs.iteritems()) else: wrapped_kwargs = {} @@ -167,7 +175,8 @@ class _unicode_func_wrapper(object): if isinstance(rval, (basestring, list, tuple)): if isinstance(rval, basestring): - rval = _unicode_decode(rval, encoding=encoding) + rval = _unicode_decode(rval, + encoding=encoding, errors='replace') else: decoded_rval = [] for x in rval: -- cgit v1.2.3-1-g7c22