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/test/test_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/test/test_email')
-rw-r--r-- | Lib/test/test_email/test_email.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 2f89a10..af8bc7b 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -3390,6 +3390,31 @@ class TestParsers(TestEmailBase): self.assertIsInstance(msg.get_payload(), str) self.assertIsInstance(msg.get_payload(decode=True), bytes) + def test_bytes_parser_does_not_close_file(self): + with openfile('msg_02.txt', 'rb') as fp: + email.parser.BytesParser().parse(fp) + self.assertFalse(fp.closed) + + def test_bytes_parser_on_exception_does_not_close_file(self): + with openfile('msg_15.txt', 'rb') as fp: + bytesParser = email.parser.BytesParser + self.assertRaises(email.errors.StartBoundaryNotFoundDefect, + bytesParser(policy=email.policy.strict).parse, + fp) + self.assertFalse(fp.closed) + + def test_parser_does_not_close_file(self): + with openfile('msg_02.txt', 'r') as fp: + email.parser.Parser().parse(fp) + self.assertFalse(fp.closed) + + def test_parser_on_exception_does_not_close_file(self): + with openfile('msg_15.txt', 'r') as fp: + parser = email.parser.Parser + self.assertRaises(email.errors.StartBoundaryNotFoundDefect, + parser(policy=email.policy.strict).parse, fp) + self.assertFalse(fp.closed) + def test_whitespace_continuation(self): eq = self.assertEqual # This message contains a line after the Subject: header that has only |