1 | """NDG XACML ElementTree based reader for AttributeDesignator type |
---|
2 | |
---|
3 | NERC 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$" |
---|
12 | from ndg.xacml.utils import str2Bool |
---|
13 | from ndg.xacml.parsers import XMLParseError |
---|
14 | from ndg.xacml.parsers.etree import QName |
---|
15 | from ndg.xacml.parsers.etree.expressionreader import ExpressionReader |
---|
16 | |
---|
17 | |
---|
18 | class AttributeDesignatorReaderBase(ExpressionReader): |
---|
19 | '''ElementTree based XACML Attribute Designator base class type parser |
---|
20 | ''' |
---|
21 | def _parseExtension(self, elem, attributeDesignator): |
---|
22 | """Parse AttributeDesignator object""" |
---|
23 | xacmlType = self.__class__.TYPE |
---|
24 | |
---|
25 | # Unpack additional *required* attributes from top-level element |
---|
26 | attributeValues = [] |
---|
27 | for attributeName in (xacmlType.ATTRIBUTE_ID_ATTRIB_NAME,): |
---|
28 | attributeValue = elem.attrib.get(attributeName) |
---|
29 | if attributeValue is None: |
---|
30 | raise XMLParseError('No "%s" attribute found in "%s" element' % |
---|
31 | (attributeName, |
---|
32 | xacmlType.ELEMENT_LOCAL_NAME)) |
---|
33 | |
---|
34 | attributeValues.append(attributeValue) |
---|
35 | |
---|
36 | attributeDesignator.attributeId, = attributeValues |
---|
37 | |
---|
38 | # Optional attributes |
---|
39 | issuer = elem.attrib.get(xacmlType.ISSUER_ATTRIB_NAME) |
---|
40 | if issuer is not None: |
---|
41 | attributeDesignator.issuer = issuer |
---|
42 | |
---|
43 | mustBePresent = elem.attrib.get(xacmlType.MUST_BE_PRESENT_ATTRIB_NAME) |
---|
44 | if mustBePresent is not None: |
---|
45 | attributeDesignator.mustBePresent = str2Bool(mustBePresent) |
---|
46 | |
---|
47 | return attributeDesignator |
---|
48 | |
---|