/usr/lib/python2.7/dist-packages/ZSI/fault.py is in python-zsi 2.1~a1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | # $Header$
'''Faults.
'''
from ZSI import _copyright, _children, _child_elements, \
_get_idstr, _stringtypes, _seqtypes, _Node, SoapWriter, ZSIException
from ZSI.TCcompound import Struct
from ZSI.TC import QName, URI, String, XMLString, AnyElement, UNBOUNDED
from ZSI.wstools.Namespaces import SOAP, ZSI_SCHEMA_URI
from ZSI.wstools.c14n import Canonicalize
from ZSI.TC import ElementDeclaration
import traceback, cStringIO as StringIO
class Detail:
def __init__(self, any=None):
self.any = any
Detail.typecode = Struct(Detail, [AnyElement(aname='any',minOccurs=0, maxOccurs="unbounded",processContents="lax")], pname='detail', minOccurs=0)
class FaultType:
def __init__(self, faultcode=None, faultstring=None, faultactor=None, detail=None):
self.faultcode = faultcode
self.faultstring= faultstring
self.faultactor = faultactor
self.detail = detail
FaultType.typecode = \
Struct(FaultType,
[QName(pname='faultcode'),
String(pname='faultstring'),
URI(pname=(SOAP.ENV,'faultactor'), minOccurs=0),
Detail.typecode,
AnyElement(aname='any',minOccurs=0, maxOccurs=UNBOUNDED, processContents="lax"),
],
pname=(SOAP.ENV,'Fault'),
inline=True,
hasextras=0,
)
class ZSIHeaderDetail:
def __init__(self, detail):
self.any = detail
ZSIHeaderDetail.typecode =\
Struct(ZSIHeaderDetail,
[AnyElement(aname='any', minOccurs=0, maxOccurs=UNBOUNDED, processContents="lax")],
pname=(ZSI_SCHEMA_URI, 'detail'))
class ZSIFaultDetailTypeCode(ElementDeclaration, Struct):
'''<ZSI:FaultDetail>
<ZSI:string>%s</ZSI:string>
<ZSI:trace>%s</ZSI:trace>
</ZSI:FaultDetail>
'''
schema = ZSI_SCHEMA_URI
literal = 'FaultDetail'
def __init__(self, **kw):
Struct.__init__(self, ZSIFaultDetail, [String(pname=(ZSI_SCHEMA_URI, 'string')),
String(pname=(ZSI_SCHEMA_URI, 'trace'),minOccurs=0),],
pname=(ZSI_SCHEMA_URI, 'FaultDetail'), **kw
)
class ZSIFaultDetail:
def __init__(self, string=None, trace=None):
self.string = string
self.trace = trace
def __str__(self):
if self.trace:
return self.string + '\n[trace: ' + self.trace + ']'
return self.string
def __repr__(self):
return "<%s.ZSIFaultDetail %s>" % (__name__, _get_idstr(self))
ZSIFaultDetail.typecode = ZSIFaultDetailTypeCode()
class URIFaultDetailTypeCode(ElementDeclaration, Struct):
'''
<ZSI:URIFaultDetail>
<ZSI:URI>uri</ZSI:URI>
<ZSI:localname>localname</ZSI:localname>
</ZSI:URIFaultDetail>
'''
schema = ZSI_SCHEMA_URI
literal = 'URIFaultDetail'
def __init__(self, **kw):
Struct.__init__(self, URIFaultDetail,
[String(pname=(ZSI_SCHEMA_URI, 'URI')), String(pname=(ZSI_SCHEMA_URI, 'localname')),],
pname=(ZSI_SCHEMA_URI, 'URIFaultDetail'), **kw
)
class URIFaultDetail:
def __init__(self, uri=None, localname=None):
self.URI = uri
self.localname = localname
URIFaultDetail.typecode = URIFaultDetailTypeCode()
class ActorFaultDetailTypeCode(ElementDeclaration, Struct):
'''
<ZSI:ActorFaultDetail>
<ZSI:URI>%s</ZSI:URI>
</ZSI:ActorFaultDetail>
'''
schema = ZSI_SCHEMA_URI
literal = 'ActorFaultDetail'
def __init__(self, **kw):
Struct.__init__(self, ActorFaultDetail, [String(pname=(ZSI_SCHEMA_URI, 'URI')),],
pname=(ZSI_SCHEMA_URI, 'ActorFaultDetail'), **kw
)
class ActorFaultDetail:
def __init__(self, uri=None):
self.URI = uri
ActorFaultDetail.typecode = ActorFaultDetailTypeCode()
class Fault(ZSIException):
'''SOAP Faults.
'''
Client = "SOAP-ENV:Client"
Server = "SOAP-ENV:Server"
MU = "SOAP-ENV:MustUnderstand"
def __init__(self, code, string,
actor=None, detail=None, headerdetail=None):
if detail is not None and type(detail) not in _seqtypes:
detail = (detail,)
if headerdetail is not None and type(headerdetail) not in _seqtypes:
headerdetail = (headerdetail,)
self.code, self.string, self.actor, self.detail, self.headerdetail = \
code, string, actor, detail, headerdetail
ZSIException.__init__(self, code, string, actor, detail, headerdetail)
def DataForSOAPHeader(self):
if not self.headerdetail: return None
# SOAP spec doesn't say how to encode header fault data.
return ZSIHeaderDetail(self.headerdetail)
def serialize(self, sw):
'''Serialize the object.'''
detail = None
if self.detail is not None:
detail = Detail()
detail.any = self.detail
pyobj = FaultType(self.code, self.string, self.actor, detail)
sw.serialize(pyobj, typed=False)
def AsSOAP(self, **kw):
header = self.DataForSOAPHeader()
sw = SoapWriter(**kw)
self.serialize(sw)
if header is not None:
sw.serialize_header(header, header.typecode, typed=False)
return str(sw)
def __str__(self):
strng = str(self.string) + "\n"
if hasattr(self, 'detail'):
if hasattr(self.detail, '__len__'):
for d in self.detail:
strng += str(d)
else:
strng += str(self.detail)
return strng
def __repr__(self):
return "<%s.Fault at %s>" % (__name__, _get_idstr(self))
AsSoap = AsSOAP
def FaultFromNotUnderstood(uri, localname, actor=None):
detail, headerdetail = None, URIFaultDetail(uri, localname)
return Fault(Fault.MU, 'SOAP mustUnderstand not understood',
actor, detail, headerdetail)
def FaultFromActor(uri, actor=None):
detail, headerdetail = None, ActorFaultDetail(uri)
return Fault(Fault.Client, 'Cannot process specified actor',
actor, detail, headerdetail)
def FaultFromZSIException(ex, actor=None):
'''Return a Fault object created from a ZSI exception object.
'''
mystr = getattr(ex, 'str', None) or str(ex)
mytrace = getattr(ex, 'trace', '')
elt = '''<ZSI:ParseFaultDetail>
<ZSI:string>%s</ZSI:string>
<ZSI:trace>%s</ZSI:trace>
</ZSI:ParseFaultDetail>
''' % (mystr, mytrace)
if getattr(ex, 'inheader', 0):
detail, headerdetail = None, elt
else:
detail, headerdetail = elt, None
return Fault(Fault.Client, 'Unparseable message',
actor, detail, headerdetail)
def FaultFromException(ex, inheader, tb=None, actor=None):
'''Return a Fault object created from a Python exception.
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Processing Failure</faultstring>
<detail>
<ZSI:FaultDetail>
<ZSI:string></ZSI:string>
<ZSI:trace></ZSI:trace>
</ZSI:FaultDetail>
</detail>
</SOAP-ENV:Fault>
'''
tracetext = None
if tb:
try:
lines = '\n'.join(['%s:%d:%s' % (name, line, func)
for name, line, func, text in traceback.extract_tb(tb)])
except:
pass
else:
tracetext = lines
exceptionName = ""
try:
exceptionName = ":".join([ex.__module__, ex.__class__.__name__])
except: pass
elt = ZSIFaultDetail(string=exceptionName + "\n" + str(ex), trace=tracetext)
if inheader:
detail, headerdetail = None, elt
else:
detail, headerdetail = elt, None
return Fault(Fault.Server, 'Processing Failure',
actor, detail, headerdetail)
def FaultFromFaultMessage(ps):
'''Parse the message as a fault.
'''
pyobj = ps.Parse(FaultType.typecode)
if pyobj.detail == None: detailany = None
else: detailany = pyobj.detail.any
return Fault(pyobj.faultcode, pyobj.faultstring,
pyobj.faultactor, detailany)
if __name__ == '__main__': print _copyright
|