source: TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/expressionreader.py @ 7087

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/expressionreader.py@7087
Revision 7087, 2.2 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 reader for Expression type
2
3NERC DataGrid
4"""
5__author__ = "P J Kershaw"
6__date__ = "18/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 abc import abstractmethod
13
14from ndg.xacml.core.expression import Expression
15from ndg.xacml.parsers import XMLParseError
16from ndg.xacml.parsers.etree import QName
17from ndg.xacml.parsers.etree.reader import ETreeAbstractReader
18
19
20class ExpressionReader(ETreeAbstractReader):
21    '''ElementTree based XACML Expression type parser
22    '''
23    TYPE = Expression
24   
25    def __call__(self, obj):
26        """Parse AttributeValue object"""
27        elem = super(ExpressionReader, self)._parse(obj)
28       
29        xacmlType = self.__class__.TYPE
30        expression = xacmlType()
31       
32        localName = QName.getLocalPart(elem.tag)
33        if localName != xacmlType.ELEMENT_LOCAL_NAME:
34            raise XMLParseError("No \"%s\" element found" % 
35                                xacmlType.ELEMENT_LOCAL_NAME)
36           
37        # Unpack *required* attributes from top-level element
38        attributeValues = []
39        for attributeName in (xacmlType.DATA_TYPE_ATTRIB_NAME,):
40            attributeValue = elem.attrib.get(attributeName)
41            if attributeValue is None:
42                raise XMLParseError('No "%s" attribute found in "%s" element' %
43                                    (attributeName, 
44                                     xacmlType.ELEMENT_LOCAL_NAME))
45               
46            attributeValues.append(attributeValue)
47             
48        expression.dataType, = attributeValues
49                   
50        self._parseExtension(elem, expression)
51       
52        return expression
53       
54    @abstractmethod
55    def _parseExtension(self, elem, expression):
56        """Derived classes should implement this method to read any remaining
57        attributes and elements specific to their type"""
58        raise NotImplementedError()
59         
60# Set up new class as an abstract base itself             
61ETreeAbstractReader.register(ExpressionReader)
Note: See TracBrowser for help on using the repository browser.