[PATCH 1 of 2] py3: use email.generator.BytesGenerator in patch.split()

Denis Laxalde denis at laxalde.org
Thu Oct 10 04:58:49 EDT 2019


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1570697337 -7200
#      Thu Oct 10 10:48:57 2019 +0200
# Node ID 707fc6aeadc33b02888e057e549c05d886fb67b0
# Parent  52781d57313d512efb7150603104bea3ca11d0eb
py3: use email.generator.BytesGenerator in patch.split()

This fixes test-import.t on python3.

We add Generator alias in mail module to handle python2/python3
compatibility.

diff --git a/mercurial/mail.py b/mercurial/mail.py
index b478f38..8ee25bf 100644
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -420,6 +420,8 @@ def mimeencode(ui, s, charsets=None, dis
 
 if pycompat.ispy3:
 
+    Generator = email.generator.BytesGenerator
+
     def parse(fp):
         ep = email.parser.Parser()
         # disable the "universal newlines" mode, which isn't binary safe.
@@ -436,6 +438,8 @@ if pycompat.ispy3:
 
 else:
 
+    Generator = email.generator.Generator
+
     def parse(fp):
         ep = email.parser.Parser()
         return ep.parse(fp)
diff --git a/mercurial/patch.py b/mercurial/patch.py
index 927b798..68ae21f 100644
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -11,7 +11,6 @@ from __future__ import absolute_import, 
 import collections
 import contextlib
 import copy
-import email
 import errno
 import hashlib
 import os
@@ -107,7 +106,7 @@ def split(stream):
     def mimesplit(stream, cur):
         def msgfp(m):
             fp = stringio()
-            g = email.Generator.Generator(fp, mangle_from_=False)
+            g = mail.Generator(fp, mangle_from_=False)
             g.flatten(m)
             fp.seek(0)
             return fp


More information about the Mercurial-devel mailing list