py3: use a BytesParser in notify extension stable
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 24 Oct 2019 15:28:00 +0200
branchstable
changeset 43326 ef81de93143e
parent 43325 7d4f2e4899c5
child 43327 ac33550f63e8
py3: use a BytesParser in notify extension This is the first step to make the "long line" case in test-notify.t pass by fixing a UnicodeDecodeError on Python 3. We alias a parsebytes() in mail module, similarly as we already have a parse() function for Python 2 and Python 3 compatibility.
hgext/notify.py
mercurial/mail.py
--- a/hgext/notify.py	Thu Oct 24 17:16:43 2019 +0200
+++ b/hgext/notify.py	Thu Oct 24 15:28:00 2019 +0200
@@ -148,7 +148,6 @@
 from __future__ import absolute_import
 
 import email.errors as emailerrors
-import email.parser as emailparser
 import fnmatch
 import hashlib
 import socket
@@ -382,9 +381,8 @@
             )
             return
 
-        p = emailparser.Parser()
         try:
-            msg = p.parsestr(encoding.strfromlocal(data))
+            msg = mail.parsebytes(data)
         except emailerrors.MessageParseError as inst:
             raise error.Abort(inst)
 
--- a/mercurial/mail.py	Thu Oct 24 17:16:43 2019 +0200
+++ b/mercurial/mail.py	Thu Oct 24 15:28:00 2019 +0200
@@ -440,6 +440,9 @@
         finally:
             fp.detach()
 
+    def parsebytes(data):
+        ep = email.parser.BytesParser()
+        return ep.parsebytes(data)
 
 else:
 
@@ -449,6 +452,10 @@
         ep = email.parser.Parser()
         return ep.parse(fp)
 
+    def parsebytes(data):
+        ep = email.parser.Parser()
+        return ep.parsestr(data)
+
 
 def headdecode(s):
     '''Decodes RFC-2047 header'''