1 """NDG XACML one and only functions module
2
3 NERC DataGrid
4 """
5 __author__ = "Prashant Kediyal"
6 __date__ = "03/01/12"
7 __copyright__ = ""
8 __license__ = "BSD - see LICENSE file in top-level directory"
9 __contact__ = "pkediyal@gmail.com"
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 Not(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 + 'not'
25 ATTRIBUTE_TYPE = bool
26
28 """perform not function on the element
29
30 access_control-xacml-2.0-core-spec-os, Fe 2005 - A.3.5 Logical functions
31
32 @param attribute: elements to be NOT'ed
33 @type attribute: bool
34
35 @return: result of NOT operation on the inputs
36 @rtype: bool
37
38 """
39 if type(attribute) != self.__class__.ATTRIBUTE_TYPE:
40 raise XacmlContextTypeError('Expecting %r type for attribute; '
41 'got %r' %
42 (self.__class__.ATTRIBUTE_TYPE,
43 type(attribute)))
44
45 if attribute is None:
46 response = False
47 else:
48 response = not attribute
49
50 return response
51
52
54 """Class Factory for not XACML function class
55
56 @cvar FUNCTION_NS: URN for not function
57 @type FUNCTION_NS: string
58 """
59 FUNCTION_NS = 'urn:oasis:names:tc:xacml:1.0:function:not'
60
62 '''Create class for the Not 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.not.Not / NoneType
68 '''
69 if identifier == Not.FUNCTION_NS:
70 return Not
71 else:
72 return None
73