Patchwork py3: use email.parser module to parse email messages

login
register
mail settings
Submitter Pulkit Goyal
Date Jan. 14, 2018, 6:48 p.m.
Message ID <9c8cc14cd05fa3420b15.1515955695@workspace>
Download mbox | patch
Permalink /patch/26738/
State Accepted
Headers show

Comments

Pulkit Goyal - Jan. 14, 2018, 6:48 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1514573036 -19800
#      Sat Dec 30 00:13:56 2017 +0530
# Node ID 9c8cc14cd05fa3420b1549c5369bf9b3623bd5ee
# Parent  390f860228ba909499093e0e8861c908fe15a2d0
# EXP-Topic py3
py3: use email.parser module to parse email messages

Before this patch we use email.Parser.Parser() from the email module which is
not available on Python 3.

On Python 2:

>>> import email
>>> import email.parser as emailparser
>>> email.Parser.Parser is emailparser.Parser
True
Gregory Szorc - Jan. 14, 2018, 8:16 p.m.
On Sun, Jan 14, 2018 at 10:48 AM, Pulkit Goyal <7895pulkit@gmail.com> wrote:

> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1514573036 -19800
> #      Sat Dec 30 00:13:56 2017 +0530
> # Node ID 9c8cc14cd05fa3420b1549c5369bf9b3623bd5ee
> # Parent  390f860228ba909499093e0e8861c908fe15a2d0
> # EXP-Topic py3
> py3: use email.parser module to parse email messages
>

Queued.

This was a top 5 crasher for Python 3 in the test harness. I suspect some
tests starting passing as a result of this!


>
> Before this patch we use email.Parser.Parser() from the email module which
> is
> not available on Python 3.
>
> On Python 2:
>
> >>> import email
> >>> import email.parser as emailparser
> >>> email.Parser.Parser is emailparser.Parser
> True
>
> diff --git a/hgext/convert/gnuarch.py b/hgext/convert/gnuarch.py
> --- a/hgext/convert/gnuarch.py
> +++ b/hgext/convert/gnuarch.py
> @@ -7,7 +7,7 @@
>  # GNU General Public License version 2 or any later version.
>  from __future__ import absolute_import
>
> -import email
> +import email.parser as emailparser
>  import os
>  import shutil
>  import stat
> @@ -63,7 +63,7 @@
>          self.changes = {}
>          self.parents = {}
>          self.tags = {}
> -        self.catlogparser = email.Parser.Parser()
> +        self.catlogparser = emailparser.Parser()
>          self.encoding = encoding.encoding
>          self.archives = []
>
> diff --git a/hgext/notify.py b/hgext/notify.py
> --- a/hgext/notify.py
> +++ b/hgext/notify.py
> @@ -135,6 +135,7 @@
>  from __future__ import absolute_import
>
>  import email
> +import email.parser as emailparser
>  import fnmatch
>  import socket
>  import time
> @@ -339,7 +340,7 @@
>                            'and revset\n')
>              return
>
> -        p = email.Parser.Parser()
> +        p = emailparser.Parser()
>          try:
>              msg = p.parsestr(data)
>          except email.Errors.MessageParseError as inst:
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -12,6 +12,7 @@
>  import copy
>  import difflib
>  import email
> +import email.parser as emailparser
>  import errno
>  import hashlib
>  import os
> @@ -108,7 +109,7 @@
>              cur.append(line)
>          c = chunk(cur)
>
> -        m = email.Parser.Parser().parse(c)
> +        m = emailparser.Parser().parse(c)
>          if not m.is_multipart():
>              yield msgfp(m)
>          else:
> @@ -217,7 +218,7 @@
>      fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
>      tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
>      try:
> -        msg = email.Parser.Parser().parse(fileobj)
> +        msg = emailparser.Parser().parse(fileobj)
>
>          subject = msg['Subject'] and mail.headdecode(msg['Subject'])
>          data['user'] = msg['From'] and mail.headdecode(msg['From'])
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/hgext/convert/gnuarch.py b/hgext/convert/gnuarch.py
--- a/hgext/convert/gnuarch.py
+++ b/hgext/convert/gnuarch.py
@@ -7,7 +7,7 @@ 
 # GNU General Public License version 2 or any later version.
 from __future__ import absolute_import
 
-import email
+import email.parser as emailparser
 import os
 import shutil
 import stat
@@ -63,7 +63,7 @@ 
         self.changes = {}
         self.parents = {}
         self.tags = {}
-        self.catlogparser = email.Parser.Parser()
+        self.catlogparser = emailparser.Parser()
         self.encoding = encoding.encoding
         self.archives = []
 
diff --git a/hgext/notify.py b/hgext/notify.py
--- a/hgext/notify.py
+++ b/hgext/notify.py
@@ -135,6 +135,7 @@ 
 from __future__ import absolute_import
 
 import email
+import email.parser as emailparser
 import fnmatch
 import socket
 import time
@@ -339,7 +340,7 @@ 
                           'and revset\n')
             return
 
-        p = email.Parser.Parser()
+        p = emailparser.Parser()
         try:
             msg = p.parsestr(data)
         except email.Errors.MessageParseError as inst:
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -12,6 +12,7 @@ 
 import copy
 import difflib
 import email
+import email.parser as emailparser
 import errno
 import hashlib
 import os
@@ -108,7 +109,7 @@ 
             cur.append(line)
         c = chunk(cur)
 
-        m = email.Parser.Parser().parse(c)
+        m = emailparser.Parser().parse(c)
         if not m.is_multipart():
             yield msgfp(m)
         else:
@@ -217,7 +218,7 @@ 
     fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
     tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
     try:
-        msg = email.Parser.Parser().parse(fileobj)
+        msg = emailparser.Parser().parse(fileobj)
 
         subject = msg['Subject'] and mail.headdecode(msg['Subject'])
         data['user'] = msg['From'] and mail.headdecode(msg['From'])