Patchwork mail: handle renamed email.Header

login
register
mail settings
Submitter Pulkit Goyal
Date Oct. 7, 2016, 3:30 p.m.
Message ID <96f956b15caca4b754bb.1475854236@pulkit-goyal>
Download mbox | patch
Permalink /patch/16900/
State Superseded
Headers show

Comments

Pulkit Goyal - Oct. 7, 2016, 3:30 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1475854211 -7200
#      Fri Oct 07 17:30:11 2016 +0200
# Node ID 96f956b15caca4b754bbdee542173d9acef24561
# Parent  afce80b816e2baf6ed2b828feee00115f71936b6
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
Pulkit Goyal - Oct. 8, 2016, 8:26 a.m.
Don't take this one, I send an updated version with test output
updated based on current tip of hg-committed.

On Fri, Oct 7, 2016 at 5:30 PM, Pulkit Goyal <7895pulkit@gmail.com> wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1475854211 -7200
> #      Fri Oct 07 17:30:11 2016 +0200
> # Node ID 96f956b15caca4b754bbdee542173d9acef24561
> # Parent  afce80b816e2baf6ed2b828feee00115f71936b6
> 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 -r afce80b816e2 -r 96f956b15cac mercurial/mail.py
> --- a/mercurial/mail.py Fri Oct 07 15:29:57 2016 +0200
> +++ b/mercurial/mail.py Fri Oct 07 17:30:11 2016 +0200
> @@ -23,7 +23,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 +279,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 +330,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))

Patch

diff -r afce80b816e2 -r 96f956b15cac mercurial/mail.py
--- a/mercurial/mail.py	Fri Oct 07 15:29:57 2016 +0200
+++ b/mercurial/mail.py	Fri Oct 07 17:30:11 2016 +0200
@@ -23,7 +23,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 +279,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 +330,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))