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.

RevLine 
[6746]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
[6753]14from ndg.xacml.parsers.etree import QName
[6746]15from ndg.xacml.parsers.etree.reader import ETreeAbstractReader
[6753]16from ndg.xacml.parsers.etree.applyreader import ApplyReader
[6746]17
18
19class ConditionReader(ETreeAbstractReader):
[6753]20    '''ElementTree based XACML Condition parser
21   
22    @cvar TYPE: XACML type to instantiate from parsed object
23    @type string: type
[6746]24    '''
[6753]25    TYPE = Condition
26   
[6746]27    def __call__(self, obj):
28        """Parse policy object"""
[6753]29        elem = super(ConditionReader, self)._parse(obj)
[6746]30       
[6753]31        xacmlType = self.__class__.TYPE
32        condition = xacmlType()
[6746]33       
34        localName = QName.getLocalPart(elem.tag)
[6752]35        if localName != xacmlType.ELEMENT_LOCAL_NAME:
[6746]36            raise XMLParseError("No \"%s\" element found" % 
[6752]37                                xacmlType.ELEMENT_LOCAL_NAME)
[6746]38           
39        # Parse expression sub-element
40        if len(elem) != 1:
41            raise XMLParseError("No expression sub element found in "
42                                "Condition element")
[6753]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)
[6746]51           
[6753]52       
[6746]53   
54        return condition
Note: See TracBrowser for help on using the repository browser.