Esempio n. 1
0
                def get_output_message(ns):
                    _returns = kparams.get('_returns')

                    _out_message = kparams.get('_out_message', '%sResponse' %
                                                                    f.func_name)

                    kparams.get('_out_variable_name')
                    out_params = TypeInfo()

                    if _returns:
                        if isinstance(_returns, (list, tuple)):
                            default_names = ['%sResult%d' % (f.func_name, i)
                                                  for i in range(len(_returns))]

                            _out_variable_names = kparams.get(
                                        '_out_variable_names', default_names)

                            assert (len(_returns) == len(_out_variable_names))

                            var_pair = zip(_out_variable_names,_returns)
                            out_params = TypeInfo(var_pair)

                        else:
                            _out_variable_name = kparams.get(
                                 '_out_variable_name', '%sResult' % f.func_name)

                            out_params[_out_variable_name] = _returns

                    message=Message.produce(type_name=_out_message,namespace=ns,
                                                             members=out_params)
                    message.__namespace__ = ns
                    message.resolve_namespace(message, ns)
                    return message
Esempio n. 2
0
    def test_to_xml_nested(self):
        m = Message.produce(
            namespace=None,
            type_name='myMessage',
            members={'p':Person}
        )

        m.resolve_namespace(m,"m")

        p = Person()
        p.name = 'steve-o'
        p.age = 2
        p.addresses = []

        for i in range(0, 100):
            a = Address()
            a.street = '123 happy way'
            a.zip = i
            a.laditude = '45.22'
            a.longitude = '444.234'
            p.addresses.append(a)

        m_inst = m(p=p)

        element=etree.Element('test')
        m.to_xml(m_inst,m.get_namespace(),element)
        element=element[0]

        #print etree.tostring(element, pretty_print=True)
        self.assertEquals('{%s}myMessage' % m.get_namespace(), element.tag)

        addresses = element.getchildren()[0].find('{%s}addresses' % m.get_namespace()).getchildren()
        self.assertEquals(100, len(addresses))
        self.assertEquals('0', addresses[0].find('{%s}zip' % m.get_namespace()).text)
Esempio n. 3
0
    def test_class_to_xml(self):
        m = Message.produce(
            namespace=None,
            type_name='myMessage',
            members={'p': Person}
        )

        m.resolve_namespace(m,"punk")

        m_inst = m()
        m_inst.p = Person()
        m_inst.p.name = 'steve-o'
        m_inst.p.age = 2
        m_inst.p.addresses = []

        element=etree.Element('test')
        m.to_xml(m_inst,m.get_namespace(),element)
        element=element[0]

        self.assertEquals(element.tag, '{%s}myMessage' % m.get_namespace())
        self.assertEquals(element.getchildren()[0].find('{%s}name' % m.get_namespace()).text,
            'steve-o')
        self.assertEquals(element.getchildren()[0].find('{%s}age' % m.get_namespace()).text, '2')
        self.assertEquals(
            len(element.getchildren()[0].find('{%s}addresses' % m.get_namespace()).getchildren()), 0)

        p1 = m.from_xml(element)[0]

        self.assertEquals(p1.name, m_inst.p.name)
        self.assertEquals(p1.age, m_inst.p.age)
        self.assertEquals(p1.addresses, [])
Esempio n. 4
0
    def test_namespaces(self):
        m = Message.produce(
            namespace="some_namespace",
            type_name='myMessage',
            members={'s': String, 'i': Integer},
        )

        mi = m()
        mi.s = 'a'

        e = etree.Element('test')
        m.to_xml(mi,m.get_namespace(),e)
        e=e[0]

        self.assertEquals(e.tag, '{some_namespace}myMessage')
Esempio n. 5
0
    def test_simple_message(self):
        m = Message.produce(
            namespace=None,
            type_name='myMessage',
            members={'s': String, 'i': Integer}
        )
        m.resolve_namespace(m,'test')

        m_inst = m(s="a", i=43)

        e = etree.Element('test')
        m.to_xml(m_inst,m.get_namespace(),e)
        e=e[0]
        
        self.assertEquals(e.tag, '{%s}myMessage' % m.get_namespace())

        self.assertEquals(e.find('{%s}s' % m.get_namespace()).text, 'a')
        self.assertEquals(e.find('{%s}i' % m.get_namespace()).text, '43')

        values = m.from_xml(e)

        self.assertEquals('a', values.s)
        self.assertEquals(43, values.i)
Esempio n. 6
0
        def explain_method(*args, **kwargs):
            if '_method_descriptor' in kwargs:
                # input message
                def get_input_message(ns):
                    _in_message = kparams.get('_in_message', f.func_name)
                    _in_variable_names = kparams.get('_in_variable_names', {})

                    arg_count = f.func_code.co_argcount
                    param_names = f.func_code.co_varnames[1:arg_count]

                    try:
                        in_params = TypeInfo()

                        for i in range(len(params)):
                            e0 = _in_variable_names.get(param_names[i],
                                                                 param_names[i])
                            e1 = params[i]

                            in_params[e0] = e1

                    except IndexError, e:
                        raise Exception("%s has parameter numbers mismatching" %
                                                                    f.func_name)

                    message=Message.produce(type_name=_in_message, namespace=ns,
                                                            members=in_params)
                    message.__namespace__ = ns
                    message.resolve_namespace(message, ns)
                    return message

                def get_output_message(ns):
                    _returns = kparams.get('_returns')

                    _out_message = kparams.get('_out_message', '%sResponse' %
                                                                    f.func_name)

                    kparams.get('_out_variable_name')
                    out_params = TypeInfo()

                    if _returns:
                        if isinstance(_returns, (list, tuple)):
                            default_names = ['%sResult%d' % (f.func_name, i)
                                                  for i in range(len(_returns))]

                            _out_variable_names = kparams.get(
                                        '_out_variable_names', default_names)

                            assert (len(_returns) == len(_out_variable_names))

                            var_pair = zip(_out_variable_names,_returns)
                            out_params = TypeInfo(var_pair)

                        else:
                            _out_variable_name = kparams.get(
                                 '_out_variable_name', '%sResult' % f.func_name)

                            out_params[_out_variable_name] = _returns

                    message=Message.produce(type_name=_out_message,namespace=ns,
                                                             members=out_params)
                    message.__namespace__ = ns
                    message.resolve_namespace(message, ns)
                    return message

                _is_callback = kparams.get('_is_callback', False)
                _public_name = kparams.get('_public_name', f.func_name)
                _is_async = kparams.get('_is_async', False)
                _mtom = kparams.get('_mtom', False)
                _in_header = kparams.get('_in_header', None)
                _out_header = kparams.get('_out_header', None)

                # the decorator function does not have a reference to the
                # class and needs to be passed in
                ns = kwargs['clazz'].get_tns()

                in_message = get_input_message(ns)
                out_message = get_output_message(ns)

                if not (_in_header is None):
                    _in_header.resolve_namespace(_in_header, ns)
                if not (_out_header is None):
                    _out_header.resolve_namespace(_out_header, ns)

                doc = getattr(f, '__doc__')
                descriptor = MethodDescriptor(f.func_name, _public_name,
                        in_message, out_message, doc, _is_callback, _is_async,
                        _mtom, _in_header, _out_header)

                return descriptor