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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/ndg_xacml/ndg/xacml/core/functions/v1/bag.py@7109
Revision 7109, 2.9 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 string bag function module
2
3NERC DataGrid
4"""
5__author__ = "P J Kershaw"
6__date__ = "31/03/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.utils import TypedList as Bag
12from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase
13
14
15class BagBase(AbstractFunction):
16    """Abstract bag function for all types of bag function
17   
18    urn:oasis:names:tc:xacml:1.0:function:<type>-bag
19   
20    @cvar TYPE: attribute type for the given implementation.  Derived classes
21    should set appropriately
22    @type TYPE: NoneType
23   
24    @cvar FUNCTION_SUFFIX: suffix for all bag function class names
25    @type FUNCTION_SUFFIX: string
26   
27    @cvar FUNCTION_NS_SUFFIX: generic suffix for at least one member of function
28    URNs
29    @type FUNCTION_NS_SUFFIX: string
30    """
31    TYPE = None
32    FUNCTION_SUFFIX = 'Bag'
33    FUNCTION_NS_SUFFIX = '-bag'
34   
35    def evaluate(self, *args):
36        """return inputs into a bag
37       
38        @param args: inputs to add to bag
39        @type args: tuple
40        @return: True if strings match, False otherwise
41        @rtype: bool
42        """
43        bag = Bag(self.__class__.TYPE)
44        for i in args:
45            if not isinstance(i, self.__class__.TYPE):
46                raise TypeError('Expecting %r derived type for bag element; '
47                                'got %r' % (self.__class__.TYPE, type(i)))
48            bag.append(i)
49         
50        return bag
51
52
53class FunctionClassFactory(FunctionClassFactoryBase):
54    """Class Factory for *-bag XACML function classes
55   
56    @cvar FUNCTION_NAMES: bag function URNs
57    @type FUNCTION_NAMES: tuple
58   
59    @cvar FUNCTION_NS_SUFFIX: generic suffix for bag function URNs
60    @type FUNCTION_NS_SUFFIX: string
61   
62    @cvar FUNCTION_BASE_CLASS: base class for all bag function classes
63    @type FUNCTION_BASE_CLASS: ndg.xacml.core.functions.v1.BagBase
64    """
65    FUNCTION_NAMES = (
66        'urn:oasis:names:tc:xacml:1.0:function:string-bag',
67        'urn:oasis:names:tc:xacml:1.0:function:boolean-bag',
68        'urn:oasis:names:tc:xacml:1.0:function:integer-bag',
69        'urn:oasis:names:tc:xacml:1.0:function:double-bag',
70        'urn:oasis:names:tc:xacml:1.0:function:time-bag',
71        'urn:oasis:names:tc:xacml:1.0:function:date-bag',
72        'urn:oasis:names:tc:xacml:1.0:function:dateTime-bag',
73        'urn:oasis:names:tc:xacml:1.0:function:anyURI-bag',
74        'urn:oasis:names:tc:xacml:1.0:function:hexBinary-bag',
75        'urn:oasis:names:tc:xacml:1.0:function:base64Binary-bag',
76        'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-bag',
77        'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-bag',
78        'urn:oasis:names:tc:xacml:1.0:function:x500Name-bag',
79        'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-bag',
80    )
81    FUNCTION_NS_SUFFIX = '-bag'
82    FUNCTION_BASE_CLASS = BagBase
Note: See TracBrowser for help on using the repository browser.