From: Arfrever Frehtes Taifersar Arahesis Date: Fri, 25 Sep 2009 06:34:34 +0000 (-0000) Subject: Define __bool__() for compatibility with Python 3. X-Git-Tag: v2.2_rc42~6 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8f7d6cd85e68af46648ff93bf846ba95abf7dcee;p=portage.git Define __bool__() for compatibility with Python 3. svn path=/main/trunk/; revision=14427 --- diff --git a/pym/_emerge/SequentialTaskQueue.py b/pym/_emerge/SequentialTaskQueue.py index 7dcc6e516..4909290c0 100644 --- a/pym/_emerge/SequentialTaskQueue.py +++ b/pym/_emerge/SequentialTaskQueue.py @@ -2,6 +2,7 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ +import sys from _emerge.SlotObject import SlotObject from collections import deque class SequentialTaskQueue(SlotObject): @@ -79,9 +80,11 @@ class SequentialTaskQueue(SlotObject): task.cancel() self._dirty = False - def __nonzero__(self): + def __bool__(self): return bool(self._task_queue or self.running_tasks) + if sys.hexversion < 0x3000000: + __nonzero__ = __bool__ + def __len__(self): return len(self._task_queue) + len(self.running_tasks) - diff --git a/pym/portage/dep.py b/pym/portage/dep.py index 98448d959..1fe4bc905 100644 --- a/pym/portage/dep.py +++ b/pym/portage/dep.py @@ -412,9 +412,12 @@ class _use_dep(object): raise InvalidAtom(_("Invalid use dep: '%s'") % (token,)) return flag - def __nonzero__(self): + def __bool__(self): return bool(self.tokens) + if sys.hexversion < 0x3000000: + __nonzero__ = __bool__ + def __str__(self): if not self.tokens: return "" diff --git a/pym/portage/proxy/objectproxy.py b/pym/portage/proxy/objectproxy.py index 6dffff7d5..dff4a07f7 100644 --- a/pym/portage/proxy/objectproxy.py +++ b/pym/portage/proxy/objectproxy.py @@ -2,6 +2,8 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ +import sys + __all__ = ['ObjectProxy'] class ObjectProxy(object): @@ -70,8 +72,11 @@ class ObjectProxy(object): def __ne__(self, other): return object.__getattribute__(self, '_get_target')() != other - def __nonzero__(self): + def __bool__(self): return bool(object.__getattribute__(self, '_get_target')()) + if sys.hexversion < 0x3000000: + __nonzero__ = __bool__ + def __int__(self): return int(object.__getattribute__(self, '_get_target')()) diff --git a/pym/portage/sets/base.py b/pym/portage/sets/base.py index d58b5f297..216c8cc16 100644 --- a/pym/portage/sets/base.py +++ b/pym/portage/sets/base.py @@ -41,10 +41,13 @@ class PackageSet(object): for x in self._nonatoms: yield x - def __nonzero__(self): + def __bool__(self): self._load() return bool(self._atoms or self._nonatoms) + if sys.hexversion < 0x3000000: + __nonzero__ = __bool__ + def supportsOperation(self, op): if not op in OPERATIONS: raise ValueError(op)