Add initial Jython support

Currently only works for http as ssl module is not yet fully functional.

Ran the tests, with some (expectedly) failing on ssl support


Thanks for this! Jython is weird. =)

I think before we merge this we should set up our CI server with a Jython build. If we're going to support Jython, let's do it properly. @kennethreitz do you want to do that yourself, or would you rather one of @sigmavirus24 or I did it?


@kennethreitz controls the Jenkins CI server so I would guess he'd be able to set up Jython if desired. FWIW, I would like to support Jython, but I'm curious about some things in the PR. None are really merge blockers.

The only thing that _is_ a merge blocker to me is failing HTTPS tests. If we're going to support Jython, given that we're the only package that does SSL as correctly as possible, I would want that to be fully functional before we ship anything advertising that we support Jython. Otherwise, the greatest draw to requests (beyond its API) is invalid and horribly broken. That raises the question:

How far out is SSL support?


SSL won't work with Jython 2.7b1 (http://bugs.jython.org/issue2016)
I don't think Requests would support Jython 2.5.3.


Yes, SSL support is broken in Jython, and should not require any changes to requests, once written/fixed.
Jim Baker has a branch for SSL support in Jython, but it's not yet complete: https://bitbucket.org/jimbaker/jython-ssl
I'm not targeting Jython 2.5 for obvious reasons.


Uhhhh. That makes me uncomfortable.

Are we interested in raising a Warning on import?


Thanks so much for the patch, and the work, but I think this is a step in the wrong direction for us at the moment. I'll continue to think about it, however. Thanks again :)


Hey Kenneth,
Thanks for looking at it. Could you please elaborate a bit more on the "wrong direction"? I'd love to get Jython working for more libraries, but without knowing what's wrong with this patch, I can't fix it :(

Thanks!
Darjus


I'm generally not against making a few tweaks here and there for compatibility reasons, but these seems like really odd changes that taint a generally pure code base, and they are being made to support an obscure interpreter that doesn't even support SSL, one of our biggest features.

It's just not a good fit :)


e.g. at this point, I'm afraid to say that all of these changes should be made on Jython's end :)


FWIW, Jython 2.7 will soon have proper SSL support, both blocking and nonblocking; see https://github.com/jimbaker/socket-reboot, which reworks Jython's implementation of socket/select/ssl by layering on top of Netty 4. Supporting requests, and indirectly pip, is an explicit goal of this work.

Some other work that should support requests without modification:
- idna.encodings was added a few months ago to 2.7, as of 7137:a9283b590960
- Large collection literals, to work around cases where a dict, set, tuple, or list was being initialized from a literal, causing the generated Java bytecode to exceed classfile limits on method size (~ 32K bytecodes). IIRC, used in character determination for certain east asian encodings in requests.

The one issue that may come up is that Jython does not support unicode literals that are not valid for UTF-16 (or for that matter any attempt to construct such strings - but in practice it's seen in literals in large sophisticated libraries that are doing this to efficiently detect invalid usage!). IIRC, this only came up in pip, not requests directly. The particular case this arises is the use of isolated surrogates.


@jimbaker correct me if I am misunderstanding you but basically requests should not need to do anything after Jython 2.7 is released to support it. It sounds like the IDNA changes that were made here will be made unnecessary and that ssl will not be an issue. Also, requests does not use unicode string literals in the library at all, only in the tests. Can you ping us when Jython 2.7 is released so we can start testing with it then?


@sigmavirus24 As of a few minutes ago, 100% of the unit tests for requests master now pass when run on this branch of Jython, which supports SSL and other goodies: https://bitbucket.org/jimbaker/jython-socket-reboot

Please note that the above branch still needs to be cleaned up (at the very least, remove copious print debugging!), but that's all pretty obvious in the FIXMEs and prints.

I will ping again when we have this merged against Jython trunk, in prep for beta 3 - it would be great for us to have Jython as part of your testing.


Jython 2.7 trunk now supports requests. This will be part of the forthcoming beta 3.


:+1: That's awesome! If you let me know when you release beta 3, I'll tweet and blog and generally make positive noises everywhere I can.


You're doing great work @jimbaker !


Just because we can do something, doesn't mean we should. 


@kennethreitz sorry?