Exemplo n.º 1
0
    def serialize(self, sw, pyobj, name=None, attrtext='', orig=None, **kw):
        objid = _get_object_id(pyobj)
        n = name or self.oname or ('E' + objid)
        if type(pyobj) in _seqtypes:
            print >>sw, '<%s%s href="%s"/>' % (n, attrtext, pyobj[0])
            return
        if not self.unique and sw.Known(orig or pyobj):
            print >>sw, '<%s%s href="#%s"/>' % (n, attrtext, objid)
            return
        if type(pyobj) == types.UnicodeType: pyobj = pyobj.encode('utf-8')
        if kw.get('typed', self.typed):
            if self.tag and self.tag.find(':') != -1:
                tstr = ' xsi:type="%s"' % self.tag
            else:
                tstr = ' xsi:type="xsd:%s"' % (self.tag or 'string')
        else:
            tstr = ''
        if self.unique:
            idstr = ''
        else:
            idstr = ' id="%s"' % objid
        if self.textprotect: pyobj = _textprotect(pyobj)

        # ignore the xmlns if it was explicitly stated
        i = n.find('xmlns')
        if i > 0:
            ctag = '</%s>' % n[:i - 1]
        else:
            ctag = '</%s>' % n

        print >>sw, \
            '<%s%s%s%s>%s%s' % (n, attrtext, idstr, tstr, pyobj, ctag)
Exemplo n.º 2
0
def FaultFromZSIException(ex, actor=None):
    '''Return a Fault object created from a ZSI exception object.
    '''
    mystr = getattr(ex, 'str') or str(ex)
    mytrace = getattr(ex, 'trace', '') or ''
    elt = '''<ZSI:ParseFaultDetail>
<ZSI:string>%s</ZSI:string>
<ZSI:trace>%s</ZSI:trace>
</ZSI:ParseFaultDetail>
''' % (_textprotect(mystr), _textprotect(mytrace))
    if getattr(ex, 'inheader', 0):
        detail, headerdetail = None, elt
    else:
        detail, headerdetail = elt, None
    return Fault(Fault.Client, 'Unparseable message',
                actor, detail, headerdetail)
Exemplo n.º 3
0
def FaultFromException(ex, inheader, tb=None, actor=None):
    '''Return a Fault object created from a Python exception.
    '''
    if tb:
        try:
            lines = '\n'.join(['%s:%d:%s' % (name, line, func)
                        for name, line, func, text in traceback.extract_tb(tb)])
            tracetext = '<ZSI:trace>\n' + _textprotect(lines) + '</ZSI:trace>\n'
        except:
            tracetext = ''
    else:
        tracetext = ''

    elt = '''<ZSI:FaultDetail>
<ZSI:string>%s</ZSI:string>
%s</ZSI:FaultDetail>
''' % ( _textprotect(str(ex)), tracetext)
    if inheader:
        detail, headerdetail = None, elt
    else:
        detail, headerdetail = elt, None
    return Fault(Fault.Server, 'Processing Failure',
                actor, detail, headerdetail)
Exemplo n.º 4
0
 def process_headers(self, headers, ps):
     '''Process headers, set self.headertext to be what to output.
     '''
     self.headertext = ''
     for h in headers:
         if h.localName == 'echoMeStringRequest':
             s = TC.String().parse(h, ps)
             self.headertext += \
 '<E:echoMeStringResponse>%s</E:echoMeStringResponse>\n' % _textprotect(s)
         elif h.localName == 'echoMeStructRequest':
             tc = TC_SOAPStruct('echoMeStructRequest', inline=1)
             data = tc.parse(h, ps)
             s = StringIO.StringIO()
             sw = SoapWriter(s, envelope=0)
             tc.serialize(sw, data, name='E:echoMeStructResponse')
             sw.close()
             self.headertext += s.getvalue()
         else:
             raise TypeError('Unhandled header ' + h.nodeName)
     pass
Exemplo n.º 5
0
 def process_headers(self, headers, ps):
     '''Process headers, set self.headertext to be what to output.
     '''
     self.headertext = ''
     for h in headers:
         if h.localName == 'echoMeStringRequest':
             s = TC.String().parse(h, ps)
             self.headertext += \
 '<E:echoMeStringResponse>%s</E:echoMeStringResponse>\n' % _textprotect(s)
         elif h.localName == 'echoMeStructRequest':
             tc = TC_SOAPStruct('echoMeStructRequest', inline=1)
             data = tc.parse(h, ps)
             s = StringIO.StringIO()
             sw = SoapWriter(s, envelope=0)
             tc.serialize(sw, data, name='E:echoMeStructResponse')
             sw.close()
             self.headertext += s.getvalue()
         else:
             raise TypeError('Unhandled header ' + h.nodeName)
     pass