[Python-Dev] Reintroduce or drop completly hex, bz2, rot13, ... codecs

"Martin v. Löwis" martin at v.loewis.de
Wed Jun 9 22:13:28 CEST 2010


>> But in both cases you probably want bytes ->  bytes and str ->  str. If
>> you want text out then put text in, if you want bytes out then put bytes in.
>
> No, I don't think so. If I'm using hex "encoding", it's because I want
> to see a text representation of some arbitrary bytestring (in order to
> display it inside another piece of text, for example).
> In other words, the purpose of hex is precisely to give a textual
> display of non-textual data.

I think this is the way it is for consistency reasons (which I would not 
lightly wish away). I think you agree that base64 is a bytes->bytes
transformation (because you typically use it as a payload on some wire
protocol).

So:

py> binascii.b2a_base64(b'foo')
b'Zm9v\n'
py> binascii.b2a_hex(b'foo')
b'666f6f'

Now, I'd admit that "b2a" may be a misnomer (binary -> ASCII), but then
it may not because ASCII actually *also* implies "bytes" (it's an encoding).

So what would you propose to change: b2a_hex should return a Unicode
string? or this future transform method should return a Unicode string,
whereas the module returns bytes? Something else?

Regards,
Martin


More information about the Python-Dev mailing list