Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b459f74

Browse files
mircea-cosbucMariatta
authored andcommittedJun 12, 2017
[email] bpo-29478: Fix passing max_line_length=None from Compat32 policy (pythonGH-595)
If max_line_length=None is specified while using the Compat32 policy, it is no longer ignored.
1 parent 3fd54d4 commit b459f74

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed
 

‎Lib/email/_policybase.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,12 @@ def _fold(self, name, value, sanitize):
361361
# Assume it is a Header-like object.
362362
h = value
363363
if h is not None:
364-
parts.append(h.encode(linesep=self.linesep,
365-
maxlinelen=self.max_line_length))
364+
# The Header class interprets a value of None for maxlinelen as the
365+
# default value of 78, as recommended by RFC 2822.
366+
maxlinelen = 0
367+
if self.max_line_length is not None:
368+
maxlinelen = self.max_line_length
369+
parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
366370
parts.append(self.linesep)
367371
return ''.join(parts)
368372

‎Lib/test/test_email/test_generator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ def test_set_mangle_from_via_policy(self):
162162
g.flatten(msg)
163163
self.assertEqual(s.getvalue(), self.typ(expected))
164164

165+
def test_compat32_max_line_length_does_not_fold_when_none(self):
166+
msg = self.msgmaker(self.typ(self.refold_long_expected[0]))
167+
s = self.ioclass()
168+
g = self.genclass(s, policy=policy.compat32.clone(max_line_length=None))
169+
g.flatten(msg)
170+
self.assertEqual(s.getvalue(), self.typ(self.refold_long_expected[0]))
171+
165172

166173
class TestGenerator(TestGeneratorBase, TestEmailBase):
167174

‎Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ Garrett Cooper
310310
Greg Copeland
311311
Ian Cordasco
312312
Aldo Cortesi
313+
Mircea Cosbuc
313314
David Costanzo
314315
Scott Cotton
315316
Greg Couch

‎Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ Core and Builtins
142142

143143
- bpo-29546: Improve from-import error message with location
144144

145+
- bpo-29478: If max_line_length=None is specified while using the Compat32 policy,
146+
it is no longer ignored. Patch by Mircea Cosbuc.
147+
145148
- Issue #29319: Prevent RunMainFromImporter overwriting sys.path[0].
146149

147150
- Issue #29337: Fixed possible BytesWarning when compare the code objects.

0 commit comments

Comments
 (0)
Please sign in to comment.