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

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

Added AttributeValueFactory? to generate <type>AttributeValue? classes.

Line 
1"""NDG XACML URI equal matching function module
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "30/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.core.functions import AbstractFunction, TYPE_MAP
14from ndg.xacml.core.context.exceptions import XacmlContextError
15from ndg.xacml.utils import TypedList as Bag
16
17
18class AtLeastOneMemberOfBase(AbstractFunction):
19    """Base class implementation for at least one member of XACML function -
20    check an item of a given type is contained in a given bag
21   
22    urn:oasis:names:tc:xacml:1.0:function:<type>-at-least-one-member-of
23    """
24    TYPE = None
25    FUNCTION_SUFFIX = 'AtLeastOneMemberOf'
26    FUNCTION_NS_SUFFIX = '-at-least-one-member-of'
27   
28    def evaluate(self, item, bag):
29        """Check input is contained in the bag
30       
31        @param item: check to see if this string is contained in the bag
32        @type item: type
33        @param bag: bag of <type> values
34        @type bag: TypedList(<type>)
35        @return: True if str is in bag, False otherwise
36        @rtype: bool
37        """
38        if not isinstance(item, self.__class__.TYPE):
39            raise XacmlContextError('Expecting %r derived type for "str"; '
40                                    'got %r' % (self.__class__.TYPE, 
41                                                type(item)))
42           
43        if not isinstance(bag, Bag):
44            raise XacmlContextError('Expecting %r derived type for "bag"; got '
45                                    '%r' % (Bag, type(bag)))
46           
47        if bag.elementType != self.__class__.TYPE:
48            raise XacmlContextError('Expecting %r type elements for "bag"; '
49                                    'got %r' %
50                                    (self.__class__.TYPE, bag.elementType))           
51        return str in bag
52   
53
54_thisModule = sys.modules[__name__]
55
56for typeName, _type in TYPE_MAP.items():
57    className = typeName + AtLeastOneMemberOfBase.FUNCTION_SUFFIX
58    classVars = {
59        'TYPE': _type,
60        'FUNCTION_NS': AbstractFunction.V1_0_FUNCTION_NS + typeName[0
61            ].lower() + typeName[1:] + AtLeastOneMemberOfBase.FUNCTION_NS_SUFFIX
62    }
63    setattr(_thisModule, 
64            className, 
65            type(className, (AtLeastOneMemberOfBase, ), classVars)) 
Note: See TracBrowser for help on using the repository browser.