1 | """NDG XACML parsers package |
---|
2 | |
---|
3 | NERC 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: $" |
---|
12 | import logging |
---|
13 | log = logging.getLogger(__name__) |
---|
14 | from abc import ABCMeta, abstractmethod |
---|
15 | |
---|
16 | from xml.etree import ElementTree |
---|
17 | |
---|
18 | |
---|
19 | class 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) |
---|