[New-bugs-announce] [issue14475] codecs.StreamReader.read behaves differently from regular files

Mikko Rasa report at bugs.python.org
Mon Apr 2 15:13:34 CEST 2012

New submission from Mikko Rasa <tdb at tdb.fi>:

For regular files, a read() call without arguments will read until EOF.  codecs.StreamReader does its own buffering, and if there are characters in the buffer, a read() call will be satisfied from the buffer without an attempt to read the rest of the file.  This discrepancy causes certain code that worked with regular open() fail if codecs.open() is substituted.

The easiest way to reproduce this is to first call readline() and then read().  Since readline() can't know how many characters are on the line, it will almost always leave some characters in the buffer, triggering the problem with read().

messages: 157355
nosy: tdb
priority: normal
severity: normal
status: open
title: codecs.StreamReader.read behaves differently from regular files
type: behavior
versions: Python 2.6, Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list