Patchwork [2,of,2] patchbomb: use mail.Generator alias for py2/py3 compat

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 10, 2019, 8:58 a.m.
Message ID <8d90bbd4598cd7ca521e.1570697930@steppe.local>
Download mbox | patch
Permalink /patch/42180/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 10, 2019, 8:58 a.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1570697593 -7200
#      Thu Oct 10 10:53:13 2019 +0200
# Node ID 8d90bbd4598cd7ca521e007a2b30fe1990127dff
# Parent  707fc6aeadc33b02888e057e549c05d886fb67b0
patchbomb: use mail.Generator alias for py2/py3 compat

Patch

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
index 711e9bc..d0095ba 100644
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -74,7 +74,6 @@  You can set patchbomb to always ask for 
 from __future__ import absolute_import
 
 import email.encoders as emailencoders
-import email.generator as emailgen
 import email.mime.base as emimebase
 import email.mime.multipart as emimemultipart
 import email.utils as eutil
@@ -141,11 +140,6 @@  configitem(
     b'patchbomb', b'to', default=None,
 )
 
-if pycompat.ispy3:
-    _bytesgenerator = emailgen.BytesGenerator
-else:
-    _bytesgenerator = emailgen.Generator
-
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
@@ -976,7 +970,7 @@  def email(ui, repo, *revs, **opts):
         if opts.get(b'test'):
             ui.status(_(b'displaying '), subj, b' ...\n')
             ui.pager(b'email')
-            generator = _bytesgenerator(ui, mangle_from_=False)
+            generator = mail.Generator(ui, mangle_from_=False)
             try:
                 generator.flatten(m, 0)
                 ui.write(b'\n')
@@ -992,7 +986,7 @@  def email(ui, repo, *revs, **opts):
                 # Exim does not remove the Bcc field
                 del m[b'Bcc']
             fp = stringio()
-            generator = _bytesgenerator(fp, mangle_from_=False)
+            generator = mail.Generator(fp, mangle_from_=False)
             generator.flatten(m, 0)
             alldests = to + bcc + cc
             alldests = [encoding.strfromlocal(d) for d in alldests]