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

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

Started adding parsing for Condition and Apply types.

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 Condition parser
21   
22    @cvar TYPE: XACML type to instantiate from parsed object
23    @type string: type
24    '''
25    TYPE = Condition
26   
27    def __call__(self, obj):
28        """Parse policy object"""
29        elem = super(ConditionReader, self)._parse(obj)
30       
31        xacmlType = self.__class__.TYPE
32        condition = xacmlType()
33       
34        localName = QName.getLocalPart(elem.tag)
35        if localName != xacmlType.ELEMENT_LOCAL_NAME:
36            raise XMLParseError("No \"%s\" element found" % 
37                                xacmlType.ELEMENT_LOCAL_NAME)
38           
39        # Parse expression sub-element
40        if len(elem) != 1:
41            raise XMLParseError("No expression sub element found in "
42                                "Condition element")
43       
44        subElemlocalName = QName.getLocalPart(elem[0].tag)
45        if subElemlocalName == xacmlType.APPLY_ELEMENT_LOCAL_NAME:
46            condition.expression = ApplyReader.parse(elem[0])
47        else:
48            raise XMLParseError('Expecting %r Condition sub-element not '
49                                'recognised' %
50                                xacmlType.EXPRESSION_ELEMENT_LOCAL_NAME)
51           
52       
53   
54        return condition
Note: See TracBrowser for help on using the repository browser.