Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/mail.py @ 11542:594b98846ce1 stable
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
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Tue, 06 Jul 2010 18:24:04 +0900 |
parents | d6512b3e9ac0 |
children | 49463314c24f ee601a6264e0 |
comparison
equal
deleted
inserted
replaced
11541:ab9fa7a85dd9 | 11542:594b98846ce1 |
---|---|
7 | 7 |
8 from i18n import _ | 8 from i18n import _ |
9 import util, encoding | 9 import util, encoding |
10 import os, smtplib, socket, quopri | 10 import os, smtplib, socket, quopri |
11 import email.Header, email.MIMEText, email.Utils | 11 import email.Header, email.MIMEText, email.Utils |
12 | |
13 _oldheaderinit = email.Header.Header.__init__ | |
14 def _unifiedheaderinit(self, *args, **kw): | |
15 """ | |
16 Python2.7 introduces a backwards incompatible change | |
17 (Python issue1974, r70772) in email.Generator.Generator code: | |
18 pre-2.7 code passed "continuation_ws='\t'" to the Header | |
19 constructor, and 2.7 removed this parameter. | |
20 | |
21 Default argument is continuation_ws=' ', which means that the | |
22 behaviour is different in <2.7 and 2.7 | |
23 | |
24 We consider the 2.7 behaviour to be preferable, but need | |
25 to have an unified behaviour for versions 2.4 to 2.7 | |
26 """ | |
27 # override continuation_ws | |
28 kw['continuation_ws'] = ' ' | |
29 _oldheaderinit(self, *args, **kw) | |
30 | |
31 email.Header.Header.__dict__['__init__'] = _unifiedheaderinit | |
12 | 32 |
13 def _smtp(ui): | 33 def _smtp(ui): |
14 '''build an smtp connection and return a function to send mail''' | 34 '''build an smtp connection and return a function to send mail''' |
15 local_hostname = ui.config('smtp', 'local_hostname') | 35 local_hostname = ui.config('smtp', 'local_hostname') |
16 s = smtplib.SMTP(local_hostname=local_hostname) | 36 s = smtplib.SMTP(local_hostname=local_hostname) |