[PATCH 6/7] py3k: Add and use a mixin class that implements __str__
[notmuch-archives.git] / bb / 2de0e0fbe34d23e388c0adeeb6b73b66c682fb
1 Return-Path: <teythoon@jade-hamburg.de>\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 C5A47429E30\r
6         for <notmuch@notmuchmail.org>; Wed, 14 Dec 2011 02:59:12 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id fMgscPraLskf for <notmuch@notmuchmail.org>;\r
16         Wed, 14 Dec 2011 02:59:09 -0800 (PST)\r
17 Received: from mail.cryptobitch.de (cryptobitch.de [88.198.7.68])\r
18         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 803F1429E3B\r
21         for <notmuch@notmuchmail.org>; Wed, 14 Dec 2011 02:59:04 -0800 (PST)\r
22 Received: from mail.jade-hamburg.de (unknown [85.183.11.228])\r
23         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
24         (No client certificate requested)\r
25         by mail.cryptobitch.de (Postfix) with ESMTPSA id 4716850F614\r
26         for <notmuch@notmuchmail.org>; Wed, 14 Dec 2011 11:59:03 +0100 (CET)\r
27 Received: by mail.jade-hamburg.de (Postfix, from userid 401)\r
28         id BE8C7DF2A0; Wed, 14 Dec 2011 11:59:02 +0100 (CET)\r
29 Received: from thinkbox.jade-hamburg.de (unknown [85.183.11.228])\r
30         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
31         (No client certificate requested) (Authenticated sender: teythoon)\r
32         by mail.jade-hamburg.de (Postfix) with ESMTPSA id 37527DF2A5;\r
33         Wed, 14 Dec 2011 11:58:48 +0100 (CET)\r
34 Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.77)\r
35         (envelope-from <teythoon@thinkbox.jade-hamburg.de>)\r
36         id 1RamXs-0004Mh-3I; Wed, 14 Dec 2011 11:58:44 +0100\r
37 From: Justus Winter <4winter@informatik.uni-hamburg.de>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 6/7] py3k: Add and use a mixin class that implements __str__\r
40 Date: Wed, 14 Dec 2011 11:58:24 +0100\r
41 Message-Id:\r
42  <1323860305-15802-7-git-send-email-4winter@informatik.uni-hamburg.de>\r
43 X-Mailer: git-send-email 1.7.7.3\r
44 In-Reply-To:\r
45  <1323860305-15802-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
46 References:\r
47  <1323860305-15802-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
48 X-BeenThere: notmuch@notmuchmail.org\r
49 X-Mailman-Version: 2.1.13\r
50 Precedence: list\r
51 List-Id: "Use and development of the notmuch mail system."\r
52         <notmuch.notmuchmail.org>\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
56 List-Post: <mailto:notmuch@notmuchmail.org>\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
59         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
60 X-List-Received-Date: Wed, 14 Dec 2011 10:59:13 -0000\r
61 \r
62 ---\r
63  bindings/python/notmuch/filename.py |    7 ++-----\r
64  bindings/python/notmuch/globals.py  |   15 +++++++++++----\r
65  bindings/python/notmuch/message.py  |    8 +++-----\r
66  bindings/python/notmuch/tag.py      |    7 ++-----\r
67  bindings/python/notmuch/thread.py   |    6 +++---\r
68  5 files changed, 21 insertions(+), 22 deletions(-)\r
69 \r
70 diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py\r
71 index a7cd7e6..969931a 100644\r
72 --- a/bindings/python/notmuch/filename.py\r
73 +++ b/bindings/python/notmuch/filename.py\r
74 @@ -18,10 +18,10 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'\r
75  """\r
76  from ctypes import c_char_p\r
77  from notmuch.globals import (nmlib, STATUS, NotmuchError,\r
78 -    NotmuchFilenamesP, NotmuchMessageP)\r
79 +    NotmuchFilenamesP, NotmuchMessageP, _str, Python3StringMixIn)\r
80  \r
81  \r
82 -class Filenames(object):\r
83 +class Filenames(Python3StringMixIn):\r
84      """Represents a list of filenames as returned by notmuch\r
85  \r
86      This object contains the Filenames iterator. The main function is\r
87 @@ -98,9 +98,6 @@ class Filenames(object):\r
88  \r
89          self._files = None\r
90  \r
91 -    def __str__(self):\r
92 -        return unicode(self).encode('utf-8')\r
93 -\r
94      def __unicode__(self):\r
95          """Represent Filenames() as newline-separated list of full paths\r
96  \r
97 diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py\r
98 index c52790c..2111b86 100644\r
99 --- a/bindings/python/notmuch/globals.py\r
100 +++ b/bindings/python/notmuch/globals.py\r
101 @@ -28,6 +28,16 @@ except:\r
102      raise ImportError("Could not find shared 'notmuch' library.")\r
103  \r
104  \r
105 +if sys.version_info[0] == 2:\r
106 +    class Python3StringMixIn(object):\r
107 +        def __str__(self):\r
108 +            return unicode(self).encode('utf-8')\r
109 +else:\r
110 +    class Python3StringMixIn(object):\r
111 +        def __str__(self):\r
112 +            return self.__unicode__()\r
113 +\r
114 +\r
115  class Enum(object):\r
116      """Provides ENUMS as "code=Enum(['a','b','c'])" where code.a=0 etc..."""\r
117      def __init__(self, names):\r
118 @@ -90,7 +100,7 @@ argument to receive a human readable string"""\r
119  STATUS.__name__ = 'STATUS'\r
120  \r
121  \r
122 -class NotmuchError(Exception):\r
123 +class NotmuchError(Exception, Python3StringMixIn):\r
124      """Is initiated with a (notmuch.STATUS[, message=None]). It will not\r
125      return an instance of the class NotmuchError, but a derived instance\r
126      of a more specific Error Message, e.g. OutOfMemoryError. Each status\r
127 @@ -134,9 +144,6 @@ class NotmuchError(Exception):\r
128          self.status = status\r
129          self.message = message\r
130  \r
131 -    def __str__(self):\r
132 -        return unicode(self).encode('utf-8')\r
133 -\r
134      def __unicode__(self):\r
135          if self.message is not None:\r
136              return self.message\r
137 diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py\r
138 index bf0c4da..955382d 100644\r
139 --- a/bindings/python/notmuch/message.py\r
140 +++ b/bindings/python/notmuch/message.py\r
141 @@ -21,7 +21,8 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'\r
142  \r
143  from ctypes import c_char_p, c_long, c_uint, c_int\r
144  from datetime import date\r
145 -from notmuch.globals import (nmlib, STATUS, NotmuchError, Enum, _str,\r
146 +from notmuch.globals import (\r
147 +    nmlib, STATUS, NotmuchError, Enum, _str, Python3StringMixIn,\r
148      NotmuchTagsP, NotmuchMessagesP, NotmuchMessageP, NotmuchFilenamesP)\r
149  from notmuch.tag import Tags\r
150  from notmuch.filename import Filenames\r
151 @@ -239,7 +240,7 @@ class Messages(object):\r
152          sys.stdout.write(set_end)\r
153  \r
154  \r
155 -class Message(object):\r
156 +class Message(Python3StringMixIn):\r
157      """Represents a single Email message\r
158  \r
159      Technically, this wraps the underlying *notmuch_message_t*\r
160 @@ -796,9 +797,6 @@ class Message(object):\r
161          """Represent a Message() object by str()"""\r
162          return self.__str__()\r
163  \r
164 -    def __str__(self):\r
165 -        return unicode(self).encode('utf-8')\r
166 -\r
167      def __unicode__(self):\r
168          format = "%s (%s) (%s)"\r
169          return format % (self.get_header('from'),\r
170 diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py\r
171 index d42ba77..ceb7244 100644\r
172 --- a/bindings/python/notmuch/tag.py\r
173 +++ b/bindings/python/notmuch/tag.py\r
174 @@ -17,10 +17,10 @@ along with notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
175  Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'\r
176  """\r
177  from ctypes import c_char_p\r
178 -from notmuch.globals import nmlib, STATUS, NotmuchError, NotmuchTagsP\r
179 +from notmuch.globals import nmlib, STATUS, NotmuchError, NotmuchTagsP, _str, Python3StringMixIn\r
180  \r
181  \r
182 -class Tags(object):\r
183 +class Tags(Python3StringMixIn):\r
184      """Represents a list of notmuch tags\r
185  \r
186      This object provides an iterator over a list of notmuch tags (which\r
187 @@ -111,9 +111,6 @@ class Tags(object):\r
188              left."""\r
189          return self._valid(self._tags) > 0\r
190  \r
191 -    def __str__(self):\r
192 -        return unicode(self).encode('utf-8')\r
193 -\r
194      def __unicode__(self):\r
195          """string representation of :class:`Tags`: a space separated list of tags\r
196  \r
197 diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py\r
198 index 39285d6..3912957 100644\r
199 --- a/bindings/python/notmuch/thread.py\r
200 +++ b/bindings/python/notmuch/thread.py\r
201 @@ -20,13 +20,13 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'\r
202  from ctypes import c_char_p, c_long, c_int\r
203  from notmuch.globals import (nmlib, STATUS,\r
204      NotmuchError, NotmuchThreadP, NotmuchThreadsP, NotmuchMessagesP,\r
205 -    NotmuchTagsP,)\r
206 +    NotmuchTagsP, Python3StringMixIn)\r
207  from notmuch.message import Messages\r
208  from notmuch.tag import Tags\r
209  from datetime import date\r
210  \r
211  \r
212 -class Threads(object):\r
213 +class Threads(Python3StringMixIn):\r
214      """Represents a list of notmuch threads\r
215  \r
216      This object provides an iterator over a list of notmuch threads\r
217 @@ -393,7 +393,7 @@ class Thread(object):\r
218          return Tags(tags_p, self)\r
219  \r
220      def __str__(self):\r
221 -        return unicode(self).encode('utf-8')\r
222 +        return self.__unicode__().encode('utf-8')\r
223  \r
224      def __unicode__(self):\r
225          frm = "thread:%s %12s [%d/%d] %s; %s (%s)"\r
226 -- \r
227 1.7.7.3\r
228 \r