1 """NDG XACML ElementTree based reader for AttributeValue 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: attributevaluereader.py 7955 2011-12-21 18:29:45Z rwilkinson $"
12 from ndg.xacml.core.attributevalue import (AttributeValue,
13 AttributeValueClassFactory)
14 from ndg.xacml.parsers import XMLParseError
15 from ndg.xacml.parsers.etree import QName
16 from ndg.xacml.parsers.etree.expressionreader import ExpressionReader
17 from ndg.xacml.utils import VettedDict
21 '''ElementTree based XACML AttributeValue type parser
22
23 @cvar TYPE: XACML class type that this reader will read values into
24 @type TYPE: abc.ABCMeta
25
26 @cvar FACTORY: factory function for returning an Attribute value type for a
27 given XACML Attribute value URI
28 @type FACTORY: ndg.xacml.core.attributevalue.AttributeValueClassFactory
29 '''
30 TYPE = AttributeValue
31 FACTORY = AttributeValueClassFactory()
32
73
75 """Parse XML Attribute value element
76
77 @param elem: ElementTree XML element
78 @type elem: xml.etree.Element
79
80 @param attributeValue: attribute selector to be updated with parsed
81 values
82 @type attributeValue: ndg.xacml.core.attributevalue.AttributeValue
83
84 @raise XMLParseError: error parsing attribute ID XML attribute
85 """
86 reader = DataTypeReaderClassFactory.getReader(attributeValue)
87 reader.parse(elem, attributeValue)
88
91 @classmethod
92 - def parse(cls, elem, attributeValue):
98
101 """Specialised dictionary to hold mappings of XACML AttributeValue DataTypes
102 and their equivalent ElementTree reader classes
103 """
104
113
114 @staticmethod
116 """Enforce string type keys for Attribute Value DataType URIs
117
118 @param key: URN for attribute
119 @type key: basestring
120 @return: boolean True indicating key is OK
121 @rtype: bool
122 @raise TypeError: incorrect input type
123 """
124 if not isinstance(key, basestring):
125 raise TypeError('Expecting %r derived type for key; got %r' %
126 (basestring, type(key)))
127 return True
128
129 @staticmethod
131 """Enforce ElementTree abstract reader derived types for values
132 @param value: attribute value
133 @type value:
134 ndg.xacml.parsers.etree.attributevaluereader.ETreeDataTypeReaderBase to
135 their derived type
136 @return: boolean True indicating attribute value is correct type
137 @rtype: bool
138 @raise TypeError: incorrect input type
139 """
140 if not issubclass(value, ETreeDataTypeReaderBase):
141 raise TypeError('Expecting %r derived type for value; got %r' %
142 (ETreeDataTypeReaderBase, type(value)))
143 return True
144
163