aboutsummaryrefslogtreecommitdiff
blob: 250d45802b82934b11b922c8154e30b876f38e14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

from portage.util.SlotObject import SlotObject

class Task(SlotObject):
	__slots__ = ("_hash_key", "_hash_value")

	def __eq__(self, other):
		try:
			return self._hash_key == other._hash_key
		except AttributeError:
			# depgraph._pkg() generates _hash_key
			# for lookups here, so handle that
			return self._hash_key == other

	def __ne__(self, other):
		try:
			return self._hash_key != other._hash_key
		except AttributeError:
			return True

	def __hash__(self):
		return self._hash_value

	def __len__(self):
		return len(self._hash_key)

	def __getitem__(self, key):
		return self._hash_key[key]

	def __iter__(self):
		return iter(self._hash_key)

	def __contains__(self, key):
		return key in self._hash_key

	def __str__(self):
		"""
		Emulate tuple.__repr__, but don't show 'foo' as u'foo' for unicode
		strings.
		"""
		return "(%s)" % ", ".join(("'%s'" % x for x in self._hash_key))

	def __repr__(self):
		if self._hash_key is None:
			# triggered by python-trace
			return SlotObject.__repr__(self)
		return "<%s (%s)>" % (self.__class__.__name__,
			", ".join(("'%s'" % x for x in self._hash_key)))