This is a work-in-progress, unofficial port of Twisted to Python 3. The strategy is:
- run 2to3 over the codebase
- fix code manually until tests pass, one test file at a time
Optionally, howtos and examples should also be fixed, to validate the approach on entire programs.
The changes done to the code are the smallest changes needed to make stuff work. The goal is to minimize the resulting diffs (they will still be big of course).
The port is done in the t3k branch, so make sure you update to it.
I use Python 3.2 to develop this project. Currently, I do not intend to support previous Python 3 versions.
For TLS/SSL support, pyOpenSSL is required.
For Windows support, pywin32 is recommended.
The first milestone is to make core Twisted work (twisted.python, twisted.internet, twisted.protocols, twisted.spread, twisted.trial). This is pretty much done.
The second milestone is to experiment with merging new changes from upstream. The necessary effort looks so far quite reasonable.
The third, pie-in-the-sky milestone is to make all of Twisted work.
Twisted builds and installs fine, including the optional extension modules. You can use most of Twisted Core and also Names and Conch.
The following configurations were tested:
- 64-bit Linux
- 64-bit Windows 7 (including the IOCP reactor, but without pyOpenSSL)
The following tests pass:
- All of twisted/application/test
- All of twisted/conch/test
- All of twisted/internet/test
- All of twisted/lore/test
- All of twisted/manhole/test
- All of twisted/names/test
- All of twisted/pair/test
- All of twisted/protocols/test
- All of twisted/python/test
- All of twisted/runner/test
- All of twisted/scripts/test
- All of twisted/trial/test
- All of twisted/test except test_hook, test_sip
The following scripts are known to work:
As a last resort, due to irreconcilable differences between Python 2 and 3, a couple of test cases have been marked "skipped" or "todo". They are very exceptional and don't affect overall functionality. The primary offenders are the semantic gap between old-style and new-style classes, and the fact that Python 3 doesn't have "unbound" methods (when you lookup a normal method on a class, you just get the original function without a
__class__ attribute to tell you where it is attached).
If you want to help, there are several possible tasks:
- easy: take an existing example, run it and fix it (in general, this mostly requires making string literals into bytes literals)
- ranging from easy to tricky: take a test that currently fails and fix code (in the test and/or the tested modules) so that it passes
First you'll need to build Twisted, for example using
python3 setup.py develop
Then running a test is a matter of
python3 bin/trial twisted.test.test_name
The trial test runner has many options, use the
--help option for more information.
I had to make the following decisions:
- FilePath.open() gets an additional "encoding" argument
- banana gets support for bytes objects using a separate opcode
- an AMP box is now a dictionary of str keys mapping to bytes values
When conversion of strings from/to bytes is required, utf-8 is preferred as an encoding, although ascii is sometimes used for safety when parsing well-known datatypes. I also rely on os.fsencode() and os.fsdecode() where appropriate.