summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-06-26 17:31:43 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-06-26 17:31:43 (GMT)
commitc6772c4d592be2274a66ccd26b5956738fc6e4f8 (patch)
tree2152a9d94dc41c1c30078a06c3c564d35011c280 /Lib/email
parent19454563d85361beeb8cd39dcabcb28d2639be31 (diff)
downloadcpython-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.py4
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):