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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/equal.py@6804
Revision 6804, 2.6 KB checked in by pjkersha, 9 years ago (diff)

Working class factories for each function module. Function class evaluate methods need to be refactored to accept *AttributeValue? types

Line 
1"""NDG XACML URI equal matching function module
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "26/03/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
12from ndg.xacml.core.context.exceptions import XacmlContextTypeError
13from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase
14
15
16class EqualBase(AbstractFunction):
17    """Generic equal function for all types"""
18    TYPE = None
19   
20    def evaluate(self, string1, string2):
21        """Match input strings
22       
23        @param string1: first of two strings to match
24        @type string1: basestring
25        @param string2: second string
26        @type string2: basestring
27        @return: True if strings match, False otherwise
28        @rtype: bool
29        """
30        if not isinstance(string1, basestring):
31            raise XacmlContextTypeError('Expecting %r derived type for '
32                                        '"string1"; got %r' %
33                                        (self.__class__.TYPE, 
34                                         type(string1)))
35           
36        if not isinstance(string2, self.__class__.TYPE):
37            raise XacmlContextTypeError('Expecting %r derived type for '
38                                        '"string2"; got %r' %
39                                        (self.__class__.TYPE, 
40                                         type(string2)))
41           
42        return string1 == string2
43   
44
45class FunctionClassFactory(FunctionClassFactoryBase):
46    """Class Factory for *-equal XACML function classes
47    """
48    FUNCTION_NAMES = (
49        'urn:oasis:names:tc:xacml:1.0:function:string-equal',
50        'urn:oasis:names:tc:xacml:1.0:function:boolean-equal',
51        'urn:oasis:names:tc:xacml:1.0:function:integer-equal',
52        'urn:oasis:names:tc:xacml:1.0:function:double-equal',
53        'urn:oasis:names:tc:xacml:1.0:function:date-equal',
54        'urn:oasis:names:tc:xacml:1.0:function:time-equal',
55        'urn:oasis:names:tc:xacml:1.0:function:dateTime-equal',
56        'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-equal',
57        'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-equal',
58        'urn:oasis:names:tc:xacml:1.0:function:anyURI-equal',
59        'urn:oasis:names:tc:xacml:1.0:function:x500Name-equal',
60        'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-equal',
61        'urn:oasis:names:tc:xacml:1.0:function:hexBinary-equal',
62        'urn:oasis:names:tc:xacml:1.0:function:base64Binary-equal'
63    )
64    FUNCTION_NS_SUFFIX = '-equal'
65    FUNCTION_BASE_CLASS = EqualBase
Note: See TracBrowser for help on using the repository browser.