source: TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/conditionreader.py @ 7109

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

Incomplete - task 2: XACML-Security Integration

  • updating epydoc ready for release.
  • Property svn:keywords set to Id
Line 
1"""NDG XACML ElementTree based Target Element reader
2
3NERC DataGrid
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 TYPE: type
26    '''
27    TYPE = Condition
28   
29    def __call__(self, obj):
30        """Parse condition object
31       
32        @param obj: input object to parse
33        @type obj: ElementTree Element, or stream object
34        @return: new XACML condition instance
35        @rtype: ndg.xacml.core.condition.Condition
36        @raise XMLParseError: error reading sub-elements
37        """
38        elem = super(ConditionReader, self)._parse(obj)
39       
40        xacmlType = self.__class__.TYPE
41        condition = xacmlType()
42       
43        localName = QName.getLocalPart(elem.tag)
44        if localName != xacmlType.ELEMENT_LOCAL_NAME:
45            raise XMLParseError("No \"%s\" element found" % 
46                                xacmlType.ELEMENT_LOCAL_NAME)
47           
48        # Parse expression sub-element
49        nSubElem = len(elem)
50        if nSubElem != 1:
51            raise XMLParseError('XACML 2.0 policy schema expects only one '
52                                'expression sub-element in the Condition '
53                                'element; policy file has %d' % nSubElem)
54       
55        subElemlocalName = QName.getLocalPart(elem[0].tag)
56        if subElemlocalName == xacmlType.APPLY_ELEMENT_LOCAL_NAME:
57            condition.expression = ApplyReader.parse(elem[0])
58        else:
59            raise XMLParseError('Expecting %r Condition sub-element not '
60                                'recognised' %
61                                xacmlType.EXPRESSION_ELEMENT_LOCAL_NAME)
62           
63       
64   
65        return condition
Note: See TracBrowser for help on using the repository browser.