[Python-Dev] Reintroduce or drop completly hex, bz2, rot13, ... codecs
M.-A. Lemburg
mal at egenix.com
Wed Jun 9 13:53:08 CEST 2010
Antoine Pitrou wrote:
> On Wed, 09 Jun 2010 10:41:29 +0200
> "M.-A. Lemburg" <mal at egenix.com> wrote:
>>
>> The above example will read:
>>
>> >>> b'abc'.transform("hex")
>> b'616263'
>> >>> b'616263'.untranform("hex")
>> b'abc'
>
> This doesn't look right to me. Hex-encoded "data" is really text (it's
> a textual representation of binary, and isn't often used as an opaque
> binary transport encoding).
Then we'd need new .encode() and .decode() methods, so that
we could write:
>>> b'abc'.encode("hex")
'616263'
>>> '616263'.decode("hex")
b'abc'
The reason is that we don't have helper methods for the directions
encoding: bytes->str and
decoding: str->bytes.
We do in Python2, so perhaps adding those back as well would
be a possibility, but I don't want to strain all this too much.
It's always possible to use:
codecs.encode(b'abc')
and
codecs.decode('616263')
instead.
> Of course, this is not necessarily so for all codecs. For
> base64-encoded data, for example, it is debatable whether you want it
> as ASCII bytes or unicode text.
Since there are multiple ways of choosing types, I would like
to use the ones that Python2 already chose, if possible.
The only one I'm not sure about is 'rot13': this is an encoding
that is only defined for text and works by creating mangled
text, so str->str appears to be more correct than str->bytes
(which we have in Python2).
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Jun 09 2010)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2010-07-19: EuroPython 2010, Birmingham, UK 39 days to go
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-Dev
mailing list