aboutsummaryrefslogtreecommitdiff
blob: bf5a370295a713744caad672c0e8d7b40b6178fd (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright: 2005 Gentoo Foundation
# Author(s): Brian Harring (ferringb@gentoo.org)
# License: GPL2
# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/restrictions/Attic/restrictionSet.py,v 1.7 2005/07/27 02:34:30 ferringb Exp $

import restriction

class RestrictionSet(restriction.base):
	__slots__ = tuple(["restrictions"] + restriction.base.__slots__)

	def __init__(self, *restrictions, **kwds):
		if "finalize" in kwds:
			finalize = kdws["finalize"]
			del kwds["finalize"]
		else:
			finalize = False
		super(RestrictionSet, self).__init__(**kwds)
		for x in restrictions:
			if not isinstance(x, restriction.base):
				#bad monkey.
				raise TypeError, x

		if finalize:
			self.restrictions = tuple(restrictions)
		else:
			self.restrictions = list(restrictions)


	def add_restriction(self, NewRestriction, strict=True):
		if strict and not isinstance(NewRestriction, restriction.base):
			raise TypeError, NewRestriction

		self.restrictions.append(NewRestriction)


	def finalize(self):
		self.restrictions = tuple(self.restrictions)


class AndRestrictionSet(RestrictionSet):
	__slots__ = tuple(RestrictionSet.__slots__)
	
	def match(self, packagedataInstance):
		for rest in self.restrictions:
			if not rest.match(packagedataInstance):
				return self.negate
		return not self.negate


#	def intersect(self, other):
		


class OrRestrictionSet(RestrictionSet):
	__slots__ = tuple(RestrictionSet.__slots__)
	
	def match(self, packagedataInstance):
		for rest in self.restrictions:
			if rest.match(packagedataInstance):
				return self.negate
		return not self.negate

class XorRestrictionSet(RestrictionSet):
	__slots__ = tuple(RestrictionSet.__slots__)

	def match(self, pkginst):
		armed = False
		for rest in self.restrictions:
			if rest.match(pkginst):
				if armed:
					return self.negate
				armed = True
		return armed ^ self.negate