mosquito / aiohttp-xmlrpc

XMLRPC for aiohttp
MIT License
34 stars 19 forks source link

kwargs parsing seems incorrect #21

Closed bohui closed 4 years ago

bohui commented 6 years ago

Hi,

This is a great project and exactly what I am looking for. However when I did some test on server code, it responds inconsistently with python native xmlrpc library. Here is my parameter:

<param>
    <value>
        <i4>100</i4>
    </value>
</param>
<param>
    <value>
        <i4>200</i4>
    </value>
</param>
<param>
    <value>
        <struct>
            <member>
                <name>key1</name>
                <value>
                    <i4>1</i4>
                </value>
            </member>
            <member>
                <name>key2</name>
                <value>
                    <i4>2</i4>
                </value>
            </member>
        </struct>
    </value>
</param>

aiohttp-xmlrpc will parse it as one argument list with 2 elements(100 and 200) and one named argument with 2 keys(key1 and key2), while python3's native xmlrpc will parse it as one argument list with 3 elements ((100, 200, {'key1': 1, 'key2': 2})) Here is the code I use for native xmlrpc:

from xmlrpc.server import SimpleXMLRPCServer

def ping():
    return 'Pong'

def echo( *args, **kwargs):
    return (args, kwargs)

def test():
    return None

def args(*args):
    return len(args)

def kwargs(**kwargs):
    return len(kwargs)

def args_kwargs(*args, **kwargs):
    print(args)
    print(kwargs)
    return len(args) + len(kwargs)

def exception():
    raise Exception("YEEEEEE!!!")

server = SimpleXMLRPCServer(("localhost", 8080),allow_none=True)
print("Listening on port 8080...")
server.register_function(ping, "ping")
server.register_function(echo, "echo")
server.register_function(test, "test")
server.register_function(args, "args")
server.register_function(kwargs, "kwargs")
server.register_function(args_kwargs, "args_kwargs")

server.serve_forever()

server on aiohttp-xmlrpc one:

from aiohttp import web
from aiohttp_xmlrpc import handler

class XMLRPCExample(handler.XMLRPCView):
    def rpc_ping(self):
        return 'Pong'

    def rpc_echo(self, *args, **kwargs):
        return (args, kwargs)

    def rpc_test(self):
        return None

    def rpc_args(self, *args):
        return len(args)

    def rpc_kwargs(self, **kwargs):
        return len(kwargs)

    def rpc_args_kwargs(self, *args, **kwargs):
        print(args)
        print(kwargs)
        return len(args) + len(kwargs)

    def rpc_exception(self):
        raise Exception("YEEEEEE!!!")

def start_server():
    app = web.Application()
    app.router.add_route('*', '/', XMLRPCExample)
    web.run_app(app)

if __name__ == "__main__":
    start_server()

I called the same method of args_kwargs on client side. But results are 4 for aiohttp-xmlrpc and 3 for xmlrpc. (BTW, I use https://xmlrpc.devzing.com/ tool to call rpc service which is running locally and tunnelled by ngork).

I think xmlrpc is doing the right way. Maybe there are some configurations I missed or some tests I did incorrectly?

mgrrx commented 4 years ago

I have the same problem. If I remove the lines here https://github.com/mosquito/aiohttp-xmlrpc/blob/master/aiohttp_xmlrpc/handler.py#L90-L93 and simpy calling the methods without kwargs. From what I can see in the native xmlrpc library kwargs are simply not supported and should be removed?

mosquito commented 4 years ago

Fixed in 1.0.0

mgrrx commented 4 years ago

Thanks, works like a charm!