Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 73 / a4be0fe31a7f7fafb79fb95294f27e0cebf976
1 Return-Path: <wking@tremily.us>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id DA9BC429E37\r
6         for <notmuch@notmuchmail.org>; Mon,  3 Feb 2014 03:00:52 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: 0\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
13         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001]\r
14         autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id oufyJVMxC3mG for <notmuch@notmuchmail.org>;\r
18         Mon,  3 Feb 2014 03:00:44 -0800 (PST)\r
19 Received: from qmta06.westchester.pa.mail.comcast.net\r
20         (qmta06.westchester.pa.mail.comcast.net [76.96.62.56])\r
21         by olra.theworths.org (Postfix) with ESMTP id 346BD431E82\r
22         for <notmuch@notmuchmail.org>; Mon,  3 Feb 2014 03:00:40 -0800 (PST)\r
23 Received: from omta24.westchester.pa.mail.comcast.net ([76.96.62.76])\r
24         by qmta06.westchester.pa.mail.comcast.net with comcast\r
25         id Mmyc1n0051ei1Bg56n0fTQ; Mon, 03 Feb 2014 11:00:39 +0000\r
26 Received: from odin.tremily.us ([24.18.63.50])\r
27         by omta24.westchester.pa.mail.comcast.net with comcast\r
28         id Mn0e1n00C152l3L3kn0fgZ; Mon, 03 Feb 2014 11:00:39 +0000\r
29 Received: from mjolnir.tremily.us (unknown [192.168.0.140])\r
30         by odin.tremily.us (Postfix) with ESMTPS id 66E23FB4D45;\r
31         Mon,  3 Feb 2014 03:00:38 -0800 (PST)\r
32 Received: (nullmailer pid 682 invoked by uid 1000);\r
33         Mon, 03 Feb 2014 10:59:41 -0000\r
34 From: "W. Trevor King" <wking@tremily.us>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: [PATCH 03/17] nmbug-status: Decode Popen output using the user's\r
37         locale\r
38 Date: Mon,  3 Feb 2014 02:59:21 -0800\r
39 Message-Id:\r
40  <9a07face73274cbb977b8a8e4e983e64b0863531.1391424512.git.wking@tremily.us>\r
41 X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1\r
42 In-Reply-To: <cover.1391424512.git.wking@tremily.us>\r
43 References: <cover.1391424512.git.wking@tremily.us>\r
44 In-Reply-To: <cover.1391424512.git.wking@tremily.us>\r
45 References: <cover.1391424512.git.wking@tremily.us>\r
46 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;\r
47         s=q20121106; t=1391425239;\r
48         bh=1aQ15C7VOfb5SpJX2PiuZjmexLCSbY7tx6l56EDHxmQ=;\r
49         h=Received:Received:Received:Received:From:To:Subject:Date:\r
50         Message-Id;\r
51         b=TMdHbFIg1lQ9PJ/IDfoz4OhY9vahsGG0R3YCe5MBoAzaf+MNVMU06dDvGvKTEUWVU\r
52         JOulrby7W7CTKT/rl+Z1fgMOtM2BkrxNH7GfnSbb/Rc3CDl746r8siK6dkmuqJn+RN\r
53         RQMUa4lxZ/JxZy/QoBZQGMclg38f+HphLVaC7cBKDb2cAOZkA/89Hs/kdGorRECbHM\r
54         gLfAaqneASlg0a9gkIgeOc/th6BM1coiQtBmgwU5gczB/jYugniguauHAUARcz03gG\r
55         7Ms43ojc7q177Di5HDfMvVM+tKUVD/TFS1so0NZ4yTc8aMkZNu+O/Wr1+v4Q9+NK5v\r
56         WHQuBEEVaeUFA==\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Mon, 03 Feb 2014 11:00:53 -0000\r
70 \r
71 Avoid:\r
72 \r
73   $ ./nmbug-status --list-views\r
74   Traceback (most recent call last):\r
75     File "./nmbug-status", line 47, in <module>\r
76       'cat-file', 'blob', sha1+':status-config.json'],\r
77   TypeError: can't concat bytes to str\r
78 \r
79 by explicitly converting the byte-stream read from Popen into a\r
80 Unicode string.  On Python 2, this conversion is str -> unicode; on\r
81 Python 3 it is bytes -> str.\r
82 \r
83 _ENCODING is derived from the user's locale (or system default) in an\r
84 attempt to match Git's output encoding.  It may be more robust to skip\r
85 the encoding/decoding by using a Python wrapper like pygit2 [1] for\r
86 Git access.  That's a fairly heavy dependency though, and using the\r
87 locale will probably work.\r
88 \r
89 [1]: http://www.pygit2.org/\r
90 ---\r
91  devel/nmbug/nmbug-status | 25 ++++++++++++++++---------\r
92  1 file changed, 16 insertions(+), 9 deletions(-)\r
93 \r
94 diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status\r
95 index 6525176..a7a391d 100755\r
96 --- a/devel/nmbug/nmbug-status\r
97 +++ b/devel/nmbug/nmbug-status\r
98 @@ -8,8 +8,10 @@\r
99  \r
100  from __future__ import print_function\r
101  \r
102 +import codecs\r
103  import datetime\r
104  import email.utils\r
105 +import locale\r
106  import urllib\r
107  import json\r
108  import argparse\r
109 @@ -17,6 +19,10 @@ import os\r
110  import sys\r
111  import subprocess\r
112  \r
113 +\r
114 +_ENCODING = locale.getpreferredencoding() or sys.getdefaultencoding()\r
115 +\r
116 +\r
117  # parse command line arguments\r
118  \r
119  parser = argparse.ArgumentParser()\r
120 @@ -37,15 +43,16 @@ else:\r
121      nmbhome = os.getenv('NMBGIT', os.path.expanduser('~/.nmbug'))\r
122  \r
123      # read only the first line from the pipe\r
124 -    sha1 = subprocess.Popen(['git', '--git-dir', nmbhome,\r
125 -                             'show-ref', '-s', 'config'],\r
126 -                            stdout=subprocess.PIPE).stdout.readline()\r
127 -\r
128 -    sha1 = sha1.rstrip()\r
129 -\r
130 -    fp = subprocess.Popen(['git', '--git-dir', nmbhome,\r
131 -                           'cat-file', 'blob', sha1+':status-config.json'],\r
132 -                          stdout=subprocess.PIPE).stdout\r
133 +    sha1_bytes = subprocess.Popen(\r
134 +        ['git', '--git-dir', nmbhome, 'show-ref', '-s', 'config'],\r
135 +        stdout=subprocess.PIPE).stdout.readline()\r
136 +    sha1 = sha1_bytes.decode(_ENCODING).rstrip()\r
137 +\r
138 +    fp_byte_stream = subprocess.Popen(\r
139 +        ['git', '--git-dir', nmbhome, 'cat-file', 'blob',\r
140 +         sha1+':status-config.json'],\r
141 +        stdout=subprocess.PIPE).stdout\r
142 +    fp = codecs.getreader(encoding=_ENCODING)(stream=fp_byte_stream)\r
143  \r
144  config = json.load(fp)\r
145  \r
146 -- \r
147 1.8.5.2.8.g0f6c0d1\r
148 \r