Define __bool__() for compatibility with Python 3.
authorArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>
Fri, 25 Sep 2009 06:34:34 +0000 (06:34 -0000)
committerArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>
Fri, 25 Sep 2009 06:34:34 +0000 (06:34 -0000)
svn path=/main/trunk/; revision=14427

pym/_emerge/SequentialTaskQueue.py
pym/portage/dep.py
pym/portage/proxy/objectproxy.py
pym/portage/sets/base.py

index 7dcc6e516750259e895ac7784fdd506c915352ef..4909290c06a69a58af3fb51367778b08ff9f0c6c 100644 (file)
@@ -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)
-
index 98448d9593f76bc59019d3dec5afe0ff0d8cdde0..1fe4bc905fba7e73b1fd03dde43516b2020168e5 100644 (file)
@@ -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 ""
index 6dffff7d5ed57434b297eae91d1943eedcbf8dd1..dff4a07f75350ad842c7a0101b6489e91294b3e8 100644 (file)
@@ -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')())
index d58b5f297be960cfca6c1c0a76d685f1a7d76be5..216c8cc1653f7f05944ca2c20cfc5fa1c9f01217 100644 (file)
@@ -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)