Patch for Python 3.x support using 2to3
[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.