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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/__init__.py@6740
Revision 6740, 1.4 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 parsers package
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
16from xml.etree import ElementTree
17
18
19class AbstractReader:
20    """Abstract base class for ElementTree implementation of XACML reader"""
21    __metaclass__ = ABCMeta
22   
23    @classmethod
24    def __subclasshook__(cls, C):
25        """Derived class must implement __call__"""
26        if cls is AbstractReader:
27            if any("__call__" in B.__dict__ for B in C.__mro__):
28                return True
29           
30        return NotImplemented
31       
32    @abstractmethod
33    def __call__(self, obj):
34        """Abstract Parse XACML method
35        @raise NotImplementedError:
36        """
37        raise NotImplementedError()
38   
39    @classmethod
40    def parse(cls, obj):
41        """Parse from input object and return new XACML object
42        @param obj: input source - file name, stream object or other
43        @type obj: string, stream or other
44        @return: new XACML object
45        @rtype: PolicyComponent sub type
46        """
47        reader = cls()
48        return reader(obj)
Note: See TracBrowser for help on using the repository browser.