1 """NDG XACML equal function module - contains classes to represent XACML 1.0
2 *-equal functions
3
4 NERC DataGrid
5 """
6 __author__ = "P J Kershaw"
7 __date__ = "26/03/10"
8 __copyright__ = ""
9 __license__ = "BSD - see LICENSE file in top-level directory"
10 __contact__ = "Philip.Kershaw@stfc.ac.uk"
11 __revision__ = '$Id: equal.py 7955 2011-12-21 18:29:45Z rwilkinson $'
12 from ndg.xacml.core.context.exceptions import XacmlContextTypeError
13 from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase
14
15
17 """Generic equal function for all types
18
19 @cvar TYPE: attribute type for the given implementation. Derived classes
20 should set appropriately
21 @type TYPE: NoneType
22 """
23 TYPE = None
24
25 - def evaluate(self, attribute1, attribute2):
26 """Match input attribute values
27
28 @param attribute1: first of two attributes to match
29 @type attribute1: ndg.xacml.core.attributevalue.AttributeValue derived
30 @param attribute2: second attribute
31 @type attribute2: ndg.xacml.core.attributevalue.AttributeValue derived
32 @return: True if attributes match, False otherwise
33 @rtype: bool
34 """
35 if not isinstance(attribute1, self.__class__.TYPE):
36 raise XacmlContextTypeError('Expecting %r derived type for '
37 '"attribute1"; got %r' %
38 (self.__class__.TYPE,
39 type(attribute1)))
40
41 if not isinstance(attribute2, self.__class__.TYPE):
42 raise XacmlContextTypeError('Expecting %r derived type for '
43 '"attribute2"; got %r' %
44 (self.__class__.TYPE,
45 type(attribute2)))
46
47 return attribute1.value == attribute2.value
48
49
51 """Class Factory for *-equal XACML function classes
52
53 @cvar FUNCTION_NAMES: equal function URNs
54 @type FUNCTION_NAMES: tuple
55
56 @cvar FUNCTION_NS_SUFFIX: generic suffix for equal function URNs
57 @type FUNCTION_NS_SUFFIX: string
58
59 @cvar FUNCTION_BASE_CLASS: base class for all equal function classes
60 @type FUNCTION_BASE_CLASS: ndg.xacml.core.functions.v1.EqualBase
61 """
62 FUNCTION_NAMES = (
63 'urn:oasis:names:tc:xacml:1.0:function:string-equal',
64 'urn:oasis:names:tc:xacml:1.0:function:boolean-equal',
65 'urn:oasis:names:tc:xacml:1.0:function:integer-equal',
66 'urn:oasis:names:tc:xacml:1.0:function:double-equal',
67 'urn:oasis:names:tc:xacml:1.0:function:date-equal',
68 'urn:oasis:names:tc:xacml:1.0:function:time-equal',
69 'urn:oasis:names:tc:xacml:1.0:function:dateTime-equal',
70 'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-equal',
71 'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-equal',
72 'urn:oasis:names:tc:xacml:1.0:function:anyURI-equal',
73 'urn:oasis:names:tc:xacml:1.0:function:x500Name-equal',
74 'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-equal',
75 'urn:oasis:names:tc:xacml:1.0:function:hexBinary-equal',
76 'urn:oasis:names:tc:xacml:1.0:function:base64Binary-equal',
77 'urn:oasis:names:tc:xacml:1.0:function:xpath-node-equal'
78 )
79 FUNCTION_NS_SUFFIX = '-equal'
80 FUNCTION_BASE_CLASS = EqualBase
81