mail: handle renamed email.Header
authorPulkit Goyal <7895pulkit@gmail.com>
Fri, 07 Oct 2016 17:30:11 +0200
changeset 30072 87b8e40eb812
parent 30071 2def3d55b1b9
child 30073 aa23c93e636d
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
mercurial/mail.py
tests/test-check-py3-compat.t
--- a/mercurial/mail.py	Fri Oct 07 08:32:40 2016 -0400
+++ b/mercurial/mail.py	Fri Oct 07 17:30:11 2016 +0200
@@ -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 @@
     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 @@
     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 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))
--- a/tests/test-check-py3-compat.t	Fri Oct 07 08:32:40 2016 -0400
+++ b/tests/test-check-py3-compat.t	Fri Oct 07 17:30:11 2016 +0200
@@ -121,29 +121,27 @@
   mercurial/i18n.py: error importing module: <TypeError> bytes expected, not str (line *)
   mercurial/keepalive.py: error importing module: <AttributeError> module 'mercurial.util' has no attribute 'httplib' (line *)
   mercurial/localrepo.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*)
-  mercurial/mail.py: error importing module: <AttributeError> module 'email' has no attribute 'Header' (line *)
-  mercurial/manifest.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
-  mercurial/merge.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
-  mercurial/namespaces.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
-  mercurial/patch.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+  mercurial/manifest.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
+  mercurial/merge.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
+  mercurial/namespaces.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
+  mercurial/patch.py: error importing module: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (line *)
   mercurial/pvec.py: error importing module: <NameError> name 'xrange' is not defined (line *)
   mercurial/repair.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*)
-  mercurial/revlog.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+  mercurial/revlog.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
   mercurial/revset.py: error importing module: <AttributeError> 'dict' object has no attribute 'iteritems' (line *)
   mercurial/scmwindows.py: error importing module: <ImportError> No module named 'winreg' (line *)
   mercurial/sshpeer.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*)
-  mercurial/sshserver.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+  mercurial/sshserver.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
   mercurial/statichttprepo.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at byterange.py:*)
   mercurial/store.py: error importing module: <NameError> name 'xrange' is not defined (line *)
   mercurial/streamclone.py: error importing: <TypeError> can't concat bytes to str (error at store.py:*)
-  mercurial/subrepo.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
-  mercurial/templatefilters.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
-  mercurial/templatekw.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
-  mercurial/templater.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
-  mercurial/ui.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
-  mercurial/unionrepo.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+  mercurial/subrepo.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
+  mercurial/templatefilters.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
+  mercurial/templatekw.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
+  mercurial/templater.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
+  mercurial/ui.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
+  mercurial/unionrepo.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
   mercurial/url.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*)
-  mercurial/verify.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
   mercurial/win32.py: error importing module: <ImportError> No module named 'msvcrt' (line *)
   mercurial/windows.py: error importing module: <ImportError> No module named 'msvcrt' (line *)
   mercurial/wireproto.py: error importing: <TypeError> %b requires bytes, or an object that implements __bytes__, not 'str' (error at bundle2.py:*)