1 """NDG XACML concatenate functions module
2
3 NERC DataGrid
4 """
5 __author__ = "R B Wilkinson"
6 __date__ = "06/02/12"
7 __copyright__ = ""
8 __license__ = "BSD - see LICENSE file in top-level directory"
9 __contact__ = "Philip.Kershaw@stfc.ac.uk"
10 __revision__ = '$Id$'
11 from ndg.xacml.core.attributevalue import AttributeValueClassFactory
12 from ndg.xacml.core.functions import (AbstractFunction,
13 FunctionClassFactoryBase)
14 from ndg.xacml.core.context.exceptions import (XacmlContextError,
15 XacmlContextTypeError)
16
17 attributeValueClassFactory = AttributeValueClassFactory()
18
20 """Base class for XACML <type>-concatenate functions
21
22 @cvar FUNCTION_NS: namespace for this function
23 @type FUNCTION_NS: string
24 @cvar TYPE_REST: type for all but first argument
25 @type TYPE_REST: type
26 """
27 FUNCTION_NS = None
28 TYPE_REST = attributeValueClassFactory(
29 'http://www.w3.org/2001/XMLSchema#string')
30
32 """Perform CONCATENATE function on the variable length argument list of
33 elements
34
35 access_control-xacml-2.0-core-spec-os, Feb 2005 - A.3.9 String functions
36 @param *args: variable number of arguments to be concatenated
37 @type *args: ndg.xacml.utils.TypedList
38
39 @return: result of concatenating the inputs
40 @rtype: type of first argument
41 """
42
43
44
45
46 if len(args) < 2:
47
48 raise XacmlContextError(
49 "Argument list should have length two or greater")
50 else:
51
52 if not isinstance(args[0], self.__class__.TYPE):
53 raise XacmlContextTypeError('Expecting %r derived type for '
54 'argument 1; got %r' %
55 (self.__class__.TYPE,
56 type(args[0])))
57 for n, arg in enumerate(args[1:]):
58 if not isinstance(arg, self.__class__.TYPE_REST):
59 raise XacmlContextTypeError('Expecting %r derived type for '
60 'argument %d; got %r' %
61 (self.__class__.TYPE_REST,
62 n + 1,
63 type(arg)))
64
65 result = ''.join([a.value for a in args])
66 returnValue = self.__class__.TYPE(result)
67 return returnValue
68
69
71 """Class Factory for *-concatenate XACML 2.0 function classes
72
73 @cvar FUNCTION_NAMES: concatenate function URNs
74 @type FUNCTION_NAMES: tuple
75
76 @cvar FUNCTION_NS_SUFFIX: generic suffix for concatenate function URNs
77 @type FUNCTION_NS_SUFFIX: string
78
79 @cvar FUNCTION_BASE_CLASS: base class for all concatenate classes
80 @type FUNCTION_BASE_CLASS: type
81 """
82 FUNCTION_NAMES = (
83 'urn:oasis:names:tc:xacml:2.0:function:string-concatenate',
84 'urn:oasis:names:tc:xacml:2.0:function:url-string-concatenate'
85 )
86 FUNCTION_NS_SUFFIX = '-concatenate'
87 FUNCTION_BASE_CLASS = ConcatenateBase
88