source: TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/reader.py @ 6746

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

Added more !ETree readers for the different types.

Line 
1'''
2Created on 15 Mar 2010
3
4@author: pjkersha
5'''
6import logging
7log = logging.getLogger(__name__)
8"""NDG XACML ElementTree reader module containing reader base class
9
10NERC DataGrid Project
11"""
12__author__ = "P J Kershaw"
13__date__ = "16/03/10"
14__copyright__ = "(C) 2010 Science and Technology Facilities Council"
15__contact__ = "Philip.Kershaw@stfc.ac.uk"
16__license__ = "BSD - see LICENSE file in top-level directory"
17__contact__ = "Philip.Kershaw@stfc.ac.uk"
18__revision__ = "$Id: $"
19from xml.etree import ElementTree
20
21from ndg.xacml.core import PolicyComponent
22from ndg.xacml.parsers import AbstractReader
23
24
25class ETreeAbstractReader(AbstractReader):
26    """Base class for ElementTree implementation of XACML reader"""
27     
28    def __init__(self):
29        self.__namespace_map_backup = ElementTree._namespace_map.copy()
30        ElementTree._namespace_map[''] = PolicyComponent.XACML_2_0_XMLNS
31       
32    def __del__(self):
33        """Restore original global namespace map"""
34        ElementTree._namespace_map = self.__namespace_map_backup
35   
36    @staticmethod
37    def _parse(obj):
38        """Parse helper method
39        @param obj: input object to parse
40        @type obj: ElementTree Element, or stream object
41        @return: ElementTree element
42        @rtype: xml.etree.Element
43        """
44        if ElementTree.iselement(obj):
45            elem = obj
46        else:
47            # Treat as stream object
48            elem = ElementTree.parse(obj).getroot()
49           
50        return elem
51         
52# Set up new class as an abstract base itself             
53AbstractReader.register(ETreeAbstractReader)
54
55
56class VariableDefinitionReader(object):
57    def __call__(self, obj):
58        pass
Note: See TracBrowser for help on using the repository browser.