# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2016-10-07 15:30:11 # Node ID 87b8e40eb8125d5ddc848d972b117989346057dd # Parent 2def3d55b1b9ec2acd53f96ca755d778b5ec865b mail: handle renamed email.Header We are still using email.Header which was renamed to email.header back in Python 2.5. References: https://hg.python.org/cpython/file/2.4/Lib/email and https://hg.python.org/cpython/file/2.5/Lib/email diff --git a/mercurial/mail.py b/mercurial/mail.py --- a/mercurial/mail.py +++ b/mercurial/mail.py @@ -8,6 +8,7 @@ from __future__ import absolute_import, print_function import email +import email.header import os import quopri import smtplib @@ -23,7 +24,7 @@ from . import ( util, ) -_oldheaderinit = email.Header.Header.__init__ +_oldheaderinit = email.header.Header.__init__ def _unifiedheaderinit(self, *args, **kw): """ Python 2.7 introduces a backwards incompatible change @@ -279,7 +280,7 @@ def headencode(ui, s, charsets=None, dis if not display: # split into words? s, cs = _encode(ui, s, charsets) - return str(email.Header.Header(s, cs)) + return str(email.header.Header(s, cs)) return s def _addressencode(ui, name, addr, charsets=None): @@ -330,7 +331,7 @@ def mimeencode(ui, s, charsets=None, dis def headdecode(s): '''Decodes RFC-2047 header''' uparts = [] - for part, charset in email.Header.decode_header(s): + for part, charset in email.header.decode_header(s): if charset is not None: try: uparts.append(part.decode(charset)) diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t --- a/tests/test-check-py3-compat.t +++ b/tests/test-check-py3-compat.t @@ -121,29 +121,27 @@ mercurial/i18n.py: error importing module: bytes expected, not str (line *) mercurial/keepalive.py: error importing module: module 'mercurial.util' has no attribute 'httplib' (line *) mercurial/localrepo.py: error importing: module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*) - mercurial/mail.py: error importing module: module 'email' has no attribute 'Header' (line *) - mercurial/manifest.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) - mercurial/merge.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) - mercurial/namespaces.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) - mercurial/patch.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) + mercurial/manifest.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) + mercurial/merge.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) + mercurial/namespaces.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) + mercurial/patch.py: error importing module: module 'mercurial.util' has no attribute 'stringio' (line *) mercurial/pvec.py: error importing module: name 'xrange' is not defined (line *) mercurial/repair.py: error importing: module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*) - mercurial/revlog.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) + mercurial/revlog.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) mercurial/revset.py: error importing module: 'dict' object has no attribute 'iteritems' (line *) mercurial/scmwindows.py: error importing module: No module named 'winreg' (line *) mercurial/sshpeer.py: error importing: module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*) - mercurial/sshserver.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) + mercurial/sshserver.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) mercurial/statichttprepo.py: error importing: module 'mercurial.util' has no attribute 'urlerr' (error at byterange.py:*) mercurial/store.py: error importing module: name 'xrange' is not defined (line *) mercurial/streamclone.py: error importing: can't concat bytes to str (error at store.py:*) - mercurial/subrepo.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) - mercurial/templatefilters.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) - mercurial/templatekw.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) - mercurial/templater.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) - mercurial/ui.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) - mercurial/unionrepo.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) + mercurial/subrepo.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) + mercurial/templatefilters.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) + mercurial/templatekw.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) + mercurial/templater.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) + mercurial/ui.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) + mercurial/unionrepo.py: error importing: module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*) mercurial/url.py: error importing: module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*) - mercurial/verify.py: error importing: module 'email' has no attribute 'Header' (error at mail.py:*) mercurial/win32.py: error importing module: No module named 'msvcrt' (line *) mercurial/windows.py: error importing module: No module named 'msvcrt' (line *) mercurial/wireproto.py: error importing: %b requires bytes, or an object that implements __bytes__, not 'str' (error at bundle2.py:*)