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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/round.py@6804
Revision 6804, 1.5 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 one and only functions module
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "01/04/10"
7__copyright__ = ""
8__license__ = "BSD - see LICENSE file in top-level directory"
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__revision__ = '$Id: $'
11from ndg.xacml.core.functions import (AbstractFunction, 
12                                      FunctionClassFactoryInterface)
13from ndg.xacml.core.context.exceptions import XacmlContextTypeError
14
15
16class Round(AbstractFunction):
17    """Base class for XACML <type>-round functions"""
18    FUNCTION_NS = AbstractFunction.V1_0_FUNCTION_NS + 'round'
19   
20    def evaluate(self, num):
21        """Check a bag has one element only and return it
22       
23        @param bag: bag containing one element
24        @rtype: bool
25        """
26        try:
27            return round(num)
28        except TypeError, e:
29            raise XacmlContextTypeError('Round function: %s' % e)
30
31   
32class FunctionClassFactory(FunctionClassFactoryInterface):
33    """Class Factory for round XACML function class
34    """
35    def __call__(self, identifier):
36        '''Create class for the Round XACML function identifier
37       
38        @param identifier: XACML round function identifier
39        @type identifier: basestring
40        @return: round function class or None if identifier doesn't match
41        @rtype: ndg.xacml.core.functions.v1.round.Round / NoneType
42        '''
43        if identifier == Round.FUNCTION_NS:
44            return Round
45        else:
46            return None
Note: See TracBrowser for help on using the repository browser.