1. hozn
  2. stompclient
  3. Issues
Issue #4 open

Patch for Python 3.x support using 2to3

created an issue

[See attached .txt for a correctly layed out version of this text]

The attached patch modifies stompclient so that it will work with python after applying 2to3.

This patch was tested with both Python 2.6 & 3.1.

I had some decision to take with what should be string and byte in a Frame: - Command, headers' keys and values are strings (ascii) - Body is always a bytes, but will be converted automatically from string to bytes using the ascii encoding (=> the example works with no change).

Those decisions limited the amounts of changes to make which are mostly are packing/unpacking of the Frame. It also ensures that the user can pass string as queue name for example, which IMHO seems more intuitive.

Portability is achieved by introducing some portability functions (in the new module py3kutil): - as_bytes (usually aliased to 'b' on import): used to wrap bytes literal. - as_ascii_string: to convert a bytes in a string (typically used when unpacking the Frame) - format_bytes: replace '%' operator for bytes

The following changes were also made: - connection.send(frame) is always called with a Frame instance (it was sometime called with bytes). - Frame.pack() is used to obtain the serialized bytes of the frame. str(frame) is no longer called, except for logging and testing. - Frame.str returns a string where non ascii data are escaped with \x escape sequence.

Notes that I also introduced the unittests for the py3kutil modules, but those should only be run on Python 3.x (will cause syntax error on python version < 2.6).

Ideally, setup.py should also be modified to automatically call 2to3, but I don’t know how to do that.

Comments (6)

  1. hozn repo owner
    • changed status to open

    Thank you for this patch. I'm sorry that I haven't gotten around to considering it until now; I'll blame a poor notification system on bitbucket. I have been also wondering about the headers in the STOMP context (also for 3.1 version of CoilMQ). I think I agree with your interpretation of the headers (being bytes) and body being bytes (but convertable).

    Thanks for your work on this; I will work to get it incorporated as soon as possible.

  2. blep reporter

    Notes: you may want to update your e-mail in PyPi. I tried to contact you by mail back in January but got a 'user does not exist' message or something like that.

  3. Log in to comment