Patchwork [V3] mail: handle renamed email.Header

login
register
mail settings
Submitter Pulkit Goyal
Date Oct. 8, 2016, 10:29 a.m.
Message ID <00d9aeada4447cb5f155.1475922544@pulkit-goyal>
Download mbox | patch
Permalink /patch/16914/
State Accepted
Headers show

Comments

Pulkit Goyal - Oct. 8, 2016, 10:29 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1475854211 -7200
#      Fri Oct 07 17:30:11 2016 +0200
# Node ID 00d9aeada4447cb5f155b9c455c537e499ace4ee
# Parent  6ffb7e0249f44ab120b4437ae7d65020d03927ba
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

Patch

diff -r 6ffb7e0249f4 -r 00d9aeada444 mercurial/mail.py
--- a/mercurial/mail.py	Fri Oct 07 08:32:18 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))
diff -r 6ffb7e0249f4 -r 00d9aeada444 tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t	Fri Oct 07 08:32:18 2016 -0400
+++ b/tests/test-check-py3-compat.t	Fri Oct 07 17:30:11 2016 +0200
@@ -121,7 +121,6 @@ 
   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: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
-  mercurial/mail.py: error importing module: <AttributeError> module 'email' has no attribute 'Header' (line *)
   mercurial/manifest.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
   mercurial/merge.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
   mercurial/namespaces.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)