source: TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v2/anyuri_regexp_match.py @ 6792

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v2/anyuri_regexp_match.py@6792
Revision 6792, 1.3 KB checked in by pjkersha, 10 years ago (diff)

Made ndg.xacml.core.expression.Expression abstract: derived classes must implement the evaluate method used to evaluate a result in a rule condition.

Line 
1"""NDG XACML any URI 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: $'
11import re
12
13from ndg.xacml.core.functions import AbstractFunction
14
15
16class AnyURIRegexpMatch(AbstractFunction):
17    """Any URI Regular Expression matching function
18    """
19    FUNCTION_NS = 'urn:oasis:names:tc:xacml:2.0:function:anyURI-regexp-match'
20   
21    def evaluate(self, uriPat, uri):
22        """Match URI against regular expression pattern
23       
24        @param uriPat: regular expression
25        @type uriPat: basestring
26        @param uri: URI to match
27        @type uri: basestring
28        @return: True if URI matches pattern, False otherwise
29        @rtype: bool
30        """
31        if not isinstance(uriPat, basestring):
32            raise TypeError('Expecting %r derived type for "uriPat"; got %r' %
33                            (basestring, type(uri1)))
34           
35        if not isinstance(uri, basestring):
36            raise TypeError('Expecting %r derived type for "uri"; got %r' %
37                            (basestring, type(uri)))
38           
39        return bool(re.match(uriPat, uri))
40   
41#AbstractFunction.register(AnyURIRegexpMatch)
Note: See TracBrowser for help on using the repository browser.