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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/attributedesignatorreader.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 AttributeDesignator type
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.utils import str2Bool
13from ndg.xacml.core.attributedesignator import SubjectAttributeDesignator
14from ndg.xacml.parsers import XMLParseError
15from ndg.xacml.parsers.etree import QName
16from ndg.xacml.parsers.etree.expressionreader import ExpressionReader
17
18
19class AttributeDesignatorReaderBase(ExpressionReader):
20    '''ElementTree based XACML Attribute Designator base class type parser
21    '''
22    def _parseExtension(self, elem, attributeDesignator):
23        """Parse AttributeDesignator object"""
24        cls = self.__class__.TYPE
25       
26        # Unpack additional *required* attributes from top-level element
27        attributeValues = []
28        for attributeName in (cls.ATTRIBUTE_ID_ATTRIB_NAME,):
29            attributeValue = elem.attrib.get(attributeName)
30            if attributeValue is None:
31                raise XMLParseError('No "%s" attribute found in "%s" element' %
32                                    (attributeName, cls.ELEMENT_LOCAL_NAME))
33               
34            attributeValues.append(attributeValue)
35             
36        attributeDesignator.attributeId, = attributeValues
37             
38        # Optional attributes
39        issuer = elem.attrib.get(cls.DATA_TYPE_ATTRIB_NAME)
40        if issuer is not None:
41            attributeDesignator.issuer = issuer
42             
43        mustBePresent = elem.attrib.get(cls.DATA_TYPE_ATTRIB_NAME)
44        if mustBePresent is not None:
45            attributeDesignator.mustBePresent = str2Bool(mustBePresent)
46   
47        return attributeDesignator
48
49
50class SubjectAttributeDesignatorReader(AttributeDesignatorReaderBase): 
51    '''ElementTree based XACML Subject Attribute Designator type parser
52    '''
53    TYPE = SubjectAttributeDesignator
Note: See TracBrowser for help on using the repository browser.