mail: use a native string for "subtype" value
This is somehow similar to previous changeset and avoids one str
conversion.
--- a/hgext/patchbomb.py Tue Nov 12 22:52:30 2019 +0100
+++ b/hgext/patchbomb.py Wed Nov 13 15:23:04 2019 +0100
@@ -285,7 +285,7 @@
if body:
msg.attach(mail.mimeencode(ui, body, _charsets, opts.get(b'test')))
p = mail.mimetextpatch(
- b'\n'.join(patchlines), b'x-patch', opts.get(b'test')
+ b'\n'.join(patchlines), 'x-patch', opts.get(b'test')
)
binnode = nodemod.bin(node)
# if node is mq patch, it will have the patch file's name as a tag
--- a/mercurial/mail.py Tue Nov 12 22:52:30 2019 +0100
+++ b/mercurial/mail.py Wed Nov 13 15:23:04 2019 +0100
@@ -263,8 +263,8 @@
return cs
-def mimetextpatch(s, subtype=b'plain', display=False):
- # type: (bytes, bytes, bool) -> email.message.Message
+def mimetextpatch(s, subtype='plain', display=False):
+ # type: (bytes, str, bool) -> email.message.Message
'''Return MIME message suitable for a patch.
Charset will be detected by first trying to decode as us-ascii, then utf-8,
and finally the global encodings. If all those fail, fall back to
@@ -290,13 +290,13 @@
def mimetextqp(body, subtype, charset):
- # type: (bytes, bytes, str) -> email.message.Message
+ # type: (bytes, str, str) -> email.message.Message
'''Return MIME message.
Quoted-printable transfer encoding will be used if necessary.
'''
cs = email.charset.Charset(charset)
msg = email.message.Message()
- msg.set_type(pycompat.sysstr(b'text/' + subtype))
+ msg.set_type('text/' + subtype)
for line in body.splitlines():
if len(line) > 950:
@@ -450,7 +450,7 @@
cs = 'us-ascii'
if not display:
s, cs = _encode(ui, s, charsets)
- return mimetextqp(s, b'plain', cs)
+ return mimetextqp(s, 'plain', cs)
if pycompat.ispy3: