1 |
commit: a01ac6b7baef29a30cabb08ea619c9c0948df4d6 |
2 |
Author: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org> |
3 |
AuthorDate: Thu Jan 2 22:52:29 2014 +0000 |
4 |
Commit: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org> |
5 |
CommitDate: Thu Jan 2 22:52:29 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=a01ac6b7 |
7 |
|
8 |
portage.exception.PortageException: Improve performance (at least with Python 3). |
9 |
|
10 |
--- |
11 |
pym/portage/exception.py | 45 +++++++++++++++++++++++++++------------------ |
12 |
1 file changed, 27 insertions(+), 18 deletions(-) |
13 |
|
14 |
diff --git a/pym/portage/exception.py b/pym/portage/exception.py |
15 |
index 5ccd750..1388c49 100644 |
16 |
--- a/pym/portage/exception.py |
17 |
+++ b/pym/portage/exception.py |
18 |
@@ -1,4 +1,4 @@ |
19 |
-# Copyright 1998-2011 Gentoo Foundation |
20 |
+# Copyright 1998-2014 Gentoo Foundation |
21 |
# Distributed under the terms of the GNU General Public License v2 |
22 |
|
23 |
import signal |
24 |
@@ -11,26 +11,35 @@ if sys.hexversion >= 0x3000000: |
25 |
|
26 |
class PortageException(Exception): |
27 |
"""General superclass for portage exceptions""" |
28 |
- def __init__(self,value): |
29 |
- self.value = value[:] |
30 |
- if isinstance(self.value, basestring): |
31 |
- self.value = _unicode_decode(self.value, |
32 |
- encoding=_encodings['content'], errors='replace') |
33 |
+ if sys.hexversion >= 0x3000000: |
34 |
+ def __init__(self,value): |
35 |
+ self.value = value[:] |
36 |
|
37 |
- def __str__(self): |
38 |
- if isinstance(self.value, basestring): |
39 |
- return self.value |
40 |
- else: |
41 |
- return _unicode_decode(repr(self.value), |
42 |
- encoding=_encodings['content'], errors='replace') |
43 |
- |
44 |
- if sys.hexversion < 0x3000000: |
45 |
- |
46 |
- __unicode__ = __str__ |
47 |
+ def __str__(self): |
48 |
+ if isinstance(self.value, str): |
49 |
+ return self.value |
50 |
+ else: |
51 |
+ return repr(self.value) |
52 |
+ else: |
53 |
+ def __init__(self,value): |
54 |
+ self.value = value[:] |
55 |
+ if isinstance(self.value, basestring): |
56 |
+ self.value = _unicode_decode(self.value, |
57 |
+ encoding=_encodings['content'], errors='replace') |
58 |
+ |
59 |
+ def __unicode__(self): |
60 |
+ if isinstance(self.value, unicode): |
61 |
+ return self.value |
62 |
+ else: |
63 |
+ return _unicode_decode(repr(self.value), |
64 |
+ encoding=_encodings['content'], errors='replace') |
65 |
|
66 |
def __str__(self): |
67 |
- return _unicode_encode(self.__unicode__(), |
68 |
- encoding=_encodings['content'], errors='backslashreplace') |
69 |
+ if isinstance(self.value, unicode): |
70 |
+ return _unicode_encode(self.value, |
71 |
+ encoding=_encodings['content'], errors='backslashreplace') |
72 |
+ else: |
73 |
+ return repr(self.value) |
74 |
|
75 |
class CorruptionError(PortageException): |
76 |
"""Corruption indication""" |