1 """NDG XACML one and only functions module
2
3 NERC 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: round.py 8020 2012-02-23 12:35:19Z pjkersha $'
11 from ndg.xacml.core.functions import (AbstractFunction,
12 FunctionClassFactoryInterface)
13 from ndg.xacml.core.context.exceptions import XacmlContextTypeError
14
15
16 -class 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
25 """Execute mathematical round up of the input number
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
39 """Class Factory for round XACML function class
40 """
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
53