Merged in 3.x with r78942 and r78945.
See #8047 for a discussion about the `encoding` argument of the serializer (used for .write() method and tostring() tostringlist() functions).
Currently the output is not encoded by default in 3.1 and 3.x.
It is encoded to ASCII in 2.6 and 2.x.