[Python-3000] TextIOWrapper.read() "fixed"?

Humberto Diogenes humberto at digi.com.br
Fri Jun 6 12:02:07 CEST 2008


   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 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)


--
Humberto Diógenes
http://humberto.digi.com.br



More information about the Python-3000 mailing list