From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 8AEB0138247 for ; Thu, 2 Jan 2014 22:54:00 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E26A7E09AD; Thu, 2 Jan 2014 22:53:58 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6CC06E09AD for ; Thu, 2 Jan 2014 22:53:58 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6872333F5A4 for ; Thu, 2 Jan 2014 22:53:57 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id DFDB1E54AB for ; Thu, 2 Jan 2014 22:53:55 +0000 (UTC) From: "Arfrever Frehtes Taifersar Arahesis" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arfrever Frehtes Taifersar Arahesis" Message-ID: <1388703149.a01ac6b7baef29a30cabb08ea619c9c0948df4d6.arfrever@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/exception.py X-VCS-Directories: pym/portage/ X-VCS-Committer: arfrever X-VCS-Committer-Name: Arfrever Frehtes Taifersar Arahesis X-VCS-Revision: a01ac6b7baef29a30cabb08ea619c9c0948df4d6 X-VCS-Branch: master Date: Thu, 2 Jan 2014 22:53:55 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: d3f2620c-e0f9-45f6-a119-90f84ec2c3f7 X-Archives-Hash: 5dd6d76d71d74423cef486dae300929a commit: a01ac6b7baef29a30cabb08ea619c9c0948df4d6 Author: Arfrever Frehtes Taifersar Arahesis Apache Org> AuthorDate: Thu Jan 2 22:52:29 2014 +0000 Commit: Arfrever Frehtes Taifersar Arahesis Apache Org> CommitDate: Thu Jan 2 22:52:29 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=a01ac6b7 portage.exception.PortageException: Improve performance (at least with Python 3). --- pym/portage/exception.py | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/pym/portage/exception.py b/pym/portage/exception.py index 5ccd750..1388c49 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 @@ -11,26 +11,35 @@ if sys.hexversion >= 0x3000000: 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"""