source: TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/targetreader.py @ 6740

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/targetreader.py@6740
Revision 6740, 2.1 KB checked in by pjkersha, 10 years ago (diff)
  • fixed import paths changing to new ndg.xacml
  • added unit test package
Line 
1"""NDG XACML ElementTree based Target 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 import XMLParseError
13from ndg.xacml.target import Target
14from ndg.xacml.action import Action
15from ndg.xacml.resource import Resource
16from ndg.xacml.subject import Subject
17from ndg.xacml.environment import Environment
18from ndg.xacml.parsers.etree import QName
19from ndg.xacml.parsers.etree.reader import \
20    EtreeAbstractReader
21
22
23class TargetReader(EtreeAbstractReader):
24    """ElementTree based parser for XACML Target elements"""
25   
26    def __call__(self, obj):
27        elem = super(TargetReader, self)._parse(obj)
28       
29        target = Target()
30        cls = Target
31       
32        localName = QName.getLocalPart(elem.tag)
33        if localName != cls.ELEMENT_LOCAL_NAME:
34            raise XMLParseError('No "%s" element found' % 
35                                cls.ELEMENT_LOCAL_NAME)
36                   
37        # Parse sub-elements
38        for childElem in elem:
39            localName = QName.getLocalPart(childElem.tag)
40           
41            if localName == Subject.ELEMENT_LOCAL_NAME:
42                target.subjects.append(SubjectReader.parse(childElem))
43                               
44            elif localName == Resource.ELEMENT_LOCAL_NAME:
45                target.resources.append(ResourceReader.parse(childElem))
46               
47            elif localName == Action.ELEMENT_LOCAL_NAME:
48                target.actions.append(ActionReader.parse(childElem))
49               
50            elif localName == Environment.ELEMENT_LOCAL_NAME:
51                target.environments.append(EnvironmentReader.parse(childElem))
52               
53            else:
54                raise XMLParseError("XACML Target child element name %r not "
55                                    "recognised" % localName)     
56               
57        return target
Note: See TracBrowser for help on using the repository browser.