[Python-Dev] Deprecate codecs.open() and StreamWriter/StreamReader

M.-A. Lemburg mal at egenix.com
Wed May 25 11:38:10 CEST 2011

Walter Dörwald wrote:
> On 24.05.11 12:58, Victor Stinner wrote:
>> Le mardi 24 mai 2011 à 12:42 +0200, Łukasz Langa a écrit :
>>> Wiadomość napisana przez Walter Dörwald w dniu 2011-05-24, o godz. 12:16:
>>>>> I don't see which usecase is not covered by TextIOWrapper. But I know
>>>>> some cases which are not supported by StreamReader/StreamWriter.
>>>> This could be be partially fixed by implementing generic
>>>> StreamReader/StreamWriter classes that reuse the incremental codecs, but
>>>> I don't think thats worth it.
>>> Why not?
>> We have already an implementation of this idea, it is called
>> io.TextIOWrapper.
> Exactly.
> From another post by Victor:
>> As I wrote, codecs.open() is useful in Python 2. But I don't know any
>> program or library using directly StreamReader or StreamWriter.
> So: implementing this is a lot of work, duplicates existing
> functionality and is mostly unused.

You are missing the point: we have StreamReader and StreamWriter APIs
on codecs to allow each codecs to implement more efficient ways of
encoding and decoding streams.

Examples of such optimizations are reading the stream in
chunks that can be decoded in one piece, or writing to the stream
in a way that doesn't generate encoding state problems on the
receiving end by ending transmission half-way through a
shift block.

Of course, you won't find many direct uses of these APIs, since
most of the time, applications will simply use codecs.open() to
automatically benefit from these optimizations.

OTOH, TextIOWrapper doesn't know anything about specific encodings
and thus does not allow for such optimizations to be implemented
by codecs.

We don't have many such specialized implementations in the stdlib,
but this doesn't mean that there's no use for them. It
just means that developers and users are simply unaware of the
possibilities opened by these stateful stream APIs.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, May 25 2011)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
2011-05-23: Released eGenix mx Base 3.2.0      http://python.egenix.com/
2011-05-25: Released mxODBC 3.1.1              http://python.egenix.com/
2011-06-20: EuroPython 2011, Florence, Italy               26 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

More information about the Python-Dev mailing list