Skip to content

Commit 77ea798

Browse files
committed
Update NEWS entry, test case enhance, lint code
1 parent d0dc3c0 commit 77ea798

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

Lib/email/contentmanager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import sys
21
import binascii
32
import email.charset
43
import email.message
54
import email.errors
65
from email import quoprimime
6+
import sys
77

88
class ContentManager:
99

@@ -159,8 +159,7 @@ def normal_body(lines): return b'\n'.join(lines) + b'\n'
159159
if policy.cte_type == '8bit':
160160
return '8bit', normal_body(lines).decode('ascii', 'surrogateescape')
161161
sniff = embedded_body(lines[:10])
162-
sniff_qp = quoprimime.body_encode(sniff.decode('latin-1'),
163-
maxlen)
162+
sniff_qp = quoprimime.body_encode(sniff.decode('latin-1'), maxlen)
164163
sniff_base64 = binascii.b2a_base64(sniff)
165164
# This is a little unfair to qp; it includes lineseps, base64 doesn't.
166165
if len(sniff_qp) > len(sniff_base64):

Lib/test/test_email/test_message.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,33 +1004,25 @@ def test_folding_with_long_nospace_http_policy_1(self):
10041004
parsed_msg = message_from_bytes(m.as_bytes(), policy=policy.default)
10051005
self.assertEqual(parsed_msg['Message-ID'], m['Message-ID'])
10061006

1007-
def test_no_wrapping_with_zero_max_line_length(self):
1008-
pol = policy.default.clone(max_line_length=0)
1009-
subj = "S" * 100
1010-
msg = EmailMessage(policy=pol)
1011-
msg["From"] = "[email protected]"
1012-
msg["To"] = "[email protected]"
1013-
msg["Subject"] = subj
1014-
1015-
raw = msg.as_bytes()
1016-
self.assertNotIn(b"\r\n ", raw, "Found fold indicator; wrapping not disabled")
1017-
1018-
parsed = message_from_bytes(raw, policy=policy.default)
1019-
self.assertEqual(parsed["Subject"], subj)
1020-
1021-
def test_no_wrapping_with_none_max_line_length(self):
1022-
pol = policy.default.clone(max_line_length=None)
1023-
subj = "S" * 100
1024-
body = "B" * 100
1025-
msg = EmailMessage(policy=pol)
1026-
msg["From"] = "[email protected]"
1027-
msg["To"] = "[email protected]"
1028-
msg["Subject"] = subj
1029-
msg.set_content(body)
1030-
1031-
parsed = message_from_bytes(msg.as_bytes(), policy=policy.default)
1032-
self.assertEqual(parsed["Subject"], subj)
1033-
self.assertEqual(parsed.get_body().get_content().rstrip('\n'), body)
1007+
def test_no_wrapping_max_line_length(self):
1008+
def do_test_no_wrapping_max_line_length(n):
1009+
pol = policy.default.clone(max_line_length=n)
1010+
subj = "S" * 100
1011+
body = "B" * 100
1012+
msg = EmailMessage(policy=pol)
1013+
msg["From"] = "[email protected]"
1014+
msg["To"] = "[email protected]"
1015+
msg["Subject"] = subj
1016+
msg.set_content(body)
1017+
1018+
raw = msg.as_bytes()
1019+
self.assertNotIn(b"\r\n ", raw, "Found fold indicator; wrapping not disabled")
1020+
1021+
parsed = message_from_bytes(msg.as_bytes(), policy=policy.default)
1022+
self.assertEqual(parsed["Subject"], subj)
1023+
self.assertEqual(parsed.get_body().get_content().rstrip('\n'), body)
1024+
do_test_no_wrapping_max_line_length(None)
1025+
do_test_no_wrapping_max_line_length(0)
10341026

10351027
def test_invalid_header_names(self):
10361028
invalid_headers = [
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
:mod:`email`: Ensure policy accepts unlimited line lengths by
2-
treating 0 or :const:`None` as :data:`sys.maxsize`.
2+
treating falsey values as :data:`sys.maxsize`.

0 commit comments

Comments
 (0)