1 """NDG XACML parsers package
2
3 NERC 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: __init__.py 7955 2011-12-21 18:29:45Z rwilkinson $"
12 import logging
13 log = logging.getLogger(__name__)
14 from abc import ABCMeta, abstractmethod
15
16 from ndg.xacml import XacmlError
17 from ndg.xacml.core import XacmlCoreBase
21 """XACML package XML Parsing error"""
22
25 """Abstract base class for XACML reader"""
26 __metaclass__ = ABCMeta
27
28 @classmethod
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
39 """Abstract Parse XACML method
40 @raise NotImplementedError:
41 """
42 raise NotImplementedError()
43
44 @classmethod
45 - def parse(cls, obj, common):
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, common)
54
57 """Abstract base class XACML reader factory"""
58 __metaclass__ = ABCMeta
59
60 @classmethod
61 @abstractmethod
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))
72