예제 #1
0
파일: wsdl2py.py 프로젝트: caot/soaplib
def handle_portType(pt):
    operations = pt.findall(qn('wsdl', 'operation'))
    for operation in operations:
        name = operation.get('name')
        input = operation.find(qn('wsdl', 'input'))
        in_msg = input.get('message')
        in_name = input.get('name')

        output = operation.find(qn('wsdl', 'output'))
        if output != None:
            out_msg = output.get('message')
            out_name = output.get('name')
        else:
            out_msg = ''
            out_name = ''

        print '*' * 80
        print _messages[in_msg.split(':')[-1]]
        print '  name  ', name
        print '  input ', in_msg, in_name
        print ' output ', out_msg, out_name

        method = MethodDescriptor(name, _messages[in_name],
                                  _messages[out_name])
        _methods[name] = method
예제 #2
0
    def _test_callback(self):
        inputs = [MethodDescriptor('person', Person)]

        client = SimpleSoapClient('127.0.0.1:9191', '/', 'e', inputs, None)
        p = Person()
        p.name = 'wilson'
        r = client(p)
        self.assertEquals(r, None)
예제 #3
0
    def test_simple(self):
        inMessage = Message('a', [('s', String), ('i', Integer)])
        outMessage = Message('aResponse', [('retval', DateTime)])

        desc = MethodDescriptor('a', 'a', inMessage, outMessage, '')

        client = SimpleSoapClient('127.0.0.1:9191', '/', desc)
        results = client('abc', 54)
        self.assertEquals(results, datetime.datetime(1901, 12, 15))
예제 #4
0
        def explainMethod(*args, **kwargs):
            if '_soap_descriptor' in kwargs:
                name = f.func_name

                _returns = kparams.get('_returns')
                _isCallback = kparams.get('_isCallback', False)
                _soapAction = kparams.get('_soapAction', name)
                _isAsync = kparams.get('_isAsync', False)
                _inMessage = kparams.get('_inMessage', name)
                _inVariableNames = kparams.get('_inVariableNames', {})
                _outMessage = kparams.get('_outMessage', '%sResponse' % name)
                _outVariableNames = kparams.get('_outVariableNames',
                    kparams.get('_outVariableName', '%sResult' % name))
                _mtom = kparams.get('_mtom', False)

                ns = None

                # the decorator function does not have a reference to the
                # class and needs to be passed in
                if 'klazz' in kwargs:
                    ns = getTNS(kwargs['klazz'])

                # input message
                param_names = f.func_code.co_varnames[
                    1:f.func_code.co_argcount]
                try:
                    in_params = [(_inVariableNames.get(param_names[i],
                                  param_names[i]), params[i])
                                 for i in range(0, len(params))]
                except IndexError:
                    raise Exception("%s has parameter numbers mismatching" % f.func_name)

                in_message = Message(_inMessage, in_params, ns=ns, typ=_inMessage)

                # output message  
                out_params = []
                if _returns:
                    if isinstance(_returns, (list, tuple)):
                        returns = zip(_outVariableNames, _returns)
                        for key, value in returns:
                            out_params.append((key, value))
                    else:
                        out_params = [(_outVariableNames, _returns)]
                else:
                    out_params = []
                out_message = Message(_outMessage, out_params, ns=ns,
                    typ=_outMessage)
                doc = getattr(f, '__doc__')

                descriptor = MethodDescriptor(f.func_name, _soapAction,
                    in_message, out_message, doc, _isCallback, _isAsync,
                    _mtom)
                return descriptor
            return f(*args, **kwargs)
예제 #5
0
    def test_async(self):
        inMessage = Message('d', [('person', Person)])
        outMessage = Message('dResponse', [])

        desc = MethodDescriptor('d', 'd', inMessage, outMessage, '')

        client = SimpleSoapClient('127.0.0.1:9191', '/', desc)
        p = Person()
        p.name = 'wilson'
        r = client(p)
        self.assertEquals(r, None)
예제 #6
0
    def test_fault(self):
        inMessage = Message('fault', [])
        outMessage = Message('faultResponse', [])
        desc = MethodDescriptor('fault', 'fault', inMessage, outMessage, '')

        client = SimpleSoapClient('127.0.0.1:9191', '/', desc)
        try:
            client()
        except Fault, f:
            self.assertEquals(f.faultcode, 'faultFault')
            self.assertEquals(f.faultstring, 'Testing faults')
            self.assertTrue(f.detail.find('client_test.py') > -1)
예제 #7
0
    def test_nested(self):
        inMessage = Message('b', [('p', Person), ('s', String),
                                  ('i', Integer)])
        outMessage = Message('bResponse', [('retval', Address)])

        desc = MethodDescriptor('b', 'b', inMessage, outMessage, '')

        client = SimpleSoapClient('127.0.0.1:9191', '/', desc)
        p = Person()
        p.name = 'wilson'
        p.addresses = []
        for i in range(0, 123):
            a = Address()
            a.zip = i
            p.addresses.append(a)
        res = client(p, 'abc', 123)
        self.assertEquals(res.longitude, None)
        self.assertEquals(res.zip, 4444)
        self.assertEquals(res.street, 'wsgi way')
예제 #8
0
        def explainMethod(*args, **kwargs):
            if kwargs.has_key('_soap_descriptor'):
                name = f.func_name
            
                _returns = kparams.get('_returns')
                _isCallback = kparams.get('_isCallback',False)
                _soapAction = kparams.get('_soapAction',name)
                _isAsync = kparams.get('_isAsync',False)
                _inMessage = kparams.get('_inMessage',name)
                _inVariableNames = kparams.get('_inVariableNames',{})
                _outMessage = kparams.get('_outMessage','%sResponse'%name)
                _outVariableName = kparams.get('_outVariableName','retval')
                _mtom = kparams.get('_mtom',False)
                
                ns = None
                # passed in from the _get_soap_methods() call
                # the decorator function does not have a reference to the
                # class and needs to be passed in
                if kwargs.has_key('klazz'):
                    ns = getTNS(kwargs['klazz'])

                # input message
                param_names = f.func_code.co_varnames[1:f.func_code.co_argcount]
                in_params = [(_inVariableNames.get(param_names[i],param_names[i]),params[i]) for i in range(0,len(params))]
                in_message = Message(_inMessage,in_params,ns=ns,typ=_inMessage)
                
                # output message
                if _returns:
                    out_params = [(_outVariableName,_returns)]
                else:
                    out_params = []
                out_message = Message(_outMessage,out_params,ns=ns,typ=_outMessage)
                doc = getattr(f,'__doc__')
                descriptor = MethodDescriptor(f.func_name,_soapAction,in_message,out_message,doc,_isCallback,_isAsync,_mtom)
                
                return descriptor
            return f(*args, **kwargs)