[Twisted-Python] Converting str to bytes in Py3 port

Adi Roiban adi at roiban.ro
Wed Sep 2 04:38:52 MDT 2015


While reviewing the latest patch related to porting Twisted to py3 I
saw that many values which were supposed to hold just text were ported
as bytes.

The argument for this conversion was that Twisted is a low level
framework and that other high level framworks like Treq or Klein
should implement the required code so that end user can just use text.

For example the HTTP response messages are not bytes, even if the RFC
specified that they should only contain text with a single encoding.

I have little experience with twisted.web, so maybe there are many
users of twisted.web which use binary data for response messages or
maybe there is a good use case for putting random bytes in the HTTP
response message.


If for twisted.web there are Treq or Klein to implement the user
friendly interfaces, I don't know what can be used for twisted.conch

In the ticket for porting twisted.conch.ssh.key to py3 [1] the name of
the ssh key algorithms like 'ssh-rsa' or 'ssh-dsa', encryption
algorithm names like AES-128-CBC and ssh key components like p, q, y,
x, n, e are now all bytes.

Do you think that this is ok?
Why allow or encourage people to use random bytes for fields which
should contain human readable text?

For HTTP response line and response headers I think that all values
should be text and encoded in ISO-8859-1.

RFC 4819 [2] only talks about using US-ASCII for all names used in the
SSH public key subsystem.
Why use bytes to represent these names?

RFC 4716 specifies that header tags must be US-ASCII while header
value UTF-8 ... while all IANA names are US-ASCII.... and names in the
private namespace (name at domain) should also be US-ASCII.

As a reviewer I don't know that is the degin/architecture choose by
Twisted and how to review such changes.

As a developer I prefer to have as much text as possible so that I can
do text manipulation operation on these values and directly include
them in logs or error messages.

I assume that all the people involved in writing the RFC had a good
reason to require those fields to be text rather than any bytes.

Thanks for your feedback!

[1] https://github.com/twisted/twisted/compare/trunk...conch-ssh-keys-py3-7998
[2] https://www.ietf.org/rfc/rfc4819.txt
Adi Roiban

More information about the Twisted-Python mailing list