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

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

Incomplete - task 2: XACML-Security Integration

  • updating epydoc ready for release.
  • Property svn:keywords set to Id
Line 
1"""NDG XACML one and only functions module
2
3NERC DataGrid
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   
19    @cvar FUNCTION_NS: namespace for this function
20    @type FUNCTION_NS: string
21    """
22    FUNCTION_NS = AbstractFunction.V1_0_FUNCTION_NS + 'round'
23   
24    def evaluate(self, num):
25        """Check a bag has one element only and return it
26       
27        @param num: number to round up
28        @type num: int / long / float
29        @rtype: float
30        @raise TypeError: incorrect type for input
31        """
32        try:
33            return round(num)
34        except TypeError, e:
35            raise XacmlContextTypeError('Round function: %s' % e)
36
37   
38class FunctionClassFactory(FunctionClassFactoryInterface):
39    """Class Factory for round XACML function class
40    """
41    def __call__(self, identifier):
42        '''Create class for the Round XACML function identifier
43       
44        @param identifier: XACML round function identifier
45        @type identifier: basestring
46        @return: round function class or None if identifier doesn't match
47        @rtype: ndg.xacml.core.functions.v1.round.Round / NoneType
48        '''
49        if identifier == Round.FUNCTION_NS:
50            return Round
51        else:
52            return None
Note: See TracBrowser for help on using the repository browser.