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

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

Adding parsing for Subject type and SubjectMatch? elements.

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    '''
22    def __call__(self, obj):
23        """Parse subject object"""
24        elem = super(SubjectReader, self)._parse(obj)
25       
26        subject = Subject()
27        cls = Subject
28       
29        localName = QName.getLocalPart(elem.tag)
30        if localName != cls.ELEMENT_LOCAL_NAME:
31            raise XMLParseError("No \"%s\" element found" % 
32                                cls.ELEMENT_LOCAL_NAME)
33           
34        # Parse match elements
35        for childElem in elem:
36            localName = QName.getLocalPart(childElem.tag)
37           
38            if localName == cls.MATCH_TYPE.ELEMENT_LOCAL_NAME:
39                subject.matches.append(SubjectMatchReader.parse(childElem))
40           
41            else:
42                raise XMLParseError("XACML Subject child element name %r not "
43                                    "recognised" % localName)       
44        return subject
Note: See TracBrowser for help on using the repository browser.