Porting to Python 3¶
Twisted is currently being ported to work with Python 3.3. This document covers Twisted-specific issues in porting your code to Python 3.
Only some parts of Twisted have been ported, and therefore only a subset of modules are installed under Python 3. You can see the full list of ported modules in twisted.python.dist3.
Byte Strings and Text Strings¶
Several APIs which on Python 2 accepted or produced byte strings
str , sometimes just called bytes ) have
changed to accept or produce text strings (instances of
sometimes just called text or unicode ) on Python 3.
twisted.internet.address , the
IPv6Address classes have had two attributes change from
byte strings to text strings:
twisted.python.log has shifted significantly towards text
strings from byte strings. Logging events, particular those produced by a
msg("foo") , must now be text strings. Consequently,
on Python 3, event dictionaries passed to log observes will contain text
strings where they previously contained byte strings.
twisted.python.runtime.platformType and the return value
twisted.python.runtime.Platform.getType are now both text
twisted.python.filepath.FilePath has not changed.
It supports only byte strings. This will probably require applications to
update their usage of
FilePath , at least to pass explicit byte
string literals rather than “native” string literals (which are text on
reactor.addSystemEventTrigger arguments that were
previously byte strings are now native strings.
twisted.names.dns deals with strings with a wide range of
meanings, often several for each DNS record type. Most of these strings
have remained as byte strings, which will probably require application
updates (for the reason given in the
FilePath section above).
Some strings have changed to text strings, though. Any string representing
a human readable address (for
address parameter) is now a
text string. Additionally, time-to-live (ttl) values given as strings must
now be given as text strings.
twisted.web.resource.IResource continues to deal with URLs
and all URL-derived values as byte strings.
twisted.web.resource.ErrorPage has several string attributes
brief , and
detail ) which
were previously byte strings. On Python 3 only, these must now be text