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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/round.py@6803
Revision 6803, 1.1 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 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, FunctionClassFactoryBase
12from ndg.xacml.core.context.exceptions import XacmlContextTypeError
13
14
15class RoundBase(AbstractFunction):
16    """Base class for XACML <type>-round functions"""
17    FUNCTION_NS = AbstractFunction.V1_0_FUNCTION_NS + 'round'
18   
19    def evaluate(self, num):
20        """Check a bag has one element only and return it
21       
22        @param bag: bag containing one element
23        @rtype: bool
24        """
25        try:
26            return round(num)
27        except TypeError, e:
28            raise XacmlContextTypeError('Round function: %s' % e)
29
30   
31
32class FunctionClassFactory(FunctionClassFactoryBase):
33    """Class Factory for *-round XACML function classes
34    """
35    FUNCTION_NS_SUFFIX = '-round'
36    FUNCTION_BASE_CLASS = RoundBase
Note: See TracBrowser for help on using the repository browser.