source: TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/__init__.py @ 7087

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

Incomplete - task 2: XACML-Security Integration

  • updating epydoc ready for release.
  • Property svn:keywords set to Id
Line 
1"""NDG XACML parsers package
2
3NERC DataGrid
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 ndg.xacml import XacmlError
17from ndg.xacml.core import XacmlCoreBase
18
19   
20class XMLParseError(XacmlError):
21    """XACML package XML Parsing error"""
22
23
24class AbstractReader(object):
25    """Abstract base class for XACML reader"""
26    __metaclass__ = ABCMeta
27   
28    @classmethod
29    def __subclasshook__(cls, C):
30        """Derived class must implement __call__"""
31        if cls is AbstractReader:
32            if any("__call__" in B.__dict__ for B in C.__mro__):
33                return True
34           
35        return NotImplemented
36       
37    @abstractmethod
38    def __call__(self, obj):
39        """Abstract Parse XACML method
40        @raise NotImplementedError:
41        """
42        raise NotImplementedError()
43   
44    @classmethod
45    def parse(cls, obj):
46        """Parse from input object and return new XACML object
47        @param obj: input source - file name, stream object or other
48        @type obj: string, stream or other
49        @return: new XACML object
50        @rtype: XacmlCoreBase sub type
51        """
52        reader = cls()
53        return reader(obj)
54   
55   
56class AbstractReaderFactory(object):
57    """Abstract base class XACML reader factory"""
58    __metaclass__ = ABCMeta
59   
60    @classmethod
61    @abstractmethod
62    def getReader(cls, xacmlType):
63        """Get the reader class for the given XACML input type
64        @param xacmlType: XACML type to retrieve a reader for
65        @type xacmlType: ndg.xaml.core.XacmlCoreBase derived
66        @return: reader class
67        @rtype: ndg.xacml.parsers.AbstractReader derived type
68        """
69        if not issubclass(xacmlType, XacmlCoreBase):
70            raise TypeError('Expecting %r derived class for getReader method; '
71                            'got %r' % (XacmlCoreBase, xacmlType))
Note: See TracBrowser for help on using the repository browser.