diff options
author | R David Murray <rdmurray@bitdance.com> | 2014-06-26 17:31:43 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2014-06-26 17:31:43 (GMT) |
commit | c6772c4d592be2274a66ccd26b5956738fc6e4f8 (patch) | |
tree | 2152a9d94dc41c1c30078a06c3c564d35011c280 /Lib/email | |
parent | 19454563d85361beeb8cd39dcabcb28d2639be31 (diff) | |
download | cpython-c6772c4d592be2274a66ccd26b5956738fc6e4f8.zip cpython-c6772c4d592be2274a66ccd26b5956738fc6e4f8.tar.gz cpython-c6772c4d592be2274a66ccd26b5956738fc6e4f8.tar.bz2 |
#21476: Unwrap fp in BytesParser so the file isn't unexpectedly closed.
This makes the behavior match that of Parser. Patch by Vajrasky Kok.
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/parser.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/email/parser.py b/Lib/email/parser.py index 9f5f95d..8c9bc9e 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): |