tcalmant / jsonrpclib

A Python (2 & 3) JSON-RPC over HTTP that mirrors the syntax of xmlrpclib (aka jsonrpclib-pelix)
https://jsonrpclib-pelix.readthedocs.io/
Apache License 2.0
54 stars 24 forks source link

Standardize on bytestrings in py3 internally? #3

Closed dgilman closed 11 years ago

dgilman commented 11 years ago

I've started writing a WSGI app for for this library ( https://github.com/dgilman/jsonrpclib/tree/wsgi ) and I've got it working fine under 2.7. I'd like some feedback from you as I've never worked with 3.x.

The python3 json.dumps seems to be returning a python3 str and using that internally for lots of things. WSGI wants a bytestring for its data content (and they're 100% correct in their demands there). I can encode() the output of _marshaled_dispatch but there are still plenty of exceptions kicking up from the server and client side of things relating to a mismatch of bytestrings and str strings within jsonrpc.py.

So my question is 'am I on the right track? Do I need to dig through the JSONRPC server code and force it to use bytestrings everywhere in order to get WSGI on 3 working? Would you, the maintainer, be accepting of the change?'

dgilman commented 11 years ago

Actually, ignore all this. I slept on the issue, looked back at it again this morning and realized my encoding errors were my fault - I was encoding json going out but I was just handing bytestrings into the server causing all my errors. Whoops.

tcalmant commented 11 years ago

No problem ;)

FYI, I prefer to work with the str internal type, as it nearly ensures that it will work with both Python 2 and 3. The only thing to do is to convert from and to bytes in Python 3 when working with low-level or I/O APIs. In my other project, iPOPO (https://github.com/tcalmant/ipopo/), I made the pelix/utilities.py module to hide the bytes/str/unicode types.