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

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

Refactored function modules with class factories to generate classes for each variable type.

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_NS_SUFFIX = '-bag'
51    FUNCTION_BASE_CLASS = BagBase
Note: See TracBrowser for help on using the repository browser.