1 """SOAP common package for NDG SAML.
2
3 Initially for use with SAML SOAP Bindings. This itself
4 uses ElementTree. This SOAP interface provides an ElementTree interface to
5 support it
6
7 NERC DataGrid Project
8 """
9 __author__ = "P J Kershaw"
10 __date__ = "24/07/09"
11 __copyright__ = "(C) 2009 Science and Technology Facilities Council"
12 __license__ = "http://www.apache.org/licenses/LICENSE-2.0"
13 __contact__ = "Philip.Kershaw@stfc.ac.uk"
14 __revision__ = '$Id: __init__.py 7130 2010-06-30 13:33:07Z pjkersha $'
15 import logging
16 log = logging.getLogger(__name__)
20 """Configuration options
21 @type use_lxml: bool
22 @cvar use_lxml: Controls whether lxml.etree should be imported instead of
23 etree. lxml is required for XPath expressions with conditions.
24 """
25 use_lxml = None
26
54
56 """Base class for SOAP envelope, header and body elements"""
57
58 ELEMENT_PREFIX = "soap11"
59 SOAP11_NS = "http://schemas.xmlsoap.org/soap/envelope/"
60 SOAP12_NS = "http://www.w3.org/2003/05/soap-envelope"
61 DEFAULT_NS = SOAP11_NS
62
63 __slots__ = ()
64
66 raise NotImplementedError()
67
69 raise NotImplementedError()
70
72 raise NotImplementedError()
73
75 raise NotImplementedError()
76
89
98
99
100 -class SOAPBodyBase(SOAPObject):
108
111 """SOAP Fault"""
112
113 DEFAULT_ELEMENT_LOCAL_NAME = "Fault"
114 DEFAULT_ELEMENT_NS = SOAPObject.DEFAULT_NS
115 DEFAULT_ELEMENT_NS_PREFIX = SOAPObject.ELEMENT_PREFIX
116
117 FAULT_CODE_ELEMENT_LOCAL_NAME = "faultcode"
118 FAULT_STRING_ELEMENT_LOCAL_NAME = "faultstring"
119 FAULT_ACTOR_ELEMENT_LOCAL_NAME = "faultactor"
120 DETAIL_ELEMENT_LOCAL_NAME = "detail"
121
122 VERSION_MISMATCH_CODE = "VersionMismatch"
123 MUST_UNDERSTAND_FAULT_CODE = "MustUnderstand"
124 CLIENT_FAULT_CODE = "Client"
125 SERVER_FAULT_CODE = "Server"
126
127 FAULT_CODES = (
128 VERSION_MISMATCH_CODE,
129 MUST_UNDERSTAND_FAULT_CODE,
130 CLIENT_FAULT_CODE,
131 SERVER_FAULT_CODE
132 )
133
134 __slots__ = ("__faultCode", "__faultString", "__faultActor", "__detail")
135
136 - def __init__(self, faultString=None, faultCode=None, faultActor=None,
137 detail=None):
160
162 if not isinstance(value, basestring):
163 raise AttributeError('Expecting string type for "faultCode" '
164 'attribute; got %r' % type(value))
165
166 qnameElems = value.split(':')
167 if len(qnameElems) == 0:
168 raise AttributeError('Expecting Qualified Name for "faultCode" '
169 'attribute; got %r' % value)
170
171 faultCodeFound = [qnameElems[1].startswith(i)
172 for i in self.__class__.FAULT_CODES]
173 if max(faultCodeFound) == False:
174 raise AttributeError('Expecting "faultCode" prefixed with one of '
175 '%r; got %r' % (self.__class__.FAULT_CODES,
176 value))
177
178 self.__faultCode = value
179
182
183 faultCode = property(_getFaultCode, _setFaultCode,
184 doc="Fault Code")
185
187 if not isinstance(value, basestring):
188 raise AttributeError('Expecting string type for "faultString" '
189 'attribute; got %r' % type(value))
190 self.__faultString = value
191
194
195 faultString = property(_getFaultString, _setFaultString,
196 doc="Fault String")
197
200
202 if not isinstance(value, basestring):
203 raise AttributeError('Expecting string type for "faultActor" '
204 'attribute; got %r' % type(value))
205 self.__faultActor = value
206
207 faultActor = property(_getFaultActor, _setFaultActor,
208 doc="Fault Actor")
209
212
214 """No type checking - detail could be an XML element or serialised
215 string content"""
216 self.__detail = value
217
218 detail = property(_getDetail, _setDetail, doc="Fault detail")
219
222 """Base SOAP Exception class"""
223
226 """Raise an exception which also creates a fault object"""
227 SOAP_FAULT_CLASS = SOAPFaultBase
228
229 - def __init__(self, faultString, faultCode, faultActor=None, detail=None):
234
235 @property
237 """Get SOAP fault object"""
238 return self.__fault
239