aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pym/portage/exception.py')
-rw-r--r--pym/portage/exception.py54
1 files changed, 32 insertions, 22 deletions
diff --git a/pym/portage/exception.py b/pym/portage/exception.py
index 5ccd750ab..6fa5447a7 100644
--- a/pym/portage/exception.py
+++ b/pym/portage/exception.py
@@ -1,4 +1,4 @@
-# Copyright 1998-2011 Gentoo Foundation
+# Copyright 1998-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import signal
@@ -7,30 +7,40 @@ from portage import _encodings, _unicode_encode, _unicode_decode
from portage.localization import _
if sys.hexversion >= 0x3000000:
+ # pylint: disable=W0622
basestring = str
class PortageException(Exception):
"""General superclass for portage exceptions"""
- def __init__(self,value):
- self.value = value[:]
- if isinstance(self.value, basestring):
- self.value = _unicode_decode(self.value,
- encoding=_encodings['content'], errors='replace')
+ if sys.hexversion >= 0x3000000:
+ def __init__(self, value):
+ self.value = value[:]
- def __str__(self):
- if isinstance(self.value, basestring):
- return self.value
- else:
- return _unicode_decode(repr(self.value),
- encoding=_encodings['content'], errors='replace')
-
- if sys.hexversion < 0x3000000:
-
- __unicode__ = __str__
+ def __str__(self):
+ if isinstance(self.value, str):
+ return self.value
+ else:
+ return repr(self.value)
+ else:
+ def __init__(self, value):
+ self.value = value[:]
+ if isinstance(self.value, basestring):
+ self.value = _unicode_decode(self.value,
+ encoding=_encodings['content'], errors='replace')
+
+ def __unicode__(self):
+ if isinstance(self.value, unicode):
+ return self.value
+ else:
+ return _unicode_decode(repr(self.value),
+ encoding=_encodings['content'], errors='replace')
def __str__(self):
- return _unicode_encode(self.__unicode__(),
- encoding=_encodings['content'], errors='backslashreplace')
+ if isinstance(self.value, unicode):
+ return _unicode_encode(self.value,
+ encoding=_encodings['content'], errors='backslashreplace')
+ else:
+ return repr(self.value)
class CorruptionError(PortageException):
"""Corruption indication"""
@@ -75,20 +85,20 @@ class DirectoryNotFound(InvalidLocation):
"""A directory was not found when it was expected to exist"""
class OperationNotPermitted(PortageException):
- from errno import EPERM as errno
"""An operation was not permitted operating system"""
+ from errno import EPERM as errno
class OperationNotSupported(PortageException):
- from errno import EOPNOTSUPP as errno
"""Operation not supported"""
+ from errno import EOPNOTSUPP as errno
class PermissionDenied(PortageException):
- from errno import EACCES as errno
"""Permission denied"""
+ from errno import EACCES as errno
class TryAgain(PortageException):
- from errno import EAGAIN as errno
"""Try again"""
+ from errno import EAGAIN as errno
class TimeoutException(PortageException):
"""Operation timed out"""