Kaydet (Commit) e9f4d8db authored tarafından Mariatta's avatar Mariatta Kaydeden (comit) GitHub

[email] bpo-29478: Fix passing max_line_length=None from Compat32 policy (GH-595) (GH-2233)

If max_line_length=None is specified while using the Compat32 policy,
it is no longer ignored..
(cherry picked from commit b459f748)
üst 2eca5b46
...@@ -361,8 +361,12 @@ class Compat32(Policy): ...@@ -361,8 +361,12 @@ class Compat32(Policy):
# Assume it is a Header-like object. # Assume it is a Header-like object.
h = value h = value
if h is not None: if h is not None:
parts.append(h.encode(linesep=self.linesep, # The Header class interprets a value of None for maxlinelen as the
maxlinelen=self.max_line_length)) # default value of 78, as recommended by RFC 2822.
maxlinelen = 0
if self.max_line_length is not None:
maxlinelen = self.max_line_length
parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
parts.append(self.linesep) parts.append(self.linesep)
return ''.join(parts) return ''.join(parts)
......
...@@ -162,6 +162,13 @@ class TestGeneratorBase: ...@@ -162,6 +162,13 @@ class TestGeneratorBase:
g.flatten(msg) g.flatten(msg)
self.assertEqual(s.getvalue(), self.typ(expected)) self.assertEqual(s.getvalue(), self.typ(expected))
def test_compat32_max_line_length_does_not_fold_when_none(self):
msg = self.msgmaker(self.typ(self.refold_long_expected[0]))
s = self.ioclass()
g = self.genclass(s, policy=policy.compat32.clone(max_line_length=None))
g.flatten(msg)
self.assertEqual(s.getvalue(), self.typ(self.refold_long_expected[0]))
class TestGenerator(TestGeneratorBase, TestEmailBase): class TestGenerator(TestGeneratorBase, TestEmailBase):
......
...@@ -309,6 +309,7 @@ Garrett Cooper ...@@ -309,6 +309,7 @@ Garrett Cooper
Greg Copeland Greg Copeland
Ian Cordasco Ian Cordasco
Aldo Cortesi Aldo Cortesi
Mircea Cosbuc
David Costanzo David Costanzo
Scott Cotton Scott Cotton
Greg Couch Greg Couch
......
...@@ -51,6 +51,9 @@ Core and Builtins ...@@ -51,6 +51,9 @@ Core and Builtins
- bpo-29714: Fix a regression that bytes format may fail when containing zero - bpo-29714: Fix a regression that bytes format may fail when containing zero
bytes inside. bytes inside.
- bpo-29478: If max_line_length=None is specified while using the Compat32 policy,
it is no longer ignored. Patch by Mircea Cosbuc.
Library Library
------- -------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment