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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/policydefaultsreader.py@7109
Revision 7109, 2.4 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 based reader for PolicyDefaults type
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.core.policydefaults import PolicyDefaults
13from ndg.xacml.parsers import XMLParseError
14from ndg.xacml.parsers.etree import QName
15from ndg.xacml.parsers.etree.reader import ETreeAbstractReader
16
17
18class 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):
27        """Parse Policy defaults object
28       
29        @param obj: input object to parse
30        @type obj: ElementTree Element, or stream object
31        @return: new XACML expression instance
32        @rtype: ndg.xacml.core.policydefaults.PolicyDefaults derived type
33        @raise XMLParseError: error reading element               
34        """
35        elem = super(PolicyDefaultsReader, self)._parse(obj)
36       
37        xacmlType = self.__class__.TYPE
38        policyDefaults = xacmlType()
39       
40        localName = QName.getLocalPart(elem.tag)
41        if localName != xacmlType.ELEMENT_LOCAL_NAME:
42            raise XMLParseError("No \"%s\" element found" % 
43                                xacmlType.ELEMENT_LOCAL_NAME)
44       
45        if len(elem) != 1:
46            raise XMLParseError('Expecting a single child element for '
47                                'PolicyDefaults element')
48           
49        if (QName.getLocalPart(elem[0].tag) != 
50            xacmlType.XPATH_VERSION_ELEMENT_NAME):
51            raise XMLParseError('Expecting a %r child element for '
52                                'PolicyDefaults element' % 
53                                xacmlType.XPATH_VERSION_ELEMENT_NAME)
54       
55        xpathVersion = elem[0].text
56        if xpathVersion is None:
57            raise XMLParseError('No %r child element value set for '
58                                'PolicyDefaults element' % 
59                                xacmlType.XPATH_VERSION_ELEMENT_NAME) 
60             
61        policyDefaults.xpathVersion = xpathVersion
62       
63        return policyDefaults
64
65
Note: See TracBrowser for help on using the repository browser.