source: TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/conditionreader.py @ 6796

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/conditionreader.py@6796
Revision 6796, 2.2 KB checked in by pjkersha, 10 years ago (diff)

Refactored functions package to enable dynamic creation of function classes for all the XACML primitive types for any given function e.g. equal module implements EqualBase? and dynamically creates the <type>-equal classes for all the types: string, AnyURI, Boolean etc.

Line 
1"""NDG XACML ElementTree based Target Element reader
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "16/03/10"
7__copyright__ = "(C) 2010 Science and Technology Facilities Council"
8__contact__ = "Philip.Kershaw@stfc.ac.uk"
9__license__ = "BSD - see LICENSE file in top-level directory"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = "$Id: $"
12from ndg.xacml.core.condition import Condition
13from ndg.xacml.parsers import XMLParseError
14from ndg.xacml.parsers.etree import QName
15from ndg.xacml.parsers.etree.reader import ETreeAbstractReader
16from ndg.xacml.parsers.etree.applyreader import ApplyReader
17
18
19class ConditionReader(ETreeAbstractReader):
20    '''ElementTree based XACML 2.0 Condition parser.  Note the difference to
21    XACML 1.0: the Condition element is its own type and not an Apply type.
22    It expects a single Expression derived type child element
23   
24    @cvar TYPE: XACML type to instantiate from parsed object
25    @type string: type
26    '''
27    TYPE = Condition
28   
29    def __call__(self, obj):
30        """Parse policy object"""
31        elem = super(ConditionReader, self)._parse(obj)
32       
33        xacmlType = self.__class__.TYPE
34        condition = xacmlType()
35       
36        localName = QName.getLocalPart(elem.tag)
37        if localName != xacmlType.ELEMENT_LOCAL_NAME:
38            raise XMLParseError("No \"%s\" element found" % 
39                                xacmlType.ELEMENT_LOCAL_NAME)
40           
41        # Parse expression sub-element
42        nSubElem = len(elem)
43        if nSubElem != 1:
44            raise XMLParseError('XACML 2.0 policy schema expects only one '
45                                'expression sub-element in the Condition '
46                                'element; policy file has %d' % nSubElem)
47       
48        subElemlocalName = QName.getLocalPart(elem[0].tag)
49        if subElemlocalName == xacmlType.APPLY_ELEMENT_LOCAL_NAME:
50            condition.expression = ApplyReader.parse(elem[0])
51        else:
52            raise XMLParseError('Expecting %r Condition sub-element not '
53                                'recognised' %
54                                xacmlType.EXPRESSION_ELEMENT_LOCAL_NAME)
55           
56       
57   
58        return condition
Note: See TracBrowser for help on using the repository browser.