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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/ndg_xacml/ndg/xacml/core/functions/v1/one_and_only.py@7087
Revision 7087, 3.3 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$'
11#from datetime import datetime, timedelta
12
13from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase
14from ndg.xacml.utils import TypedList as Bag
15from ndg.xacml.core.context.exceptions import XacmlContextError
16
17
18class OneAndOnlyBase(AbstractFunction):
19    """Base class for XACML <type>-one-and-only functions
20   
21    @cvar TYPE: attribute type for the given implementation.  Derived classes
22    should set appropriately
23    @type TYPE: NoneType
24    """
25    TYPE = None
26   
27    def evaluate(self, bag):
28        """Check a bag has one element only and return it
29       
30        @param bag: bag containing one element
31        @type bag: ndg.xacml.utils.TypedList
32        @return: single item from bag
33        @rtype: dependent on bag type set in derived type
34        """
35        if not isinstance(bag, Bag):
36            raise XacmlContextError('Expecting %r derived type for "bag"; '
37                                    'got %r' % (Bag, type(bag)))
38           
39        if bag.elementType != self.__class__.TYPE:
40            raise XacmlContextError('Expecting %r type elements for "bag"; '
41                                    'got %r' %
42                                    (self.__class__.TYPE, bag.elementType))
43                       
44        nBagElems = len(bag)
45        if nBagElems != 1:
46            raise XacmlContextError('Expecting single element for %r bag; got '
47                                    '%r' % (self.__class__.TYPE, nBagElems))
48           
49        return bag[0]
50   
51
52class FunctionClassFactory(FunctionClassFactoryBase):
53    """Class Factory for *-one-and-only XACML function classes
54   
55    @cvar FUNCTION_NAMES: one and only function URNs
56    @type FUNCTION_NAMES: tuple
57   
58    @cvar FUNCTION_NS_SUFFIX: generic suffix for one and only function URNs
59    @type FUNCTION_NS_SUFFIX: string
60   
61    @cvar FUNCTION_BASE_CLASS: base class for all one and only function classes
62    @type FUNCTION_BASE_CLASS: ndg.xacml.core.functions.v1.OneAndOnlyBase
63    """
64    FUNCTION_NAMES = (
65        'urn:oasis:names:tc:xacml:1.0:function:string-one-and-only',
66        'urn:oasis:names:tc:xacml:1.0:function:boolean-one-and-only',
67        'urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only',
68        'urn:oasis:names:tc:xacml:1.0:function:double-one-and-only',
69        'urn:oasis:names:tc:xacml:1.0:function:time-one-and-only',
70        'urn:oasis:names:tc:xacml:1.0:function:date-one-and-only',
71        'urn:oasis:names:tc:xacml:1.0:function:dateTime-one-and-only',
72        'urn:oasis:names:tc:xacml:1.0:function:anyURI-one-and-only',
73        'urn:oasis:names:tc:xacml:1.0:function:hexBinary-one-and-only',
74        'urn:oasis:names:tc:xacml:1.0:function:base64Binary-one-and-only',
75        'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-one-and-only',
76        'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-one-and-only',
77        'urn:oasis:names:tc:xacml:1.0:function:x500Name-one-and-only',
78        'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-one-and-only'
79    )
80    FUNCTION_NS_SUFFIX = '-one-and-only'
81    FUNCTION_BASE_CLASS = OneAndOnlyBase
82   
Note: See TracBrowser for help on using the repository browser.