Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Python 3.5 Support #34

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Python 3.5 Support #34

wants to merge 14 commits into from

Conversation

hathawsh
Copy link

@hathawsh hathawsh commented Oct 3, 2016

This branch makes txsockjs compatible with Python 3.5 while retaining compatibility with Python 2.7. All qunit tests pass. Note that I added a dependency on the "six" package.

Shane Hathaway added 9 commits September 15, 2016 12:50
Twisted now calls pauseProducing() when it finishes receiving the request.
For txsockjs to continue receiving data from the transport, it now needs to
call resumeProducing().  This should have no effect on earlier versions
of Twisted.
…prepare input for JSON encoding, where the input may be an already encoded JSON message.
…2.99 to suggest 1.3 should be the next version number.
@hathawsh hathawsh changed the title Python 3.5 Python 3.5 Support Oct 3, 2016
@ElementalAlchemist
Copy link
Contributor

ElementalAlchemist commented Nov 2, 2017

I took this PR to try it out. I found that this seems to work not quite fully with how Twisted handles Python 3 connections (or at least txsockjs is passing things in a way that's incompatible with how Twisted passes things through normally).

Here's my situation:

  • Using txsockjs as an endpoint
  • Someone connects using it (over the websocket protocol) and sends a message to the server
  • Twisted passes the message off to txsockjs to handle
  • txsockjs gets hit right in the JsonProtocol.dataReceived
    • dataReceived passes the parsed data (from the JSON parser) to normalize
    • The normalized data (which is str, not bytes), gets passed into the protocol's dataReceived
  • Twisted passes this str (not bytes) right through to my protocol handler's dataReceived, through which it receives bytes (not str) messages normally over non-sockjs connections (as an endpoint specified with just a "tcp:" or "ssl:" prefix to serverFromString as opposed to the "sockjs:" prefix).

I'll keep looking at this and maybe try to fix it, though I've only done minimal prodding on txsockjs so far. I'll keep looking here, too, in case you get it before me.

@hathawsh
Copy link
Author

hathawsh commented Nov 2, 2017 via email

@ElementalAlchemist
Copy link
Contributor

Update: I fixed this for myself by adding a new line that does the encoding to bytes right before line 88 of txsockjs/protocols/websocket.py.
I'll probably want to try doing the encoding more robustly before I attempt to submit, but it's a start, and I have working websockets now.

Thanks for your work getting most of this ported! :)

@hathawsh
Copy link
Author

hathawsh commented Nov 2, 2017

I took a look today and I agree it needs fixing. Now I'm wondering why it's working on my side. I'm going to investigate.

Shane Hathaway added 2 commits November 2, 2017 15:36
…ded bytes (in Python 2 as well).

Also added a test server (echotest.py) that works with the sockjs-protocol test suite. The suite revealed some issues, now fixed.
@hathawsh
Copy link
Author

hathawsh commented Nov 2, 2017

I added echotest.py so I could test the code against the sockjs-protocol test suite. I found and fixed most of the test failures. The reasons for the rest of the failures are explained in a comment in echotest.py.

I decided it's probably best for dataReceived() to receive a UTF-8 encoded string so that Twisted protocol composition can work as expected. I also added support for a stringReceived() protocol method so consumers can skip the UTF-8 encoding.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants