On Tue, 24 May 2011 12:16:49 +0200 Walter Dörwald <wal...@livinglogic.de> wrote: > > > and so it's not possible to write a generic fix for > > all child classes in the codecs module. Each stateful codec has to > > handle special cases like seek() problems. > > Yes, which in theory makes it possible to implement shortcuts for > certain codecs (e.g. the UTF-32-BE/LE codecs could simply multiply the > character position by 4 to get the byte position). However AFAICR none > of the readers/writers does that.
And in practice, TextIOWrapper.tell() does a similar optimization in a generic way. I'm linking to the Python implementation for readability: http://hg.python.org/cpython/file/5c716437a83a/Lib/_pyio.py#l1741 TextIOWrapper.seek() is straightforward due to the structure of the integer "cookie" returned by TextIOWrapper.tell(). In practice, TextIOWrapper gets much more love than Stream{Reader,Writer} because it's an essential part of the new I/O stack. As Victor said, problems which Stream* have had for years are solved neatly in TextIOWrapper. Therefore, leaving Stream{Reader,Writer} in is not a matter of "choice" and "freedom given to users". It's giving people the misleading possibility of using non-optimized, poorly debugged, less featureful implementations of the same basic idea (an unicode stream abstraction). Regards Antoine. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com