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 B977F431FD0
\r
6 for <notmuch@notmuchmail.org>; Sun, 25 Sep 2011 18:07:10 -0700 (PDT)
\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 O7Phf2ye+DsR for <notmuch@notmuchmail.org>;
\r
16 Sun, 25 Sep 2011 18:07:08 -0700 (PDT)
\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 E9DD6431FB6
\r
21 for <notmuch@notmuchmail.org>; Sun, 25 Sep 2011 18:07:07 -0700 (PDT)
\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 B529F505B24
\r
26 for <notmuch@notmuchmail.org>; Mon, 26 Sep 2011 03:07:06 +0200 (CEST)
\r
27 Received: by mail.jade-hamburg.de (Postfix, from userid 401)
\r
28 id 35F2BDF29F; Mon, 26 Sep 2011 03:07:06 +0200 (CEST)
\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 8C7B0DF2A5;
\r
33 Mon, 26 Sep 2011 03:06:14 +0200 (CEST)
\r
34 Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.76)
\r
35 (envelope-from <teythoon@thinkbox.jade-hamburg.de>)
\r
36 id 1R7ze5-0007OY-R8; Mon, 26 Sep 2011 03:06:09 +0200
\r
37 From: Justus Winter <4winter@informatik.uni-hamburg.de>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH 8/9] python: use the new exception classes and update the
\r
41 Date: Mon, 26 Sep 2011 03:05:36 +0200
\r
43 <1316999137-28257-8-git-send-email-4winter@informatik.uni-hamburg.de>
\r
44 X-Mailer: git-send-email 1.7.6.3
\r
46 <1316999137-28257-1-git-send-email-4winter@informatik.uni-hamburg.de>
\r
48 <1316999137-28257-1-git-send-email-4winter@informatik.uni-hamburg.de>
\r
49 X-Mailman-Approved-At: Mon, 26 Sep 2011 09:17:56 -0700
\r
50 Cc: Justus Winter <4winter@informatik.uni-hamburg.de>
\r
51 X-BeenThere: notmuch@notmuchmail.org
\r
52 X-Mailman-Version: 2.1.13
\r
54 List-Id: "Use and development of the notmuch mail system."
\r
55 <notmuch.notmuchmail.org>
\r
56 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
58 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
59 List-Post: <mailto:notmuch@notmuchmail.org>
\r
60 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
61 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
63 X-List-Received-Date: Mon, 26 Sep 2011 01:07:10 -0000
\r
65 Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
\r
67 bindings/python/notmuch/database.py | 138 +++++++++++++++++++++--------------
\r
68 bindings/python/notmuch/filename.py | 9 +-
\r
69 bindings/python/notmuch/message.py | 79 ++++++++++----------
\r
70 bindings/python/notmuch/tag.py | 10 ++-
\r
71 bindings/python/notmuch/thread.py | 47 ++++++------
\r
72 5 files changed, 158 insertions(+), 125 deletions(-)
\r
74 diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
\r
75 index edde70e..8df7c2f 100644
\r
76 --- a/bindings/python/notmuch/database.py
\r
77 +++ b/bindings/python/notmuch/database.py
\r
78 @@ -19,7 +19,9 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
\r
81 from ctypes import c_int, c_char_p, c_void_p, c_uint, c_long, byref
\r
82 -from notmuch.globals import nmlib, STATUS, NotmuchError, Enum, _str
\r
83 +from notmuch.globals import nmlib, STATUS, NotmuchError, Enum, _str, \
\r
84 + NotInitializedError, FileError, \
\r
86 from notmuch.thread import Threads
\r
87 from notmuch.message import Messages, Message
\r
88 from notmuch.tag import Tags
\r
89 @@ -106,9 +108,9 @@ class Database(object):
\r
92 def _assert_db_is_initialized(self):
\r
93 - """Raises a NotmuchError in case self._db is still None"""
\r
94 + """Raises a :exc:`NotInitializedError` in case self._db is still None"""
\r
95 if self._db is None:
\r
96 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
97 + raise NotInitializedError()
\r
99 def create(self, path):
\r
100 """Creates a new notmuch database
\r
101 @@ -160,7 +162,12 @@ class Database(object):
\r
102 def get_path(self):
\r
103 """Returns the file path of an open database
\r
105 - Wraps *notmuch_database_get_path*."""
\r
106 + Wraps *notmuch_database_get_path*.
\r
108 + :returns: The path to the database as string
\r
109 + :exception: :exc:`NotInitializedError` if
\r
110 + the database was not intitialized.
\r
112 self._assert_db_is_initialized()
\r
114 return Database._get_path(self._db).decode('utf-8')
\r
115 @@ -169,7 +176,7 @@ class Database(object):
\r
116 """Returns the database format version
\r
118 :returns: The database version as positive integer
\r
119 - :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
\r
120 + :exception: :exc:`NotInitializedError` if
\r
121 the database was not intitialized.
\r
123 self._assert_db_is_initialized()
\r
124 @@ -185,7 +192,7 @@ class Database(object):
\r
125 etc.) will work unless :meth:`upgrade` is called successfully first.
\r
127 :returns: `True` or `False`
\r
128 - :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
\r
129 + :exception: :exc:`NotInitializedError` if
\r
130 the database was not intitialized.
\r
132 self._assert_db_is_initialized()
\r
133 @@ -206,6 +213,9 @@ class Database(object):
\r
134 indicating the progress made so far in the upgrade process.
\r
136 :TODO: catch exceptions, document return values and etc...
\r
138 + :exception: :exc:`NotInitializedError` if
\r
139 + the database was not intitialized.
\r
141 self._assert_db_is_initialized()
\r
143 @@ -225,15 +235,14 @@ class Database(object):
\r
144 of database (see :meth:`get_path`), or else should be an absolute path
\r
145 with initial components that match the path of 'database'.
\r
146 :returns: :class:`Directory` or raises an exception.
\r
147 - :exception: :exc:`NotmuchError`
\r
148 + :exception: :exc:`NotInitializedError` or :exc:`FileError`
\r
150 - STATUS.NOT_INITIALIZED
\r
151 + :exc:`NotInitializedError`
\r
152 If the database was not intitialized.
\r
154 - STATUS.FILE_ERROR
\r
156 If path is not relative database or absolute with initial
\r
157 components same as database.
\r
160 self._assert_db_is_initialized()
\r
162 @@ -242,9 +251,8 @@ class Database(object):
\r
163 # we got an absolute path
\r
164 if not path.startswith(self.get_path()):
\r
165 # but its initial components are not equal to the db path
\r
166 - raise NotmuchError(message="Database().get_directory() called "
\r
167 - "with a wrong absolute path.",
\r
168 - status=STATUS.FILE_ERROR)
\r
169 + raise FileError("Database().get_directory() called "
\r
170 + "with a wrong absolute path.")
\r
173 #we got a relative path, make it absolute
\r
174 @@ -293,16 +301,16 @@ class Database(object):
\r
175 :exception: Raises a :exc:`NotmuchError` with the following meaning.
\r
176 If such an exception occurs, nothing was added to the database.
\r
178 - STATUS.FILE_ERROR
\r
180 An error occurred trying to open the file, (such as
\r
181 permission denied, or file not found, etc.).
\r
182 - STATUS.FILE_NOT_EMAIL
\r
183 + :exc:`FileNotEmail`
\r
184 The contents of filename don't look like an email
\r
186 - STATUS.READ_ONLY_DATABASE
\r
187 + :exc:`ReadOnlyDatabaseError`
\r
188 Database was opened in read-only mode so no message can
\r
190 - STATUS.NOT_INITIALIZED
\r
191 + :exc:`NotInitializedError`
\r
192 The database has not been initialized.
\r
194 self._assert_db_is_initialized()
\r
195 @@ -313,7 +321,7 @@ class Database(object):
\r
198 if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:
\r
199 - raise NotmuchError(status=status)
\r
200 + raise NotmuchError.decode(status)
\r
202 #construct Message() and return
\r
203 msg = Message(msg_p, self)
\r
204 @@ -345,10 +353,10 @@ class Database(object):
\r
205 If such an exception occurs, nothing was removed from the
\r
208 - STATUS.READ_ONLY_DATABASE
\r
209 + :exc:`ReadOnlyDatabaseError`
\r
210 Database was opened in read-only mode so no message can be
\r
212 - STATUS.NOT_INITIALIZED
\r
213 + :exc:`NotInitializedError`
\r
214 The database has not been initialized.
\r
216 self._assert_db_is_initialized()
\r
217 @@ -371,7 +379,7 @@ class Database(object):
\r
218 another program in the meantime. A return value of
\r
219 `None` is therefore no guarantee that the message
\r
221 - :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if
\r
222 + :exception: :exc:`NotInitializedError` if
\r
223 the database was not intitialized.
\r
225 self._assert_db_is_initialized()
\r
226 @@ -383,13 +391,13 @@ class Database(object):
\r
227 """Returns :class:`Tags` with a list of all tags found in the database
\r
229 :returns: :class:`Tags`
\r
230 - :execption: :exc:`NotmuchError` with STATUS.NULL_POINTER on error
\r
231 + :execption: :exc:`NullPointerError` on error
\r
233 self._assert_db_is_initialized()
\r
235 tags_p = Database._get_all_tags(self._db)
\r
237 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
238 + raise NullPointerError()
\r
239 return Tags(tags_p, self)
\r
241 def create_query(self, querystring):
\r
242 @@ -409,6 +417,9 @@ class Database(object):
\r
243 q = Query(db,'from:"Biene Maja"')
\r
245 This function is a python extension and not in the underlying C API.
\r
247 + :exception: :exc:`NotInitializedError` if
\r
248 + the database was not intitialized.
\r
250 self._assert_db_is_initialized()
\r
252 @@ -425,7 +436,8 @@ class Database(object):
\r
253 def _get_user_default_db(self):
\r
254 """ Reads a user's notmuch config and returns his db location
\r
256 - Throws a NotmuchError if it cannot find it"""
\r
257 + :exception: :exc:`NotMuchError` if it cannot find it
\r
259 from ConfigParser import SafeConfigParser
\r
260 config = SafeConfigParser()
\r
261 conf_f = os.getenv('NOTMUCH_CONFIG',
\r
262 @@ -507,20 +519,20 @@ class Query(object):
\r
263 :param querystr: The query string
\r
264 :type querystr: utf-8 encoded str or unicode
\r
266 - :exception: :exc:`NotmuchError`
\r
267 + :exception: :exc:`NotInitializedError` or :exc:`NullPointerError`
\r
269 - * STATUS.NOT_INITIALIZED if db is not inited
\r
270 - * STATUS.NULL_POINTER if the query creation failed
\r
271 + :exc:`NotInitializedError` if db is not initialized
\r
272 + :exc:`NullPointerError` if the query creation failed
\r
273 (too little memory)
\r
275 if db.db_p is None:
\r
276 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
277 + raise NotInitializedError()
\r
278 # create reference to parent db to keep it alive
\r
280 # create query, return None if too little mem available
\r
281 query_p = Query._create(db.db_p, _str(querystr))
\r
282 if query_p is None:
\r
283 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
284 + raise NullPointerError()
\r
285 self._query = query_p
\r
287 def set_sort(self, sort):
\r
288 @@ -530,11 +542,11 @@ class Query(object):
\r
290 :param sort: Sort order (see :attr:`Query.SORT`)
\r
292 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if query has not
\r
293 + :exception: :exc:`NotInitializedError` if query has not
\r
296 if self._query is None:
\r
297 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
298 + raise NotInitializedError()
\r
301 nmlib.notmuch_query_set_sort(self._query, sort)
\r
302 @@ -554,18 +566,18 @@ class Query(object):
\r
303 *notmuch_query_search_threads* function.
\r
305 :returns: :class:`Threads`
\r
306 - :exception: :exc:`NotmuchError`
\r
307 + :exception: :exc:`NotInitializedError` or :exc:`NullPointerError`
\r
309 - * STATUS.NOT_INITIALIZED if query is not inited
\r
310 - * STATUS.NULL_POINTER if search_threads failed
\r
311 + :exc:`NotInitializedError` if query is not initialized
\r
312 + :exc:`NullPointerError` if the search_threads failed
\r
314 if self._query is None:
\r
315 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
316 + raise NotInitializedError()
\r
318 threads_p = Query._search_threads(self._query)
\r
320 if threads_p is None:
\r
321 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
322 + raise NullPointerError()
\r
324 return Threads(threads_p, self)
\r
326 @@ -577,18 +589,18 @@ class Query(object):
\r
327 *notmuch_query_search_messages* function.
\r
329 :returns: :class:`Messages`
\r
330 - :exception: :exc:`NotmuchError`
\r
331 + :exception: :exc:`NotInitializedError` or :exc:`NullPointerError`
\r
333 - * STATUS.NOT_INITIALIZED if query is not inited
\r
334 - * STATUS.NULL_POINTER if search_messages failed
\r
335 + :exc:`NotInitializedError` if query is not initialized
\r
336 + :exc:`NullPointerError` if the search_messages failed
\r
338 if self._query is None:
\r
339 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
340 + raise NotInitializedError()
\r
342 msgs_p = Query._search_messages(self._query)
\r
345 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
346 + raise NullPointerError()
\r
348 return Messages(msgs_p, self)
\r
350 @@ -603,12 +615,12 @@ class Query(object):
\r
351 *notmuch_query_count_messages* function.
\r
353 :returns: :class:`Messages`
\r
354 - :exception: :exc:`NotmuchError`
\r
355 + :exception: :exc:`NotInitializedError`
\r
357 - * STATUS.NOT_INITIALIZED if query is not inited
\r
358 + :exc:`NotInitializedError` if query is not initialized
\r
360 if self._query is None:
\r
361 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
362 + raise NotInitializedError()
\r
364 return Query._count_messages(self._query)
\r
366 @@ -651,7 +663,7 @@ class Directory(object):
\r
367 def _assert_dir_is_initialized(self):
\r
368 """Raises a NotmuchError(status=STATUS.NOT_INITIALIZED) if dir_p is None"""
\r
369 if self._dir_p is None:
\r
370 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
371 + raise NotInitializedError()
\r
373 def __init__(self, path, dir_p, parent):
\r
375 @@ -693,14 +705,15 @@ class Directory(object):
\r
377 :param mtime: A (time_t) timestamp
\r
378 :returns: Nothing on success, raising an exception on failure.
\r
379 - :exception: :exc:`NotmuchError`:
\r
380 + :exception: :exc:`NotInitializedError`, :exc:`XapianError` or
\r
381 + :exc:`ReadOnlyDatabaseError`
\r
383 - STATUS.XAPIAN_EXCEPTION
\r
384 + :exc:`XapianError`
\r
385 A Xapian exception occurred, mtime not stored.
\r
386 - STATUS.READ_ONLY_DATABASE
\r
387 + :exc:`ReadOnlyDatabaseError`
\r
388 Database was opened in read-only mode so directory
\r
389 mtime cannot be modified.
\r
390 - STATUS.NOT_INITIALIZED
\r
391 + :exc:`NotInitializedError`
\r
392 The directory has not been initialized
\r
394 self._assert_dir_is_initialized()
\r
395 @@ -712,7 +725,7 @@ class Directory(object):
\r
396 if status == STATUS.SUCCESS:
\r
398 #fail with Exception otherwise
\r
399 - raise NotmuchError(status=status)
\r
400 + raise NotmuchError.decode(status)
\r
402 def get_mtime(self):
\r
403 """Gets the mtime value of this directory in the database
\r
404 @@ -721,9 +734,9 @@ class Directory(object):
\r
406 :param mtime: A (time_t) timestamp
\r
407 :returns: Nothing on success, raising an exception on failure.
\r
408 - :exception: :exc:`NotmuchError`:
\r
409 + :exception: :exc:`NotInitializedError`
\r
411 - STATUS.NOT_INITIALIZED
\r
412 + :exc:`NotInitializedError`
\r
413 The directory has not been initialized
\r
415 self._assert_dir_is_initialized()
\r
416 @@ -743,6 +756,11 @@ class Directory(object):
\r
418 The returned filenames will be the basename-entries only (not
\r
421 + :exception: :exc:`NotInitializedError`
\r
423 + :exc:`NotInitializedError`
\r
424 + The directory has not been initialized
\r
426 self._assert_dir_is_initialized()
\r
428 @@ -755,6 +773,11 @@ class Directory(object):
\r
430 The returned filenames will be the basename-entries only (not
\r
433 + :exception: :exc:`NotInitializedError`
\r
435 + :exc:`NotInitializedError`
\r
436 + The directory has not been initialized
\r
438 self._assert_dir_is_initialized()
\r
440 @@ -801,7 +824,7 @@ class Filenames(object):
\r
443 if self._files_p is None:
\r
444 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
445 + raise NotInitializedError()
\r
447 if not nmlib.notmuch_filenames_valid(self._files_p):
\r
448 self._files_p = None
\r
449 @@ -820,11 +843,16 @@ class Filenames(object):
\r
451 files = Database().get_directory('').get_child_files()
\r
452 if len(files) > 0: #this 'exhausts' msgs
\r
453 - # next line raises NotmuchError(status=STATUS.NOT_INITIALIZED)!!!
\r
454 + # next line raises NotInitializedError()!!!
\r
455 for file in files: print file
\r
457 + :exception: :exc:`NotInitializedError`
\r
459 + :exc:`NotInitializedError`
\r
460 + If self._files_p is None
\r
462 if self._files_p is None:
\r
463 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
464 + raise NotInitializedError()
\r
467 while nmlib.notmuch_filenames_valid(self._files_p):
\r
468 diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py
\r
469 index c5dfd94..ddfd494 100644
\r
470 --- a/bindings/python/notmuch/filename.py
\r
471 +++ b/bindings/python/notmuch/filename.py
\r
472 @@ -17,7 +17,8 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
473 Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
\r
475 from ctypes import c_char_p
\r
476 -from notmuch.globals import nmlib, STATUS, NotmuchError
\r
477 +from notmuch.globals import nmlib, STATUS, NotmuchError, \
\r
478 + NullPointerError, NotInitializedError
\r
481 class Filenames(object):
\r
482 @@ -68,7 +69,7 @@ class Filenames(object):
\r
483 once all derived objects are dead.
\r
485 if files_p is None:
\r
486 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
487 + raise NullPointerError()
\r
489 self._files = files_p
\r
490 #save reference to parent object so we keep it alive
\r
491 @@ -80,7 +81,7 @@ class Filenames(object):
\r
492 This is the main function that will usually be used by the
\r
494 if self._files is None:
\r
495 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
496 + raise NotInitializedError()
\r
498 if not nmlib.notmuch_filenames_valid(self._files):
\r
500 @@ -96,7 +97,7 @@ class Filenames(object):
\r
501 .. note:: As this iterates over the filenames, we will not be
\r
502 able to iterate over them again (as in retrieve them)! If
\r
503 the tags have been exhausted already, this will raise a
\r
504 - :exc:`NotmuchError` STATUS.NOT_INITIALIZED on subsequent
\r
505 + :exc:`NotInitializedError` on subsequent
\r
506 attempts. However, you can use
\r
507 :meth:`Message.get_filenames` repeatedly to perform
\r
508 various actions on filenames.
\r
509 diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
\r
510 index 5cc3175..ac708ec 100644
\r
511 --- a/bindings/python/notmuch/message.py
\r
512 +++ b/bindings/python/notmuch/message.py
\r
513 @@ -21,7 +21,8 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
\r
515 from ctypes import c_char_p, c_void_p, c_long, c_uint, c_int
\r
516 from datetime import date
\r
517 -from notmuch.globals import nmlib, STATUS, NotmuchError, Enum, _str
\r
518 +from notmuch.globals import nmlib, STATUS, Enum, _str, NotmuchError, \
\r
519 + NullPointerError, NotInitializedError
\r
520 from notmuch.tag import Tags
\r
521 from notmuch.filename import Filenames
\r
523 @@ -42,7 +43,7 @@ class Messages(object):
\r
524 only provides a one-time iterator (it cannot reset the iterator to
\r
525 the start). Thus iterating over the function will "exhaust" the list
\r
526 of messages, and a subsequent iteration attempt will raise a
\r
527 - :exc:`NotmuchError` STATUS.NOT_INITIALIZED. If you need to
\r
528 + :exc:`NotInitializedError`. If you need to
\r
529 re-iterate over a list of messages you will need to retrieve a new
\r
530 :class:`Messages` object or cache your :class:`Message`\s in a list
\r
532 @@ -115,7 +116,7 @@ class Messages(object):
\r
533 the Python object.(?)
\r
536 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
537 + raise NullPointerError()
\r
539 self._msgs = msgs_p
\r
540 #store parent, so we keep them alive as long as self is alive
\r
541 @@ -125,13 +126,13 @@ class Messages(object):
\r
542 """Return the unique :class:`Tags` in the contained messages
\r
544 :returns: :class:`Tags`
\r
545 - :exceptions: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if not inited
\r
546 + :exceptions: :exc:`NotInitializedError` if not inited
\r
548 .. note:: :meth:`collect_tags` will iterate over the messages and
\r
549 therefore will not allow further iterations.
\r
551 if self._msgs is None:
\r
552 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
553 + raise NotInitializedError()
\r
555 # collect all tags (returns NULL on error)
\r
556 tags_p = Messages._collect_tags(self._msgs)
\r
557 @@ -139,7 +140,7 @@ class Messages(object):
\r
561 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
562 + raise NullPointerError()
\r
563 return Tags(tags_p, self)
\r
565 def __iter__(self):
\r
566 @@ -148,7 +149,7 @@ class Messages(object):
\r
569 if self._msgs is None:
\r
570 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
571 + raise NotInitializedError()
\r
573 if not nmlib.notmuch_messages_valid(self._msgs):
\r
575 @@ -292,7 +293,7 @@ class Message(object):
\r
579 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
580 + raise NullPointerError()
\r
582 #keep reference to parent, so we keep it alive
\r
583 self._parent = parent
\r
584 @@ -301,11 +302,11 @@ class Message(object):
\r
585 """Returns the message ID
\r
587 :returns: String with a message ID
\r
588 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
\r
589 + :exception: :exc:`NotInitializedError` if the message
\r
590 is not initialized.
\r
592 if self._msg is None:
\r
593 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
594 + raise NotInitializedError()
\r
595 return Message._get_message_id(self._msg)
\r
597 def get_thread_id(self):
\r
598 @@ -318,11 +319,11 @@ class Message(object):
\r
599 message belongs to a single thread.
\r
601 :returns: String with a thread ID
\r
602 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
\r
603 + :exception: :exc:`NotInitializedError` if the message
\r
604 is not initialized.
\r
606 if self._msg is None:
\r
607 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
608 + raise NotInitializedError()
\r
610 return Message._get_thread_id(self._msg)
\r
612 @@ -341,11 +342,11 @@ class Message(object):
\r
614 :returns: :class:`Messages` or `None` if there are no replies to
\r
616 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
\r
617 + :exception: :exc:`NotInitializedError` if the message
\r
618 is not initialized.
\r
620 if self._msg is None:
\r
621 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
622 + raise NotInitializedError()
\r
624 msgs_p = Message._get_replies(self._msg)
\r
626 @@ -363,11 +364,11 @@ class Message(object):
\r
628 :returns: A time_t timestamp.
\r
630 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
\r
631 + :exception: :exc:`NotInitializedError` if the message
\r
632 is not initialized.
\r
634 if self._msg is None:
\r
635 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
636 + raise NotInitializedError()
\r
637 return Message._get_date(self._msg)
\r
639 def get_header(self, header):
\r
640 @@ -389,23 +390,23 @@ class Message(object):
\r
641 * STATUS.NULL_POINTER, if no header was found
\r
643 if self._msg is None:
\r
644 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
645 + raise NotInitializedError()
\r
647 #Returns NULL if any error occurs.
\r
648 header = Message._get_header(self._msg, header)
\r
650 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
651 + raise NullPointerError()
\r
652 return header.decode('UTF-8')
\r
654 def get_filename(self):
\r
655 """Returns the file path of the message file
\r
657 :returns: Absolute file path & name of the message file
\r
658 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
\r
659 + :exception: :exc:`NotInitializedError` if the message
\r
660 is not initialized.
\r
662 if self._msg is None:
\r
663 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
664 + raise NotInitializedError()
\r
665 return Message._get_filename(self._msg)
\r
667 def get_filenames(self):
\r
668 @@ -415,7 +416,7 @@ class Message(object):
\r
669 messages recorded to have the same Message-ID. These files must
\r
670 not necessarily have identical content."""
\r
671 if self._msg is None:
\r
672 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
673 + raise NotInitializedError()
\r
675 files_p = Message._get_filenames(self._msg)
\r
677 @@ -431,11 +432,11 @@ class Message(object):
\r
678 :param flag: One of the :attr:`Message.FLAG` values (currently only
\r
679 *Message.FLAG.MATCH*
\r
680 :returns: An unsigned int (0/1), indicating whether the flag is set.
\r
681 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
\r
682 + :exception: :exc:`NotInitializedError` if the message
\r
683 is not initialized.
\r
685 if self._msg is None:
\r
686 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
687 + raise NotInitializedError()
\r
688 return Message._get_flag(self._msg, flag)
\r
690 def set_flag(self, flag, value):
\r
691 @@ -446,11 +447,11 @@ class Message(object):
\r
692 :param value: A bool indicating whether to set or unset the flag.
\r
695 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
\r
696 + :exception: :exc:`NotInitializedError` if the message
\r
697 is not initialized.
\r
699 if self._msg is None:
\r
700 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
701 + raise NotInitializedError()
\r
702 nmlib.notmuch_message_set_flag(self._msg, flag, value)
\r
704 def get_tags(self):
\r
705 @@ -464,11 +465,11 @@ class Message(object):
\r
706 * STATUS.NULL_POINTER, on error
\r
708 if self._msg is None:
\r
709 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
710 + raise NotInitializedError()
\r
712 tags_p = Message._get_tags(self._msg)
\r
714 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
715 + raise NullPointerError()
\r
716 return Tags(tags_p, self)
\r
718 def add_tag(self, tag, sync_maildir_flags=False):
\r
719 @@ -503,13 +504,13 @@ class Message(object):
\r
720 The message has not been initialized.
\r
722 if self._msg is None:
\r
723 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
724 + raise NotInitializedError()
\r
726 status = nmlib.notmuch_message_add_tag(self._msg, _str(tag))
\r
728 # bail out on failure
\r
729 if status != STATUS.SUCCESS:
\r
730 - raise NotmuchError(status=status)
\r
731 + raise NotmuchError.decode(status)
\r
733 if sync_maildir_flags:
\r
734 self.tags_to_maildir_flags()
\r
735 @@ -547,12 +548,12 @@ class Message(object):
\r
736 The message has not been initialized.
\r
738 if self._msg is None:
\r
739 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
740 + raise NotInitializedError()
\r
742 status = nmlib.notmuch_message_remove_tag(self._msg, _str(tag))
\r
743 # bail out on error
\r
744 if status != STATUS.SUCCESS:
\r
745 - raise NotmuchError(status=status)
\r
746 + raise NotmuchError.decode(status)
\r
748 if sync_maildir_flags:
\r
749 self.tags_to_maildir_flags()
\r
750 @@ -584,13 +585,13 @@ class Message(object):
\r
751 The message has not been initialized.
\r
753 if self._msg is None:
\r
754 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
755 + raise NotInitializedError()
\r
757 status = nmlib.notmuch_message_remove_all_tags(self._msg)
\r
759 # bail out on error
\r
760 if status != STATUS.SUCCESS:
\r
761 - raise NotmuchError(status=status)
\r
762 + raise NotmuchError.decode(status)
\r
764 if sync_maildir_flags:
\r
765 self.tags_to_maildir_flags()
\r
766 @@ -638,7 +639,7 @@ class Message(object):
\r
767 The message has not been initialized.
\r
769 if self._msg is None:
\r
770 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
771 + raise NotInitializedError()
\r
773 status = nmlib.notmuch_message_freeze(self._msg)
\r
775 @@ -646,7 +647,7 @@ class Message(object):
\r
776 # return on success
\r
779 - raise NotmuchError(status=status)
\r
780 + raise NotmuchError.decode(status)
\r
783 """Thaws the current 'message'
\r
784 @@ -673,7 +674,7 @@ class Message(object):
\r
785 The message has not been initialized.
\r
787 if self._msg is None:
\r
788 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
789 + raise NotInitializedError()
\r
791 status = nmlib.notmuch_message_thaw(self._msg)
\r
793 @@ -681,7 +682,7 @@ class Message(object):
\r
794 # return on success
\r
797 - raise NotmuchError(status=status)
\r
798 + raise NotmuchError.decode(status)
\r
800 def is_match(self):
\r
801 """(Not implemented)"""
\r
802 @@ -709,7 +710,7 @@ class Message(object):
\r
803 :returns: a :class:`STATUS`. In short, you want to see
\r
804 notmuch.STATUS.SUCCESS here. See there for details."""
\r
805 if self._msg is None:
\r
806 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
807 + raise NotInitializedError()
\r
808 status = Message._tags_to_maildir_flags(self._msg)
\r
810 def maildir_flags_to_tags(self):
\r
811 @@ -736,7 +737,7 @@ class Message(object):
\r
812 :returns: a :class:`STATUS`. In short, you want to see
\r
813 notmuch.STATUS.SUCCESS here. See there for details."""
\r
814 if self._msg is None:
\r
815 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
816 + raise NotInitializedError()
\r
817 status = Message._tags_to_maildir_flags(self._msg)
\r
819 def __repr__(self):
\r
820 diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
\r
821 index 9ca871a..b903864 100644
\r
822 --- a/bindings/python/notmuch/tag.py
\r
823 +++ b/bindings/python/notmuch/tag.py
\r
824 @@ -17,7 +17,9 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
825 Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
\r
827 from ctypes import c_char_p
\r
828 -from notmuch.globals import nmlib, STATUS, NotmuchError
\r
829 +from notmuch.globals import nmlib, STATUS, NotmuchError, \
\r
830 + NullPointerError, NotInitializedError
\r
834 class Tags(object):
\r
835 @@ -70,7 +72,7 @@ class Tags(object):
\r
836 cache the tags in the Python object(?)
\r
839 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
840 + raise NullPointerError()
\r
842 self._tags = tags_p
\r
843 #save reference to parent object so we keep it alive
\r
844 @@ -82,7 +84,7 @@ class Tags(object):
\r
847 if self._tags is None:
\r
848 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
849 + raise NotInitializedError()
\r
850 if not nmlib.notmuch_tags_valid(self._tags):
\r
852 raise StopIteration
\r
853 @@ -107,7 +109,7 @@ class Tags(object):
\r
854 .. note:: As this iterates over the tags, we will not be able
\r
855 to iterate over them again (as in retrieve them)! If
\r
856 the tags have been exhausted already, this will raise a
\r
857 - :exc:`NotmuchError` STATUS.NOT_INITIALIZED on
\r
858 + :exc:`NotInitializedError` on
\r
859 subsequent attempts.
\r
861 return " ".join(self)
\r
862 diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
\r
863 index 93089d0..e9d1185 100644
\r
864 --- a/bindings/python/notmuch/thread.py
\r
865 +++ b/bindings/python/notmuch/thread.py
\r
866 @@ -18,7 +18,8 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
\r
869 from ctypes import c_char_p, c_void_p, c_long
\r
870 -from notmuch.globals import nmlib, STATUS, NotmuchError
\r
871 +from notmuch.globals import nmlib, STATUS, NotmuchError, \
\r
872 + NullPointerError, NotInitializedError
\r
873 from notmuch.message import Messages
\r
874 from notmuch.tag import Tags
\r
875 from datetime import date
\r
876 @@ -33,7 +34,7 @@ class Threads(object):
\r
877 library only provides a one-time iterator (it cannot reset the
\r
878 iterator to the start). Thus iterating over the function will
\r
879 "exhaust" the list of threads, and a subsequent iteration attempt
\r
880 - will raise a :exc:`NotmuchError` STATUS.NOT_INITIALIZED. Also
\r
881 + will raise a :exc:`NotInitializedError`. Also
\r
882 note, that any function that uses iteration will also
\r
883 exhaust the messages. So both::
\r
885 @@ -95,7 +96,7 @@ class Threads(object):
\r
886 the Python object.(?)
\r
888 if threads_p is None:
\r
889 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
890 + raise NullPointerError()
\r
892 self._threads = threads_p
\r
893 #store parent, so we keep them alive as long as self is alive
\r
894 @@ -107,7 +108,7 @@ class Threads(object):
\r
897 if self._threads is None:
\r
898 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
899 + raise NotInitializedError()
\r
901 if not nmlib.notmuch_threads_valid(self._threads):
\r
902 self._threads = None
\r
903 @@ -126,11 +127,11 @@ class Threads(object):
\r
905 threads = Database().create_query('').search_threads()
\r
906 if len(threads) > 0: #this 'exhausts' threads
\r
907 - # next line raises NotmuchError(status=STATUS.NOT_INITIALIZED)!!!
\r
908 + # next line raises NotInitializedError()!!!
\r
909 for thread in threads: print thread
\r
911 if self._threads is None:
\r
912 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
913 + raise NotInitializedError()
\r
916 # returns 'bool'. On out-of-memory it returns None
\r
917 @@ -206,7 +207,7 @@ class Thread(object):
\r
920 if thread_p is None:
\r
921 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
922 + raise NullPointerError()
\r
923 self._thread = thread_p
\r
924 #keep reference to parent, so we keep it alive
\r
925 self._parent = parent
\r
926 @@ -218,11 +219,11 @@ class Thread(object):
\r
927 for as long as the thread is valid.
\r
929 :returns: String with a message ID
\r
930 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
\r
931 + :exception: :exc:`NotInitializedError` if the thread
\r
932 is not initialized.
\r
934 if self._thread is None:
\r
935 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
936 + raise NotInitializedError()
\r
937 return Thread._get_thread_id(self._thread)
\r
939 def get_total_messages(self):
\r
940 @@ -231,11 +232,11 @@ class Thread(object):
\r
941 :returns: The number of all messages in the database
\r
942 belonging to this thread. Contrast with
\r
943 :meth:`get_matched_messages`.
\r
944 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
\r
945 + :exception: :exc:`NotInitializedError` if the thread
\r
946 is not initialized.
\r
948 if self._thread is None:
\r
949 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
950 + raise NotInitializedError()
\r
951 return nmlib.notmuch_thread_get_total_messages(self._thread)
\r
953 def get_toplevel_messages(self):
\r
954 @@ -258,12 +259,12 @@ class Thread(object):
\r
955 * STATUS.NULL_POINTER if search_messages failed
\r
957 if self._thread is None:
\r
958 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
959 + raise NotInitializedError()
\r
961 msgs_p = Thread._get_toplevel_messages(self._thread)
\r
964 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
965 + raise NullPointerError()
\r
967 return Messages(msgs_p, self)
\r
969 @@ -273,11 +274,11 @@ class Thread(object):
\r
970 :returns: The number of all messages belonging to this thread that
\r
971 matched the :class:`Query`from which this thread was created.
\r
972 Contrast with :meth:`get_total_messages`.
\r
973 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
\r
974 + :exception: :exc:`NotInitializedError` if the thread
\r
975 is not initialized.
\r
977 if self._thread is None:
\r
978 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
979 + raise NotInitializedError()
\r
980 return nmlib.notmuch_thread_get_matched_messages(self._thread)
\r
982 def get_authors(self):
\r
983 @@ -291,7 +292,7 @@ class Thread(object):
\r
984 as long as this Thread() is not deleted.
\r
986 if self._thread is None:
\r
987 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
988 + raise NotInitializedError()
\r
989 authors = Thread._get_authors(self._thread)
\r
990 if authors is None:
\r
992 @@ -304,7 +305,7 @@ class Thread(object):
\r
993 as long as this Thread() is not deleted.
\r
995 if self._thread is None:
\r
996 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
997 + raise NotInitializedError()
\r
998 subject = Thread._get_subject(self._thread)
\r
999 if subject is None:
\r
1001 @@ -315,11 +316,11 @@ class Thread(object):
\r
1003 :returns: A time_t timestamp.
\r
1005 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
\r
1006 + :exception: :exc:`NotInitializedError` if the message
\r
1007 is not initialized.
\r
1009 if self._thread is None:
\r
1010 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
1011 + raise NotInitializedError()
\r
1012 return Thread._get_newest_date(self._thread)
\r
1014 def get_oldest_date(self):
\r
1015 @@ -327,11 +328,11 @@ class Thread(object):
\r
1017 :returns: A time_t timestamp.
\r
1019 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
\r
1020 + :exception: :exc:`NotInitializedError` if the message
\r
1021 is not initialized.
\r
1023 if self._thread is None:
\r
1024 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
1025 + raise NotInitializedError()
\r
1026 return Thread._get_oldest_date(self._thread)
\r
1028 def get_tags(self):
\r
1029 @@ -354,11 +355,11 @@ class Thread(object):
\r
1030 * STATUS.NULL_POINTER, on error
\r
1032 if self._thread is None:
\r
1033 - raise NotmuchError(status=STATUS.NOT_INITIALIZED)
\r
1034 + raise NotInitializedError()
\r
1036 tags_p = Thread._get_tags(self._thread)
\r
1037 if tags_p == None:
\r
1038 - raise NotmuchError(status=STATUS.NULL_POINTER)
\r
1039 + raise NullPointerError()
\r
1040 return Tags(tags_p, self)
\r
1042 def __str__(self):
\r