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 47621429E54
\r
6 for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 05:10:10 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 uxVkOKMapNY1 for <notmuch@notmuchmail.org>;
\r
16 Sun, 22 Jan 2012 05:10: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 2C9FE429E40
\r
21 for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 05:10:09 -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 6487B52C70D
\r
26 for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 14:10:07 +0100 (CET)
\r
27 Received: by mail.jade-hamburg.de (Postfix, from userid 401)
\r
28 id 783C9DF2A3; Sun, 22 Jan 2012 14:10:06 +0100 (CET)
\r
29 Received: from thinkbox.jade-hamburg.de (unknown [10.1.1.109])
\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 EF7B4DF2A0;
\r
33 Sun, 22 Jan 2012 14:10:01 +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 1RoxBI-0004iZ-VU; Sun, 22 Jan 2012 14:10:01 +0100
\r
37 From: Justus Winter <4winter@informatik.uni-hamburg.de>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH] python: fix error handling
\r
40 Date: Sun, 22 Jan 2012 14:09:35 +0100
\r
42 <1327237776-18100-1-git-send-email-4winter@informatik.uni-hamburg.de>
\r
43 X-Mailer: git-send-email 1.7.8.3
\r
44 In-Reply-To: <87obtvc42c.fsf@zancas.localnet>
\r
45 References: <87obtvc42c.fsf@zancas.localnet>
\r
46 X-BeenThere: notmuch@notmuchmail.org
\r
47 X-Mailman-Version: 2.1.13
\r
49 List-Id: "Use and development of the notmuch mail system."
\r
50 <notmuch.notmuchmail.org>
\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
54 List-Post: <mailto:notmuch@notmuchmail.org>
\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
58 X-List-Received-Date: Sun, 22 Jan 2012 13:10:10 -0000
\r
60 Before 3434d1940 the return values of libnotmuch functions were
\r
61 declared as c_void_p and the code checking for errors compared the
\r
62 returned value to None, which is the ctypes equivalent of a NULL
\r
65 But said commit wrapped all the data types in python classes and the
\r
66 semantic changed in a subtle way. If a function returns NULL, the
\r
67 wrapped python value is falsish, but no longer equal to None.
\r
69 Backported from master to 0.11.
\r
71 bindings/python/notmuch/database.py | 16 ++++++++--------
\r
72 bindings/python/notmuch/filename.py | 2 +-
\r
73 bindings/python/notmuch/message.py | 6 +++---
\r
74 bindings/python/notmuch/tag.py | 2 +-
\r
75 bindings/python/notmuch/thread.py | 6 +++---
\r
76 5 files changed, 16 insertions(+), 16 deletions(-)
\r
78 diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
\r
79 index 7923f76..0074ba3 100644
\r
80 --- a/bindings/python/notmuch/database.py
\r
81 +++ b/bindings/python/notmuch/database.py
\r
82 @@ -168,7 +168,7 @@ class Database(object):
\r
84 res = Database._create(_str(path), Database.MODE.READ_WRITE)
\r
89 message="Could not create the specified database")
\r
91 @@ -188,7 +188,7 @@ class Database(object):
\r
93 res = Database._open(_str(path), mode)
\r
97 raise NotmuchError(message="Could not open the specified database")
\r
100 @@ -645,7 +645,7 @@ class Query(object):
\r
102 # create query, return None if too little mem available
\r
103 query_p = Query._create(db.db_p, _str(querystr))
\r
104 - if query_p is None:
\r
106 raise NullPointerError
\r
107 self._query = query_p
\r
109 @@ -679,7 +679,7 @@ class Query(object):
\r
110 self._assert_query_is_initialized()
\r
111 threads_p = Query._search_threads(self._query)
\r
113 - if threads_p is None:
\r
114 + if not threads_p:
\r
115 raise NullPointerError
\r
116 return Threads(threads_p, self)
\r
118 @@ -693,7 +693,7 @@ class Query(object):
\r
119 self._assert_query_is_initialized()
\r
120 msgs_p = Query._search_messages(self._query)
\r
122 - if msgs_p is None:
\r
124 raise NullPointerError
\r
125 return Messages(msgs_p, self)
\r
127 @@ -759,7 +759,7 @@ class Directory(object):
\r
128 def _assert_dir_is_initialized(self):
\r
129 """Raises a NotmuchError(:attr:`STATUS`.NOT_INITIALIZED)
\r
130 if dir_p is None"""
\r
131 - if self._dir_p is None:
\r
132 + if not self._dir_p:
\r
133 raise NotmuchError(STATUS.NOT_INITIALIZED)
\r
135 def __init__(self, path, dir_p, parent):
\r
136 @@ -920,7 +920,7 @@ class Filenames(object):
\r
137 _move_to_next.restype = None
\r
140 - if self._files_p is None:
\r
141 + if not self._files_p:
\r
142 raise NotmuchError(STATUS.NOT_INITIALIZED)
\r
144 if not self._valid(self._files_p):
\r
145 @@ -946,7 +946,7 @@ class Filenames(object):
\r
146 # NotmuchError(:attr:`STATUS`.NOT_INITIALIZED)
\r
147 for file in files: print file
\r
149 - if self._files_p is None:
\r
150 + if not self._files_p:
\r
151 raise NotmuchError(STATUS.NOT_INITIALIZED)
\r
154 diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py
\r
155 index a7cd7e6..f7313ec 100644
\r
156 --- a/bindings/python/notmuch/filename.py
\r
157 +++ b/bindings/python/notmuch/filename.py
\r
158 @@ -69,7 +69,7 @@ class Filenames(object):
\r
159 reference to it, so we can automatically delete the db object
\r
160 once all derived objects are dead.
\r
162 - if files_p is None:
\r
164 raise NotmuchError(STATUS.NULL_POINTER)
\r
166 self._files = files_p
\r
167 diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
\r
168 index ce8e718..5540df3 100644
\r
169 --- a/bindings/python/notmuch/message.py
\r
170 +++ b/bindings/python/notmuch/message.py
\r
171 @@ -116,7 +116,7 @@ class Messages(object):
\r
172 :TODO: Make the iterator work more than once and cache the tags in
\r
173 the Python object.(?)
\r
175 - if msgs_p is None:
\r
177 raise NotmuchError(STATUS.NULL_POINTER)
\r
179 self._msgs = msgs_p
\r
180 @@ -321,7 +321,7 @@ class Message(object):
\r
181 automatically delete the parent object once all derived
\r
184 - if msg_p is None:
\r
186 raise NotmuchError(STATUS.NULL_POINTER)
\r
188 #keep reference to parent, so we keep it alive
\r
189 @@ -380,7 +380,7 @@ class Message(object):
\r
191 msgs_p = Message._get_replies(self._msg)
\r
193 - if msgs_p is None:
\r
197 return Messages(msgs_p, self)
\r
198 diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
\r
199 index 2fb7d32..4881db9 100644
\r
200 --- a/bindings/python/notmuch/tag.py
\r
201 +++ b/bindings/python/notmuch/tag.py
\r
202 @@ -70,7 +70,7 @@ class Tags(object):
\r
203 :TODO: Make the iterator optionally work more than once by
\r
204 cache the tags in the Python object(?)
\r
206 - if tags_p is None:
\r
208 raise NotmuchError(STATUS.NULL_POINTER)
\r
210 self._tags = tags_p
\r
211 diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
\r
212 index 5058846..594fa52 100644
\r
213 --- a/bindings/python/notmuch/thread.py
\r
214 +++ b/bindings/python/notmuch/thread.py
\r
215 @@ -97,7 +97,7 @@ class Threads(object):
\r
216 :TODO: Make the iterator work more than once and cache the tags in
\r
217 the Python object.(?)
\r
219 - if threads_p is None:
\r
220 + if not threads_p:
\r
221 raise NotmuchError(STATUS.NULL_POINTER)
\r
223 self._threads = threads_p
\r
224 @@ -227,7 +227,7 @@ class Thread(object):
\r
225 automatically delete the parent object once all derived
\r
228 - if thread_p is None:
\r
230 raise NotmuchError(STATUS.NULL_POINTER)
\r
231 self._thread = thread_p
\r
232 #keep reference to parent, so we keep it alive
\r
233 @@ -288,7 +288,7 @@ class Thread(object):
\r
235 msgs_p = Thread._get_toplevel_messages(self._thread)
\r
237 - if msgs_p is None:
\r
239 raise NotmuchError(STATUS.NULL_POINTER)
\r
241 return Messages(msgs_p, self)
\r