summaryrefslogtreecommitdiff
blob: 71c2e3cf25fb6ad6f844177cf93989f357e255be (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
# 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.2 2005/07/13 05:51:35 ferringb Exp $

import restriction

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

	def __init__(self, *restrictions, **kwds):
		super(RestrictionSet, self).__init__(**kwds)
		for x in restrictions:
			if not isinstance(x, restriction.base):
				#bad monkey.
				raise TypeError, x
		self.restrictions = restrictions


	def addRestriction(self, NewRestriction):
		if not isinstance(NewRestriction, restriction.base):
			raise TypeError, NewRestriction

		self.restrictions.append(NewRestriction)


	def pmatch(self, packagedataInstance):
		raise NotImplementedError


	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


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