# HG changeset patch # User Denis Laxalde # Date 1571923680 -7200 # Node ID ef81de93143efebcded6e275b9c65df592c56d50 # Parent 7d4f2e4899c5f15b38be12bc58a51512f8cd5f5b 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. diff -r 7d4f2e4899c5 -r ef81de93143e hgext/notify.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) diff -r 7d4f2e4899c5 -r ef81de93143e mercurial/mail.py --- 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'''