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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/attributeselectorreader.py@7109
Revision 7109, 2.6 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 Attribute Selector Reader 
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 ndg.xacml.utils import str2Bool
13from ndg.xacml.core.attributeselector import AttributeSelector
14from ndg.xacml.parsers import XMLParseError
15from ndg.xacml.parsers.etree import QName
16from ndg.xacml.parsers.etree.expressionreader import ExpressionReader
17
18
19class AttributeSelectorReader(ExpressionReader):
20    '''ElementTree based parser for XACML Attribute Selector type
21   
22    @cvar TYPE: XACML class type that this reader will read values into
23    @type TYPE: abc.ABCMeta
24    '''
25    TYPE = AttributeSelector
26   
27    def _parseExtension(self, elem, attributeSelector):
28        """Parse XML Attribute Selector element
29       
30        @param elem: ElementTree XML element
31        @type elem: xml.etree.Element
32       
33        @param attributeSelector: attribute selector to be updated with parsed
34        values
35        @type attributeSelector: ndg.xacml.core.attributeSelector.AttributeSelector
36       
37        @raise XMLParseError: error parsing attribute ID XML attribute
38       
39        @return: updated attribute selector
40        @rtype: ndg.xacml.core.attributeSelector.AttributeSelector
41        """
42       
43        xacmlType = self.__class__.TYPE
44       
45        localName = QName.getLocalPart(elem.tag)
46        if localName != xacmlType.ELEMENT_LOCAL_NAME:
47            raise XMLParseError("No \"%s\" element found" % 
48                                xacmlType.ELEMENT_LOCAL_NAME)
49           
50        # Unpack *required* attributes from top-level element
51        attributeValues = []
52        for attributeName in (xacmlType.REQUEST_CONTEXT_PATH_ATTRIB_NAME,):
53            attributeValue = elem.attrib.get(attributeName)
54            if attributeValue is None:
55                raise XMLParseError('No "%s" attribute found in "%s" element' %
56                                    (attributeName, 
57                                     xacmlType.ELEMENT_LOCAL_NAME))
58               
59            attributeValues.append(attributeValue)
60             
61        attributeSelector.requestContextPath, = attributeValues
62       
63        mustBePresent = elem.attrib.get(xacmlType.MUST_BE_PRESENT_ATTRIB_NAME)
64        if mustBePresent is not None:
65            attributeSelector.mustBePresent = str2Bool(mustBePresent)
66         
67        return attributeSelector
68
69               
Note: See TracBrowser for help on using the repository browser.