summaryrefslogtreecommitdiffstats
path: root/pym/portage/exception.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-09-15 20:01:21 -0700
committerZac Medico <zmedico@gentoo.org>2010-09-15 20:01:21 -0700
commitaadbaae1c3cd3c2166df593d984923dc491893b2 (patch)
tree06461942249564766ab3900dd47e06cdc06050ed /pym/portage/exception.py
parentcc440f13b4a26e5ec454e2ef8f9861af897ffba4 (diff)
downloadportage-aadbaae1c3cd3c2166df593d984923dc491893b2.tar.gz
portage-aadbaae1c3cd3c2166df593d984923dc491893b2.tar.bz2
portage-aadbaae1c3cd3c2166df593d984923dc491893b2.zip
Make PortageException __str__ and __unicode__ methods more like
DependencyArg, and add tests.
Diffstat (limited to 'pym/portage/exception.py')
-rw-r--r--pym/portage/exception.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/pym/portage/exception.py b/pym/portage/exception.py
index 6fa975ae6..e9e61e2ac 100644
--- a/pym/portage/exception.py
+++ b/pym/portage/exception.py
@@ -3,7 +3,7 @@
import signal
import sys
-from portage import _unicode_encode, _unicode_decode
+from portage import _encodings, _unicode_encode, _unicode_decode
from portage.localization import _
if sys.hexversion >= 0x3000000:
@@ -13,19 +13,24 @@ class PortageException(Exception):
"""General superclass for portage exceptions"""
def __init__(self,value):
self.value = value[:]
- if sys.hexversion < 0x3000000 and isinstance(self.value, unicode):
- # Workaround for string formatting operator and unicode value
- # attribute triggering empty output in formatted string.
- self.value = _unicode_encode(self.value)
+ if isinstance(self.value, basestring):
+ self.value = _unicode_decode(self.value,
+ encoding=_encodings['content'], errors='replace')
+
def __str__(self):
if isinstance(self.value, basestring):
return self.value
else:
- return repr(self.value)
+ return _unicode_decode(repr(self.value),
+ encoding=_encodings['content'], errors='replace')
if sys.hexversion < 0x3000000:
- def __unicode__(self):
- return _unicode_decode(self.__str__())
+
+ __unicode__ = __str__
+
+ def __str__(self):
+ return _unicode_encode(self.__unicode__(),
+ encoding=_encodings['content'], errors='backslashreplace')
class CorruptionError(PortageException):
"""Corruption indication"""