Patchwork D2147: py3: use email parser that operates on bytes

login
register
mail settings
Submitter phabricator
Date Feb. 12, 2018, 1:40 a.m.
Message ID <ac2658b9e18ebf8b10311166deb14fb5@localhost.localdomain>
Download mbox | patch
Permalink /patch/27618/
State Not Applicable
Headers show

Comments

phabricator - Feb. 12, 2018, 1:40 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG04984f2e50ae: py3: use email parser that operates on bytes (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2147?vs=5432&id=5447

REVISION DETAIL
  https://phab.mercurial-scm.org/D2147

AFFECTED FILES
  mercurial/patch.py
  mercurial/pycompat.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -267,6 +267,10 @@ 
         ret = shlex.split(s.decode('latin-1'))
         return [a.encode('latin-1') for a in ret]
 
+    def emailparser(*args, **kwargs):
+        import email.parser
+        return email.parser.BytesParser(*args, **kwargs)
+
 else:
     import cStringIO
 
@@ -327,6 +331,10 @@ 
     ziplist = zip
     rawinput = raw_input
 
+    def emailparser(*args, **kwargs):
+        import email.parser
+        return email.parser.Parser(*args, **kwargs)
+
 isjython = sysplatform.startswith('java')
 
 isdarwin = sysplatform == 'darwin'
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -12,7 +12,6 @@ 
 import copy
 import difflib
 import email
-import email.parser as emailparser
 import errno
 import hashlib
 import os
@@ -109,7 +108,7 @@ 
             cur.append(line)
         c = chunk(cur)
 
-        m = emailparser.Parser().parse(c)
+        m = pycompat.emailparser().parse(c)
         if not m.is_multipart():
             yield msgfp(m)
         else:
@@ -218,7 +217,7 @@ 
     fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
     tmpfp = os.fdopen(fd, pycompat.sysstr('w'))
     try:
-        msg = emailparser.Parser().parse(fileobj)
+        msg = pycompat.emailparser().parse(fileobj)
 
         subject = msg['Subject'] and mail.headdecode(msg['Subject'])
         data['user'] = msg['From'] and mail.headdecode(msg['From'])