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

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

Added more !ETree readers for the different types.

RevLine 
[6740]1"""NDG XACML parsers package
[6734]2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "15/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: $"
12import logging
13log = logging.getLogger(__name__)
14from abc import ABCMeta, abstractmethod
15
[6746]16from ndg.xacml import XACMLError
17 
18   
19class XMLParseError(XACMLError):
20    """XACML package XML Parsing error"""
[6734]21
22
23class AbstractReader:
24    """Abstract base class for ElementTree implementation of XACML reader"""
25    __metaclass__ = ABCMeta
26   
27    @classmethod
28    def __subclasshook__(cls, C):
29        """Derived class must implement __call__"""
30        if cls is AbstractReader:
31            if any("__call__" in B.__dict__ for B in C.__mro__):
32                return True
33           
34        return NotImplemented
35       
36    @abstractmethod
37    def __call__(self, obj):
38        """Abstract Parse XACML method
39        @raise NotImplementedError:
40        """
41        raise NotImplementedError()
42   
43    @classmethod
44    def parse(cls, obj):
45        """Parse from input object and return new XACML object
46        @param obj: input source - file name, stream object or other
47        @type obj: string, stream or other
48        @return: new XACML object
49        @rtype: PolicyComponent sub type
50        """
51        reader = cls()
52        return reader(obj)
Note: See TracBrowser for help on using the repository browser.