Package ndg :: Package xacml :: Package core :: Package functions :: Package v1 :: Module one_and_only
[hide private]

Source Code for Module ndg.xacml.core.functions.v1.one_and_only

 1  """NDG XACML one and only functions module 
 2   
 3  NERC DataGrid 
 4  """ 
 5  __author__ = "P J Kershaw" 
 6  __date__ = "01/04/10" 
 7  __copyright__ = "" 
 8  __license__ = "BSD - see LICENSE file in top-level directory" 
 9  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
10  __revision__ = '$Id: one_and_only.py 7087 2010-06-25 11:23:09Z pjkersha $' 
11  #from datetime import datetime, timedelta 
12   
13  from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase 
14  from ndg.xacml.utils import TypedList as Bag 
15  from ndg.xacml.core.context.exceptions import XacmlContextError 
16   
17   
18 -class OneAndOnlyBase(AbstractFunction):
19 """Base class for XACML <type>-one-and-only functions 20 21 @cvar TYPE: attribute type for the given implementation. Derived classes 22 should set appropriately 23 @type TYPE: NoneType 24 """ 25 TYPE = None 26
27 - def evaluate(self, bag):
28 """Check a bag has one element only and return it 29 30 @param bag: bag containing one element 31 @type bag: ndg.xacml.utils.TypedList 32 @return: single item from bag 33 @rtype: dependent on bag type set in derived type 34 """ 35 if not isinstance(bag, Bag): 36 raise XacmlContextError('Expecting %r derived type for "bag"; ' 37 'got %r' % (Bag, type(bag))) 38 39 if bag.elementType != self.__class__.TYPE: 40 raise XacmlContextError('Expecting %r type elements for "bag"; ' 41 'got %r' % 42 (self.__class__.TYPE, bag.elementType)) 43 44 nBagElems = len(bag) 45 if nBagElems != 1: 46 raise XacmlContextError('Expecting single element for %r bag; got ' 47 '%r' % (self.__class__.TYPE, nBagElems)) 48 49 return bag[0]
50 51
52 -class FunctionClassFactory(FunctionClassFactoryBase):
53 """Class Factory for *-one-and-only XACML function classes 54 55 @cvar FUNCTION_NAMES: one and only function URNs 56 @type FUNCTION_NAMES: tuple 57 58 @cvar FUNCTION_NS_SUFFIX: generic suffix for one and only function URNs 59 @type FUNCTION_NS_SUFFIX: string 60 61 @cvar FUNCTION_BASE_CLASS: base class for all one and only function classes 62 @type FUNCTION_BASE_CLASS: ndg.xacml.core.functions.v1.OneAndOnlyBase 63 """ 64 FUNCTION_NAMES = ( 65 'urn:oasis:names:tc:xacml:1.0:function:string-one-and-only', 66 'urn:oasis:names:tc:xacml:1.0:function:boolean-one-and-only', 67 'urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only', 68 'urn:oasis:names:tc:xacml:1.0:function:double-one-and-only', 69 'urn:oasis:names:tc:xacml:1.0:function:time-one-and-only', 70 'urn:oasis:names:tc:xacml:1.0:function:date-one-and-only', 71 'urn:oasis:names:tc:xacml:1.0:function:dateTime-one-and-only', 72 'urn:oasis:names:tc:xacml:1.0:function:anyURI-one-and-only', 73 'urn:oasis:names:tc:xacml:1.0:function:hexBinary-one-and-only', 74 'urn:oasis:names:tc:xacml:1.0:function:base64Binary-one-and-only', 75 'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-one-and-only', 76 'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-one-and-only', 77 'urn:oasis:names:tc:xacml:1.0:function:x500Name-one-and-only', 78 'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-one-and-only' 79 ) 80 FUNCTION_NS_SUFFIX = '-one-and-only' 81 FUNCTION_BASE_CLASS = OneAndOnlyBase
82