#21476: Unwrap fp in BytesParser so the file isn't unexpectedly closed.

This makes the behavior match that of Parser.  Patch by Vajrasky Kok.
This commit is contained in:
R David Murray 2014-06-26 13:31:43 -04:00
parent 19454563d8
commit c6772c4d59
3 changed files with 31 additions and 1 deletions

View file

@ -106,8 +106,10 @@ class BytesParser:
meaning it parses the entire contents of the file.
"""
fp = TextIOWrapper(fp, encoding='ascii', errors='surrogateescape')
with fp:
try:
return self.parser.parse(fp, headersonly)
finally:
fp.detach()
def parsebytes(self, text, headersonly=False):