source: TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/bag.py @ 6804

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/bag.py@6804
Revision 6804, 2.3 KB checked in by pjkersha, 9 years ago (diff)

Working class factories for each function module. Function class evaluate methods need to be refactored to accept *AttributeValue? types

Line 
1"""NDG XACML string bag function module
2
3NERC DataGrid Project
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: $'
11import sys
12
13from ndg.xacml.utils import TypedList as Bag
14from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase
15
16
17class BagBase(AbstractFunction):
18    """Abstract bag function for all types of bag function
19   
20    urn:oasis:names:tc:xacml:1.0:function:<type>-bag
21    """
22    TYPE = None
23    FUNCTION_SUFFIX = 'Bag'
24    FUNCTION_NS_SUFFIX = '-bag'
25   
26    def evaluate(self, *args):
27        """return inputs into a bag
28       
29        @param *args: inputs to add to bag
30        @type args: tuple
31        @param string2: second string
32        @type string2: basestring
33        @return: True if strings match, False otherwise
34        @rtype: bool
35        """
36        bag = Bag(self.__class__.TYPE)
37        for i in args:
38            if not isinstance(i, basestring):
39                raise TypeError('Expecting %r derived type for bag element; '
40                                'got %r' % (self.__class__.TYPE, type(i)))
41            bag.append(i)
42       
43           
44        return bag
45
46
47class FunctionClassFactory(FunctionClassFactoryBase):
48    """Class Factory for *-bag XACML function classes
49    """
50    FUNCTION_NAMES = (
51        'urn:oasis:names:tc:xacml:1.0:function:string-bag',
52        'urn:oasis:names:tc:xacml:1.0:function:boolean-bag',
53        'urn:oasis:names:tc:xacml:1.0:function:integer-bag',
54        'urn:oasis:names:tc:xacml:1.0:function:double-bag',
55        'urn:oasis:names:tc:xacml:1.0:function:time-bag',
56        'urn:oasis:names:tc:xacml:1.0:function:date-bag',
57        'urn:oasis:names:tc:xacml:1.0:function:dateTime-bag',
58        'urn:oasis:names:tc:xacml:1.0:function:anyURI-bag',
59        'urn:oasis:names:tc:xacml:1.0:function:hexBinary-bag',
60        'urn:oasis:names:tc:xacml:1.0:function:base64Binary-bag',
61        'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-bag',
62        'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-bag',
63        'urn:oasis:names:tc:xacml:1.0:function:x500Name-bag',
64        'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-bag',
65    )
66    FUNCTION_NS_SUFFIX = '-bag'
67    FUNCTION_BASE_CLASS = BagBase
Note: See TracBrowser for help on using the repository browser.