Package ndg :: Package xacml :: Package core :: Package context
[hide private]

Source Code for Package ndg.xacml.core.context

 1  """NDG XACML context package defines classes for types in the access control 
 2  context schema 
 3   
 4  NERC DataGrid 
 5  """ 
 6  __author__ = "P J Kershaw" 
 7  __date__ = "24/03/10" 
 8  __copyright__ = "(C) 2010 Science and Technology Facilities Council" 
 9  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
10  __license__ = "BSD - see LICENSE file in top-level directory" 
11  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
12  __revision__ = "$Id: __init__.py 8010 2012-01-30 16:24:06Z rwilkinson $" 
13  from ndg.xacml.utils import TypedList 
14  from ndg.xacml.core import XacmlCoreBase 
15  from ndg.xacml.core.attribute import Attribute 
16 17 18 -class XacmlContextBase(XacmlCoreBase):
19 """Base class for XACML Request and Response types 20 21 @cvar ELEMENT_LOCAL_NAME: XML local element name, derived classes should 22 set 23 @type ELEMENT_LOCAL_NAME: None""" 24 XACML_2_0_CONTEXT_NS = XacmlCoreBase.XACML_2_0_NS_PREFIX + ':context:schema:os' 25 XACML_2_0_CONTEXT_NS_PREFIX = 'xacml-context' 26 27 ELEMENT_LOCAL_NAME = None 28 __slots__ = () 29
30 - def __init__(self):
31 """ELEMENT_LOCAL_NAME check makes this class virtual - derived classes 32 must override this method and set ELEMENT_LOCAL_NAME to the appropriate 33 string 34 """ 35 super(XacmlContextBase, self).__init__() 36 if self.__class__.ELEMENT_LOCAL_NAME is None: 37 raise NotImplementedError('Set "ELEMENT_LOCAL_NAME" in a derived ' 38 'type')
39
40 - def __getstate__(self):
41 '''Enable pickling 42 43 @return: object's attribute dictionary 44 @rtype: dict 45 ''' 46 _dict = super(XacmlContextBase, self).__getstate__() 47 for attrName in XacmlContextBase.__slots__: 48 # Ugly hack to allow for derived classes setting private member 49 # variables 50 if attrName.startswith('__'): 51 attrName = "_XacmlContextBase" + attrName 52 53 _dict[attrName] = getattr(self, attrName) 54 55 return _dict
56
57 - def __setstate__(self, attrDict):
58 '''Explicit implementation needed with __slots__''' 59 for attr, val in attrDict.items(): 60 setattr(self, attr, val)
61
62 -class RequestChildBase(XacmlContextBase):
63 """Base class for XACML Context Subject, Resource, Action and Environment 64 types 65 66 @ivar __attributes: XACML Context subject attributes 67 @type __attributes: ndg.xacml.utils.TypedList 68 """ 69 __slots__ = ('__attributes', ) 70
71 - def __init__(self):
72 """Initialise attribute list""" 73 super(RequestChildBase, self).__init__() 74 self.__attributes = TypedList(Attribute)
75 76 @property
77 - def attributes(self):
78 """ 79 @return: XACML Context subject attributes 80 @rtype: ndg.xacml.utils.TypedList 81 """ 82 return self.__attributes
83
84 - def __getstate__(self):
85 '''Enable pickling 86 87 @return: object's attribute dictionary 88 @rtype: dict 89 ''' 90 _dict = super(RequestChildBase, self).__getstate__() 91 for attrName in RequestChildBase.__slots__: 92 # Ugly hack to allow for derived classes setting private member 93 # variables 94 if attrName.startswith('__'): 95 attrName = "_RequestChildBase" + attrName 96 _dict[attrName] = getattr(self, attrName) 97 return _dict
98