Package ndg :: Package xacml :: Package core :: Module expression
[hide private]

Source Code for Module ndg.xacml.core.expression

 1  """NDG Security Expression type definition 
 2   
 3  NERC DataGrid 
 4  """ 
 5  __author__ = "P J Kershaw" 
 6  __date__ = "25/02/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: expression.py 8010 2012-01-30 16:24:06Z rwilkinson $" 
12  from abc import ABCMeta, abstractmethod 
13   
14  from ndg.xacml.core import XacmlCoreBase 
15 16 17 -class Expression(XacmlCoreBase):
18 """XACML Expression type 19 20 @cvar ELEMENT_LOCAL_NAME: XML local name for this element 21 @type ELEMENT_LOCAL_NAME: string 22 @cvar DATA_TYPE_ATTRIB_NAME: XML attribute name for data type 23 @type DATA_TYPE_ATTRIB_NAME: string 24 25 @ivar __dataType: data type for this expression 26 @type __dataType: None / basestring 27 """ 28 __metaclass__ = ABCMeta 29 ELEMENT_LOCAL_NAME = None 30 DATA_TYPE_ATTRIB_NAME = 'DataType' 31 32 __slots__ = ('__dataType', ) 33
34 - def __init__(self):
35 super(Expression, self).__init__() 36 self.__dataType = None
37
38 - def _get_dataType(self):
39 return self.__dataType
40
41 - def _set_dataType(self, value):
42 if not isinstance(value, basestring): 43 raise TypeError('Expecting %r type for "dataType" ' 44 'attribute; got %r' % (basestring, type(value))) 45 46 self.__dataType = value
47 48 dataType = property(_get_dataType, _set_dataType, None, 49 "expression value data type") 50 51 @abstractmethod
52 - def evaluate(self, context):
53 """Evaluate the result of the expression in a condition. Derived 54 classes must implement 55 56 @param context: the request context 57 @type context: ndg.xacml.core.context.request.Request 58 @return: attribute value(s) resulting from execution of this expression 59 in a condition 60 @rtype: AttributeValue/NoneType 61 """ 62 raise NotImplementedError()
63
64 - def __getstate__(self):
65 '''Enable pickling 66 67 @return: object's attribute dictionary 68 @rtype: dict 69 ''' 70 _dict = super(Expression, self).__getstate__() 71 for attrName in Expression.__slots__: 72 # Ugly hack to allow for derived classes setting private member 73 # variables 74 if attrName.startswith('__'): 75 attrName = "_Expression" + attrName 76 77 _dict[attrName] = getattr(self, attrName) 78 79 return _dict
80