]> granicus.if.org Git - python/commitdiff
[email] bpo-29478: Fix passing max_line_length=None from Compat32 policy (GH-595...
authorMariatta <Mariatta@users.noreply.github.com>
Fri, 16 Jun 2017 02:38:12 +0000 (19:38 -0700)
committerGitHub <noreply@github.com>
Fri, 16 Jun 2017 02:38:12 +0000 (19:38 -0700)
If max_line_length=None is specified while using the Compat32 policy,
it is no longer ignored..
(cherry picked from commit b459f7482612d340b88b62edc024628595ec6337)

Lib/email/_policybase.py
Lib/test/test_email/test_generator.py
Misc/ACKS
Misc/NEWS

index c0d98a4f5429357509502ebd1dce4b53afc26ab5..7326d3a2b1671eabbefad6ff08439d00929243ff 100644 (file)
@@ -357,8 +357,12 @@ class Compat32(Policy):
             # Assume it is a Header-like object.
             h = value
         if h is not None:
-            parts.append(h.encode(linesep=self.linesep,
-                                  maxlinelen=self.max_line_length))
+            # The Header class interprets a value of None for maxlinelen as the
+            # 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)
         return ''.join(parts)
 
index b1cbce26d5c1fb94887ec609510bb59d4376299c..226c5f98c4039cf3d35446bb76fdd5a8d75a7319 100644 (file)
@@ -162,6 +162,13 @@ class TestGeneratorBase:
                 g.flatten(msg)
                 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):
 
index 1ed9e5bc98abf57ac0743008f3e2e29df5d748e3..d728d43395b534ee3aeab3201b15129d5e6bed0f 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -304,6 +304,7 @@ Garrett Cooper
 Greg Copeland
 Ian Cordasco
 Aldo Cortesi
+Mircea Cosbuc
 David Costanzo
 Scott Cotton
 Greg Couch
index b6bab9be07d5ec44de201d128436266e21aae6ee..9ed427de35449e1fc01b24d3dc052424683f514b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,9 @@ Core and Builtins
 - Issue #29337: Fixed possible BytesWarning when compare the code objects.
   Warnings could be emitted at compile time.
 
+- bpo-29478: If max_line_length=None is specified while using the Compat32 policy,
+  it is no longer ignored.  Patch by Mircea Cosbuc.
+
 Extension Modules
 -----------------