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

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

Added more !ETree readers for the different types.

Line 
1"""NDG XACML core package
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "16/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   
13   
14class PolicyComponent(object):
15    """Base class for Policy and Policy subelements"""
16    XACML_2_0_XMLNS = "urn:oasis:names:tc:xacml:2.0:policy:schema:os"
17
18    __slots__ = ('__xmlns', '__reader', '__writer')
19
20    ELEMENT_LOCAL_NAME = None
21   
22    def __init__(self):
23        self.__xmlns = PolicyComponent.XACML_2_0_XMLNS
24        self.__reader = None
25        self.__writer = None
26       
27    def _getXmlns(self):
28        return self.__xmlns
29
30    def _setXmlns(self, value):
31        if not isinstance(value, basestring):
32            raise TypeError('Expecting string type for "xmlns" '
33                            'attribute; got %r' % type(value))
34        self.__xmlns = value
35
36    xmlns = property(_getXmlns, _setXmlns, 
37                     doc="XML Namespace for policy the document")
38   
39    @property
40    def isValidXmlns(self):
41        return self.xmlns in PolicyComponent.XMLNS
42
43    def read(self, obj):
44        """Read using callable assinged to reader property"""
45        if self.__reader is None:
46            raise AttributeError('No reader set for %r' % self.__class__)
47       
48        self.__reader(self, obj)
49
50    @classmethod
51    def Read(cls, obj):
52        """Construct a new Policy""" 
53        xacmlObj = cls()
54        xacmlObj.read(obj)
55        return xacmlObj
56   
57    def write(self, obj):
58        """Read using callable assinged to reader property"""
59        if self.__writer is None:
60            raise AttributeError('No writer set for %r' % self.__class__)
61       
62        self.__writer(self, obj)
63       
64           
65class RequestPropertyBase(PolicyComponent):
66    """Base type for Subject, Resource, Action and Environment types"""
67    MATCH_TYPE = None
68   
69    __slots__ = ('__matches', )
70   
71    def __init__(self):
72        # Derived types can specify the type for matches via the MATCH_TYPE
73        # class variable
74        self.__matches = TypedList(self.__class__.MATCH_TYPE)
75       
76    @property
77    def matches(self):
78        return self.__matches
Note: See TracBrowser for help on using the repository browser.