changeset 35633:a981ab2a1b4c

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
author Pulkit Goyal <7895pulkit@gmail.com>
date Sat, 30 Dec 2017 00:13:56 +0530
parents fa9747e7fc86
children b43578ec483a
files hgext/convert/gnuarch.py hgext/notify.py mercurial/patch.py
diffstat 3 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/gnuarch.py	Fri Jan 12 22:18:42 2018 +0900
+++ b/hgext/convert/gnuarch.py	Sat Dec 30 00:13:56 2017 +0530
@@ -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 = []
 
--- a/hgext/notify.py	Fri Jan 12 22:18:42 2018 +0900
+++ b/hgext/notify.py	Sat Dec 30 00:13:56 2017 +0530
@@ -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:
--- a/mercurial/patch.py	Fri Jan 12 22:18:42 2018 +0900
+++ b/mercurial/patch.py	Sat Dec 30 00:13:56 2017 +0530
@@ -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'])