diff options
author | Arfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org> | 2009-09-25 06:34:34 +0000 |
---|---|---|
committer | Arfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org> | 2009-09-25 06:34:34 +0000 |
commit | 8f7d6cd85e68af46648ff93bf846ba95abf7dcee (patch) | |
tree | 920b4b7d8f71eecbb27c392fb49bd92add418564 | |
parent | 91901078b3d5bc198d7ca6bef062c902ed3d367e (diff) | |
download | portage-8f7d6cd85e68af46648ff93bf846ba95abf7dcee.tar.gz portage-8f7d6cd85e68af46648ff93bf846ba95abf7dcee.tar.bz2 portage-8f7d6cd85e68af46648ff93bf846ba95abf7dcee.zip |
Define __bool__() for compatibility with Python 3.
svn path=/main/trunk/; revision=14427
-rw-r--r-- | pym/_emerge/SequentialTaskQueue.py | 7 | ||||
-rw-r--r-- | pym/portage/dep.py | 5 | ||||
-rw-r--r-- | pym/portage/proxy/objectproxy.py | 7 | ||||
-rw-r--r-- | pym/portage/sets/base.py | 5 |
4 files changed, 19 insertions, 5 deletions
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) |