Package ndg :: Package xacml :: Package parsers :: Package etree :: Module policydefaultsreader
[hide private]

Source Code for Module ndg.xacml.parsers.etree.policydefaultsreader

 1  """NDG XACML ElementTree based reader for PolicyDefaults type 
 2   
 3  NERC 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: policydefaultsreader.py 7986 2012-01-13 11:39:34Z rwilkinson $" 
12  from ndg.xacml.core.policydefaults import PolicyDefaults 
13  from ndg.xacml.parsers import XMLParseError 
14  from ndg.xacml.parsers.etree import QName 
15  from ndg.xacml.parsers.etree.reader import ETreeAbstractReader 
16   
17   
18 -class PolicyDefaultsReader(ETreeAbstractReader):
19 '''ElementTree based XACML PolicyDefaults type parser 20 21 @cvar TYPE: XACML class type that this reader will read values into 22 @type TYPE: type 23 ''' 24 TYPE = PolicyDefaults 25
26 - def __call__(self, obj, common):
27 """Parse Policy defaults object 28 29 @param obj: input object to parse 30 @type obj: ElementTree Element, or stream object 31 @param common: parsing common data 32 @type common: from ndg.xacml.parsers.common.Common 33 @return: new XACML expression instance 34 @rtype: ndg.xacml.core.policydefaults.PolicyDefaults derived type 35 @raise XMLParseError: error reading element 36 """ 37 elem = super(PolicyDefaultsReader, self)._parse(obj) 38 39 xacmlType = self.__class__.TYPE 40 policyDefaults = xacmlType() 41 42 localName = QName.getLocalPart(elem.tag) 43 if localName != xacmlType.ELEMENT_LOCAL_NAME: 44 raise XMLParseError("No \"%s\" element found" % 45 xacmlType.ELEMENT_LOCAL_NAME) 46 47 if len(elem) != 1: 48 raise XMLParseError('Expecting a single child element for ' 49 'PolicyDefaults element') 50 51 if (QName.getLocalPart(elem[0].tag) != 52 xacmlType.XPATH_VERSION_ELEMENT_NAME): 53 raise XMLParseError('Expecting a %r child element for ' 54 'PolicyDefaults element' % 55 xacmlType.XPATH_VERSION_ELEMENT_NAME) 56 57 xpathVersion = elem[0].text 58 if xpathVersion is None: 59 raise XMLParseError('No %r child element value set for ' 60 'PolicyDefaults element' % 61 xacmlType.XPATH_VERSION_ELEMENT_NAME) 62 63 policyDefaults.xpathVersion = xpathVersion 64 65 return policyDefaults
66