1 | """NDG XACML string bag function module |
---|
2 | |
---|
3 | NERC DataGrid |
---|
4 | """ |
---|
5 | __author__ = "P J Kershaw" |
---|
6 | __date__ = "31/03/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.utils import TypedList as Bag |
---|
12 | from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase |
---|
13 | |
---|
14 | |
---|
15 | class BagBase(AbstractFunction): |
---|
16 | """Abstract bag function for all types of bag function |
---|
17 | |
---|
18 | urn:oasis:names:tc:xacml:1.0:function:<type>-bag |
---|
19 | |
---|
20 | @cvar TYPE: attribute type for the given implementation. Derived classes |
---|
21 | should set appropriately |
---|
22 | @type TYPE: NoneType |
---|
23 | |
---|
24 | @cvar FUNCTION_SUFFIX: suffix for all bag function class names |
---|
25 | @type FUNCTION_SUFFIX: string |
---|
26 | |
---|
27 | @cvar FUNCTION_NS_SUFFIX: generic suffix for at least one member of function |
---|
28 | URNs |
---|
29 | @type FUNCTION_NS_SUFFIX: string |
---|
30 | """ |
---|
31 | TYPE = None |
---|
32 | FUNCTION_SUFFIX = 'Bag' |
---|
33 | FUNCTION_NS_SUFFIX = '-bag' |
---|
34 | |
---|
35 | def evaluate(self, *args): |
---|
36 | """return inputs into a bag |
---|
37 | |
---|
38 | @param args: inputs to add to bag |
---|
39 | @type args: tuple |
---|
40 | @return: True if strings match, False otherwise |
---|
41 | @rtype: bool |
---|
42 | """ |
---|
43 | bag = Bag(self.__class__.TYPE) |
---|
44 | for i in args: |
---|
45 | if not isinstance(i, self.__class__.TYPE): |
---|
46 | raise TypeError('Expecting %r derived type for bag element; ' |
---|
47 | 'got %r' % (self.__class__.TYPE, type(i))) |
---|
48 | bag.append(i) |
---|
49 | |
---|
50 | return bag |
---|
51 | |
---|
52 | |
---|
53 | class FunctionClassFactory(FunctionClassFactoryBase): |
---|
54 | """Class Factory for *-bag XACML function classes |
---|
55 | |
---|
56 | @cvar FUNCTION_NAMES: bag function URNs |
---|
57 | @type FUNCTION_NAMES: tuple |
---|
58 | |
---|
59 | @cvar FUNCTION_NS_SUFFIX: generic suffix for bag function URNs |
---|
60 | @type FUNCTION_NS_SUFFIX: string |
---|
61 | |
---|
62 | @cvar FUNCTION_BASE_CLASS: base class for all bag function classes |
---|
63 | @type FUNCTION_BASE_CLASS: ndg.xacml.core.functions.v1.BagBase |
---|
64 | """ |
---|
65 | FUNCTION_NAMES = ( |
---|
66 | 'urn:oasis:names:tc:xacml:1.0:function:string-bag', |
---|
67 | 'urn:oasis:names:tc:xacml:1.0:function:boolean-bag', |
---|
68 | 'urn:oasis:names:tc:xacml:1.0:function:integer-bag', |
---|
69 | 'urn:oasis:names:tc:xacml:1.0:function:double-bag', |
---|
70 | 'urn:oasis:names:tc:xacml:1.0:function:time-bag', |
---|
71 | 'urn:oasis:names:tc:xacml:1.0:function:date-bag', |
---|
72 | 'urn:oasis:names:tc:xacml:1.0:function:dateTime-bag', |
---|
73 | 'urn:oasis:names:tc:xacml:1.0:function:anyURI-bag', |
---|
74 | 'urn:oasis:names:tc:xacml:1.0:function:hexBinary-bag', |
---|
75 | 'urn:oasis:names:tc:xacml:1.0:function:base64Binary-bag', |
---|
76 | 'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-bag', |
---|
77 | 'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-bag', |
---|
78 | 'urn:oasis:names:tc:xacml:1.0:function:x500Name-bag', |
---|
79 | 'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-bag', |
---|
80 | ) |
---|
81 | FUNCTION_NS_SUFFIX = '-bag' |
---|
82 | FUNCTION_BASE_CLASS = BagBase |
---|