home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / ZSI / fault.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  8.8 KB  |  248 lines

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