From c6772c4d592be2274a66ccd26b5956738fc6e4f8 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Thu, 26 Jun 2014 13:31:43 -0400 Subject: #21476: Unwrap fp in BytesParser so the file isn't unexpectedly closed. This makes the behavior match that of Parser. Patch by Vajrasky Kok. --- Lib/email/parser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/email/parser.py') diff --git a/Lib/email/parser.py b/Lib/email/parser.py index 9f5f95dfba..8c9bc9e44e 100644 --- a/Lib/email/parser.py +++ b/Lib/email/parser.py @@ -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): -- cgit v1.2.1