1 """NDG XACML Condition type definition
2
3 NERC DataGrid
4 """
5 __author__ = "P J Kershaw"
6 __date__ = "25/02/10"
7 __copyright__ = "(C) 2010 Science and Technology Facilities Council"
8 __contact__ = "Philip.Kershaw@stfc.ac.uk"
9 __license__ = "BSD - see LICENSE file in top-level directory"
10 __contact__ = "Philip.Kershaw@stfc.ac.uk"
11 __revision__ = "$Id: condition.py 7955 2011-12-21 18:29:45Z rwilkinson $"
12 from ndg.xacml.core import XacmlCoreBase
13 from ndg.xacml.core.expression import Expression
17 """XACML 2.0 Rule Condition Note the difference to XACML 1.0: the Condition
18 element is its own type and not an Apply type. It expects a single
19 Expression derived type child element
20
21 @cvar ELEMENT_LOCAL_NAME: XML local name for this element
22 @type ELEMENT_LOCAL_NAME: string
23
24 @cvar APPLY_ELEMENT_LOCAL_NAME: XML local name for the apply element
25 @type APPLY_ELEMENT_LOCAL_NAME: string
26
27 @ivar __expression: expression in this condition
28 @type __expression: ndg.xacml.core.expression.Expression
29 """
30 ELEMENT_LOCAL_NAME = 'Condition'
31 APPLY_ELEMENT_LOCAL_NAME = 'Apply'
32
33 __slots__ = ('__expression', )
34
38
39 @property
41 """Get expression
42
43 @return: expression for this condition
44 @rtype: ndg.xacml.core.expression.Expression / NoneType
45 """
46 return self.__expression
47
48 @expression.setter
50 """Set expression
51
52 @param value: expression for this condition
53 @type value: ndg.xacml.core.expression.Expression
54 @raise TypeError: incorrect input type set
55 """
56 if not isinstance(value, Expression):
57 raise TypeError('Expecting Expression or Expression derived type '
58 'for "expression" attribute; got %r' %
59 type(value))
60 self.__expression = value
61
63 """Evaluate this rule condition
64 @param context: the request context
65 @type context: ndg.xacml.core.request.Request
66 @return: True/False status for whether the rule condition matched or
67 not
68 @rtype: bool
69 """
70 result = self.expression.evaluate(context)
71
72 return result
73