source: TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/subjectreader.py @ 6750

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/subjectreader.py@6750
Revision 6750, 1.7 KB checked in by pjkersha, 9 years ago (diff)

Parsing functionality near complete for rule1.xml

Line 
1"""NDG XACML ElementTree based Subject Element reader
2
3NERC DataGrid Project
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: $"
12from ndg.xacml.core.subject import Subject
13from ndg.xacml.parsers import XMLParseError
14from ndg.xacml.parsers.etree import QName
15from ndg.xacml.parsers.etree.reader import ETreeAbstractReader
16from ndg.xacml.parsers.etree.matchreader import SubjectMatchReader
17
18
19class SubjectReader(ETreeAbstractReader):
20    '''ElementTree based XACML Rule parser
21    @cvar TYPE: XACML type to instantiate from parsed object
22    @type string: type
23    '''
24    TYPE = Subject
25
26    def __call__(self, obj):
27        """Parse subject object"""
28        elem = super(SubjectReader, self)._parse(obj)
29       
30        cls = SubjectReader.TYPE
31        subject = cls()
32       
33        localName = QName.getLocalPart(elem.tag)
34        if localName != cls.ELEMENT_LOCAL_NAME:
35            raise XMLParseError("No \"%s\" element found" % 
36                                cls.ELEMENT_LOCAL_NAME)
37           
38        # Parse match elements
39        for childElem in elem:
40            localName = QName.getLocalPart(childElem.tag)
41           
42            if localName == cls.MATCH_TYPE.ELEMENT_LOCAL_NAME:
43                subject.matches.append(SubjectMatchReader.parse(childElem))
44           
45            else:
46                raise XMLParseError("XACML Subject child element name %r not "
47                                    "recognised" % localName)       
48        return subject
Note: See TracBrowser for help on using the repository browser.