[Python-3000] TextIOWrapper.read() "fixed"?
Guido van Rossum
guido at python.org
Fri Jun 6 20:14:07 CEST 2008
On Fri, Jun 6, 2008 at 3:02 AM, Humberto Diogenes <humberto at digi.com.br> wrote:
>
> I found this on Lib/email/parser.py, on Parser.parse():
>
> while True:
> data = fp.read(8192)
> if not data:
> break
> # XXX When Guido fixes TextIOWrapper.read() to act just like
> # .readlines(), this...
> feedparser.feed(str(data))
> # ...gets reverted back to
> #feedparser.feed(data)
> return feedparser.close()
>
> Is that still necessary?
I can't tell for sure what Barry meant, but this was introduced in
August 2007. Since then, a lot has changed in io.py. Why don't you try
taking it out?
> I noticed it while trying to migrate http.client.HTTPMessage away from
> mimetools (issue 2848). I was having problems when parse() received bytes
> directly, as they were being converted to 'b"..."' strings.
>
> BTW, is TextIOWrapper+BufferedReader the right solution to read a string
> from a socket?
>
> # In HTTPResponse:
> - self.msg = HTTPMessage(self.fp, 0)
> + parser = email.parser.HeaderParser(_class=HTTPMessage)
> + fp = io.TextIOWrapper(io.BufferedReader(self.fp), 'latin1')
> + self.msg = parser.parse(fp)
Probably. This is what the socket class's own makefile() method does.
Read all about it in socket.py.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list