Patchwork [2,of,3] py3: convert parsed message items to bytes in patch.extract()

login
register
mail settings
Submitter Yuya Nishihara
Date April 7, 2018, 5:32 a.m.
Message ID <e500a16779ebbd095bac.1523079169@mimosa>
Download mbox | patch
Permalink /patch/30516/
State Accepted
Headers show

Comments

Yuya Nishihara - April 7, 2018, 5:32 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1523076157 -32400
#      Sat Apr 07 13:42:37 2018 +0900
# Node ID e500a16779ebbd095bacc793a42ff57a91c47737
# Parent  5f401721fa2a4ba1e5b5ea570c9c0978481a20f7
py3: convert parsed message items to bytes in patch.extract()

Appears that BytesParser() parses bytes into unicode, sigh.
Pulkit Goyal - April 7, 2018, 9:10 a.m.
On Sat, Apr 7, 2018 at 11:02 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1523076157 -32400
> #      Sat Apr 07 13:42:37 2018 +0900
> # Node ID e500a16779ebbd095bacc793a42ff57a91c47737
> # Parent  5f401721fa2a4ba1e5b5ea570c9c0978481a20f7
> py3: convert parsed message items to bytes in patch.extract()
>
> Appears that BytesParser() parses bytes into unicode, sigh.

https://giphy.com/gifs/truthorange-cat-surprised-what-angry-glare-xThuW4BaAA2f7nRvoc/fullscreen

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -228,7 +228,8 @@  def extract(ui, fileobj):
         data['user'] = msg['From'] and mail.headdecode(msg['From'])
         if not subject and not data['user']:
             # Not an email, restore parsed headers if any
-            subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n'
+            subject = '\n'.join(': '.join(map(encoding.strtolocal, h))
+                                for h in msg.items()) + '\n'
 
         # should try to parse msg['Date']
         parents = []