[PATCH] mail: ensure that Python2.4 to 2.7 use the same header format

Nicolas Dumazet nicdumz at gmail.com
Tue Jul 6 04:38:22 CDT 2010


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1278408244 -32400
# Branch stable
# Node ID 763a425c9a5b75d271304f2251c20554187d2261
# Parent  239f3210c970615dc1d5f861a92b61b4662a71a5
mail: ensure that Python2.4 to 2.7 use the same header format

Wrapping format for long headers changed in Python2.7 (see Python issue1974).
Adopt the Python2.7 behaviour and backport it for 2.4-2.6

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -10,6 +10,26 @@
 import os, smtplib, socket, quopri
 import email.Header, email.MIMEText, email.Utils
 
+_oldheaderinit = email.Header.Header.__init__
+def _unifiedheaderinit(self, *args, **kw):
+    """
+    Python2.7 introduces a backwards incompatible change
+    (Python issue1974, r70772) in email.Generator.Generator code:
+    pre-2.7 code passed "continuation_ws='\t'" to the Header
+    constructor, and 2.7 removed this parameter.
+
+    Default argument is continuation_ws=' ', which means that the
+    behaviour is different in <2.7 and 2.7
+
+    We consider the 2.7 behaviour to be preferable, but need
+    to have an unified behaviour for versions 2.4 to 2.7
+    """
+    # override continuation_ws
+    kw['continuation_ws'] = ' '
+    _oldheaderinit(self, *args, **kw)
+
+email.Header.Header.__dict__['__init__'] = _unifiedheaderinit
+
 def _smtp(ui):
     '''build an smtp connection and return a function to send mail'''
     local_hostname = ui.config('smtp', 'local_hostname')
diff --git a/tests/test-patchbomb.out b/tests/test-patchbomb.out
--- a/tests/test-patchbomb.out
+++ b/tests/test-patchbomb.out
@@ -573,7 +573,7 @@
 Content-Type: multipart/mixed; boundary="===
 MIME-Version: 1.0
 Subject: [PATCH 3 of 3] charset=utf-8;
-	content-transfer-encoding: quoted-printable
+ content-transfer-encoding: quoted-printable
 X-Mercurial-Node: c655633f8c87700bb38cc6a59a2753bdc5a6c376
 Message-Id: <c655633f8c87700bb38c.63@
 In-Reply-To: <patchbomb.60@
@@ -836,7 +836,7 @@
 Content-Type: multipart/mixed; boundary="===
 MIME-Version: 1.0
 Subject: [PATCH 3 of 3] charset=utf-8;
-	content-transfer-encoding: quoted-printable
+ content-transfer-encoding: quoted-printable
 X-Mercurial-Node: c655633f8c87700bb38cc6a59a2753bdc5a6c376
 Message-Id: <c655633f8c87700bb38c.63@
 In-Reply-To: <patchbomb.60@
@@ -1730,7 +1730,7 @@
 MIME-Version: 1.0
 Content-Transfer-Encoding: quoted-printable
 Subject: [PATCH 3 of 8] charset=utf-8;
-	content-transfer-encoding: quoted-printable
+ content-transfer-encoding: quoted-printable
 X-Mercurial-Node: c655633f8c87700bb38cc6a59a2753bdc5a6c376
 Message-Id: <c655633f8c87700bb38c.315532863@
 In-Reply-To: <patchbomb.315532860@


More information about the Mercurial-devel mailing list