source: TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/expressionreader.py @ 6750

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

Parsing functionality near complete for rule1.xml

Line 
1"""NDG XACML ElementTree based reader for Expression type
2
3NERC DataGrid Project
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        cls = self.__class__.TYPE
30        expression = cls()
31       
32        localName = QName.getLocalPart(elem.tag)
33        if localName != cls.ELEMENT_LOCAL_NAME:
34            raise XMLParseError("No \"%s\" element found" % 
35                                cls.ELEMENT_LOCAL_NAME)
36           
37        # Unpack *required* attributes from top-level element
38        attributeValues = []
39        for attributeName in (cls.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, cls.ELEMENT_LOCAL_NAME))
44               
45            attributeValues.append(attributeValue)
46             
47        expression.dataType, = attributeValues
48                   
49        self._parseExtension(elem, expression)
50       
51        return expression
52       
53    @abstractmethod
54    def _parseExtension(self, elem, expression):
55        """Derived classes should implement this method to read any remaining
56        attributes and elements specific to their type"""
57        raise NotImplementedError()
58         
59# Set up new class as an abstract base itself             
60ETreeAbstractReader.register(ExpressionReader)
Note: See TracBrowser for help on using the repository browser.