1 """NDG XACML one and only functions module
2
3 NERC DataGrid
4 """
5 __author__ = "P J Kershaw"
6 __date__ = "01/04/10"
7 __copyright__ = ""
8 __license__ = "BSD - see LICENSE file in top-level directory"
9 __contact__ = "Philip.Kershaw@stfc.ac.uk"
10 __revision__ = '$Id$'
11 from ndg.xacml.core.functions import (AbstractFunction,
12 FunctionClassFactoryInterface)
13 from ndg.xacml.core.context.exceptions import XacmlContextTypeError
14
15
16 -class And(AbstractFunction):
17 """Base class for XACML <type>-and functions
18
19 @cvar FUNCTION_NS: namespace for this function
20 @type FUNCTION_NS: string
21 @cvar ATTRIBUTE_TYPE: type for arguments
22 @type ATTRIBUTE_TYPE: str
23 """
24 FUNCTION_NS = AbstractFunction.V1_0_FUNCTION_NS + 'and'
25 ATTRIBUTE_TYPE = bool
26
28 """perform AND function on the variable length argument list of elements
29
30 access_control-xacml-2.0-core-spec-os, Fe 2005 - A.3.5 Logical functions
31 access_control-xacml-2.0-core-spec-os, Fe 2005 - 4.2.4.2 ( Rule 2 a[346] ... a[361] )
32 @param *args: variable number of elements to be AND'ed
33 @type bool: ndg.xacml.utils.TypedList
34
35 @return: result of AND operation on the inputs
36 @rtype: bool
37 """
38 if len(args)==0:
39 return True
40 else:
41 for n, arg in enumerate(args):
42 if type(arg) != self.__class__.ATTRIBUTE_TYPE:
43 raise XacmlContextTypeError(
44 'Expecting %r type for attribute %d; got %r' %
45 (self.__class__.ATTRIBUTE_TYPE, n + 1,
46 type(arg)))
47 for arg in args:
48 if not arg:
49 return False
50 return True
51
52
54 """Class Factory for and XACML function class
55
56 @cvar FUNCTION_NS: URN for and function
57 @type FUNCTION_NS: string
58 """
59 FUNCTION_NS = 'urn:oasis:names:tc:xacml:1.0:function:and'
60
62 '''Create class for the And XACML function identifier
63
64 @param identifier: XACML and function identifier
65 @type identifier: basestring
66 @return: and function class or None if identifier doesn't match
67 @rtype: ndg.xacml.core.functions.v1.and.And / NoneType
68 '''
69 if identifier == And.FUNCTION_NS:
70 return And
71 else:
72 return None
73