From 8015cbff263606f009b5750d23b28ee332c25db8 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Sun, 22 Jan 2012 06:14:57 +0100
Subject: python: fix error handling
Before 3434d1940 the return values of libnotmuch functions were
declared as c_void_p and the code checking for errors compared the
returned value to None, which is the ctypes equivalent of a NULL
pointer.
But said commit wrapped all the data types in python classes and the
semantic changed in a subtle way. If a function returns NULL, the
wrapped python value is falsish, but no longer equal to None.
---
bindings/python/notmuch/thread.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index e81ff1b..104710c 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -97,7 +97,7 @@ class Threads(Python3StringMixIn):
:TODO: Make the iterator work more than once and cache the tags in
the Python object.(?)
"""
- if threads_p is None:
+ if not threads_p:
raise NotmuchError(STATUS.NULL_POINTER)
self._threads = threads_p
@@ -228,7 +228,7 @@ class Thread(object):
automatically delete the parent object once all derived
objects are dead.
"""
- if thread_p is None:
+ if not thread_p:
raise NotmuchError(STATUS.NULL_POINTER)
self._thread = thread_p
#keep reference to parent, so we keep it alive
@@ -289,7 +289,7 @@ class Thread(object):
msgs_p = Thread._get_toplevel_messages(self._thread)
- if msgs_p is None:
+ if not msgs_p:
raise NotmuchError(STATUS.NULL_POINTER)
return Messages(msgs_p, self)
--
cgit v1.2.3
From be851ad39de11f38e1cd4f7f15f1fa952232efe2 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Sun, 19 Feb 2012 00:36:15 +0100
Subject: python: more error handling fixes
This is a follow up commit to 221c7e0b38177f5f1dbf0561580c15e8aaa49004
fixing more NULL pointer checks.
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/database.py | 2 +-
bindings/python/notmuch/filename.py | 2 +-
bindings/python/notmuch/message.py | 40 ++++++++++++++++++-------------------
bindings/python/notmuch/query.py | 2 +-
bindings/python/notmuch/tag.py | 2 +-
bindings/python/notmuch/thread.py | 26 ++++++++++++------------
6 files changed, 37 insertions(+), 37 deletions(-)
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 0958ce0..6edb18b 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -159,7 +159,7 @@ class Database(object):
def _assert_db_is_initialized(self):
"""Raises :exc:`NotInitializedError` if self._db is `None`"""
- if self._db is None:
+ if not self._db:
raise NotInitializedError()
def create(self, path):
diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py
index 469b6a5..322e6bf 100644
--- a/bindings/python/notmuch/filename.py
+++ b/bindings/python/notmuch/filename.py
@@ -89,7 +89,7 @@ class Filenames(Python3StringMixIn):
This is the main function that will usually be used by the
user."""
- if self._files is None:
+ if not self._files:
raise NotmuchError(STATUS.NOT_INITIALIZED)
while self._valid(self._files):
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index 883ed23..28723c1 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -135,7 +135,7 @@ class Messages(object):
:meth:`collect_tags` will iterate over the messages and therefore
will not allow further iterations.
"""
- if self._msgs is None:
+ if not self._msgs:
raise NotmuchError(STATUS.NOT_INITIALIZED)
# collect all tags (returns NULL on error)
@@ -160,7 +160,7 @@ class Messages(object):
_move_to_next.restype = None
def __next__(self):
- if self._msgs is None:
+ if not self._msgs:
raise NotmuchError(STATUS.NOT_INITIALIZED)
if not self._valid(self._msgs):
@@ -362,7 +362,7 @@ class Message(Python3StringMixIn):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Message._get_message_id(self._msg).decode('utf-8', 'ignore')
@@ -379,7 +379,7 @@ class Message(Python3StringMixIn):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Message._get_thread_id(self._msg).decode('utf-8', 'ignore')
@@ -402,7 +402,7 @@ class Message(Python3StringMixIn):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
msgs_p = Message._get_replies(self._msg)
@@ -424,7 +424,7 @@ class Message(Python3StringMixIn):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Message._get_date(self._msg)
@@ -447,7 +447,7 @@ class Message(Python3StringMixIn):
is not initialized.
* STATUS.NULL_POINTER if any error occured.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
#Returns NULL if any error occurs.
@@ -463,7 +463,7 @@ class Message(Python3StringMixIn):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Message._get_filename(self._msg).decode('utf-8', 'ignore')
@@ -473,7 +473,7 @@ class Message(Python3StringMixIn):
Returns a Filenames() generator with all absolute filepaths for
messages recorded to have the same Message-ID. These files must
not necessarily have identical content."""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
files_p = Message._get_filenames(self._msg)
@@ -493,7 +493,7 @@ class Message(Python3StringMixIn):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Message._get_flag(self._msg, flag)
@@ -508,7 +508,7 @@ class Message(Python3StringMixIn):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
self._set_flag(self._msg, flag, value)
@@ -522,7 +522,7 @@ class Message(Python3StringMixIn):
is not initialized.
* STATUS.NULL_POINTER, on error
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
tags_p = Message._get_tags(self._msg)
@@ -565,7 +565,7 @@ class Message(Python3StringMixIn):
STATUS.NOT_INITIALIZED
The message has not been initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
status = self._add_tag(self._msg, _str(tag))
@@ -613,7 +613,7 @@ class Message(Python3StringMixIn):
STATUS.NOT_INITIALIZED
The message has not been initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
status = self._remove_tag(self._msg, _str(tag))
@@ -654,7 +654,7 @@ class Message(Python3StringMixIn):
STATUS.NOT_INITIALIZED
The message has not been initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
status = self._remove_all_tags(self._msg)
@@ -712,7 +712,7 @@ class Message(Python3StringMixIn):
STATUS.NOT_INITIALIZED
The message has not been initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
status = self._freeze(self._msg)
@@ -751,7 +751,7 @@ class Message(Python3StringMixIn):
STATUS.NOT_INITIALIZED
The message has not been initialized.
"""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
status = self._thaw(self._msg)
@@ -787,7 +787,7 @@ class Message(Python3StringMixIn):
:returns: a :class:`STATUS` value. In short, you want to see
notmuch.STATUS.SUCCESS here. See there for details."""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Message._tags_to_maildir_flags(self._msg)
@@ -814,7 +814,7 @@ class Message(Python3StringMixIn):
:returns: a :class:`STATUS`. In short, you want to see
notmuch.STATUS.SUCCESS here. See there for details."""
- if self._msg is None:
+ if not self._msg:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Message._tags_to_maildir_flags(self._msg)
@@ -957,7 +957,7 @@ class Message(Python3StringMixIn):
def __hash__(self):
"""Implement hash(), so we can use Message() sets"""
file = self.get_filename()
- if file is None:
+ if not file:
return None
return hash(file)
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index 0c08aa9..6132ca0 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -70,7 +70,7 @@ class Query(object):
def _assert_query_is_initialized(self):
"""Raises :exc:`NotInitializedError` if self._query is `None`"""
- if self._query is None:
+ if not self._query:
raise NotInitializedError()
"""notmuch_query_create"""
diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
index d2dc498..d0f7bb4 100644
--- a/bindings/python/notmuch/tag.py
+++ b/bindings/python/notmuch/tag.py
@@ -90,7 +90,7 @@ class Tags(Python3StringMixIn):
_move_to_next.restype = None
def __next__(self):
- if self._tags is None:
+ if not self._tags:
raise NotmuchError(STATUS.NOT_INITIALIZED)
if not self._valid(self._tags):
self._tags = None
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index 104710c..c2347fe 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -117,7 +117,7 @@ class Threads(Python3StringMixIn):
_move_to_next.restype = None
def __next__(self):
- if self._threads is None:
+ if not self._threads:
raise NotmuchError(STATUS.NOT_INITIALIZED)
if not self._valid(self._threads):
@@ -141,7 +141,7 @@ class Threads(Python3StringMixIn):
# next line raises NotmuchError(STATUS.NOT_INITIALIZED)!!!
for thread in threads: print thread
"""
- if self._threads is None:
+ if not self._threads:
raise NotmuchError(STATUS.NOT_INITIALIZED)
i = 0
@@ -244,7 +244,7 @@ class Thread(object):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
is not initialized.
"""
- if self._thread is None:
+ if not self._thread:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Thread._get_thread_id(self._thread).decode('utf-8', 'ignore')
@@ -261,7 +261,7 @@ class Thread(object):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
is not initialized.
"""
- if self._thread is None:
+ if not self._thread:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return self._get_total_messages(self._thread)
@@ -284,7 +284,7 @@ class Thread(object):
* STATUS.NOT_INITIALIZED if query is not inited
* STATUS.NULL_POINTER if search_messages failed
"""
- if self._thread is None:
+ if not self._thread:
raise NotmuchError(STATUS.NOT_INITIALIZED)
msgs_p = Thread._get_toplevel_messages(self._thread)
@@ -307,7 +307,7 @@ class Thread(object):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
is not initialized.
"""
- if self._thread is None:
+ if not self._thread:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return self._get_matched_messages(self._thread)
@@ -321,10 +321,10 @@ class Thread(object):
The returned string belongs to 'thread' and will only be valid for
as long as this Thread() is not deleted.
"""
- if self._thread is None:
+ if not self._thread:
raise NotmuchError(STATUS.NOT_INITIALIZED)
authors = Thread._get_authors(self._thread)
- if authors is None:
+ if not authors:
return None
return authors.decode('UTF-8', 'ignore')
@@ -334,10 +334,10 @@ class Thread(object):
The returned string belongs to 'thread' and will only be valid for
as long as this Thread() is not deleted.
"""
- if self._thread is None:
+ if not self._thread:
raise NotmuchError(STATUS.NOT_INITIALIZED)
subject = Thread._get_subject(self._thread)
- if subject is None:
+ if not subject:
return None
return subject.decode('UTF-8', 'ignore')
@@ -349,7 +349,7 @@ class Thread(object):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
- if self._thread is None:
+ if not self._thread:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Thread._get_newest_date(self._thread)
@@ -361,7 +361,7 @@ class Thread(object):
:exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
- if self._thread is None:
+ if not self._thread:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return Thread._get_oldest_date(self._thread)
@@ -384,7 +384,7 @@ class Thread(object):
is not initialized.
* STATUS.NULL_POINTER, on error
"""
- if self._thread is None:
+ if not self._thread:
raise NotmuchError(STATUS.NOT_INITIALIZED)
tags_p = Thread._get_tags(self._thread)
--
cgit v1.2.3
From a1442952d4d7fad8b7612502802ee346ac8fd349 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Mon, 20 Feb 2012 23:49:07 +0100
Subject: python: refactor the error handling machinery
Raise specific error classes instead of a generic NotmuchError with an
magic status value (e.g. NotmuchError(STATUS.NULL_POINTER) ->
NullPointerError()), update the documentation accordingly.
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/database.py | 15 +--
bindings/python/notmuch/filename.py | 26 ++++--
bindings/python/notmuch/message.py | 181 +++++++++++++++++-------------------
bindings/python/notmuch/tag.py | 26 ++++--
bindings/python/notmuch/thread.py | 78 ++++++++--------
5 files changed, 165 insertions(+), 161 deletions(-)
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 6edb18b..3de0f2b 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -23,7 +23,9 @@ from ctypes import c_char_p, c_void_p, c_uint, c_long, byref, POINTER
from notmuch.globals import (
nmlib,
STATUS,
+ FileError,
NotmuchError,
+ NullPointerError,
NotInitializedError,
Enum,
_str,
@@ -355,9 +357,8 @@ class Database(object):
# we got an absolute path
if not path.startswith(self.get_path()):
# but its initial components are not equal to the db path
- raise NotmuchError(STATUS.FILE_ERROR,
- message="Database().get_directory() called "
- "with a wrong absolute path.")
+ raise FileError('Database().get_directory() called '
+ 'with a wrong absolute path')
abs_dirpath = path
else:
#we got a relative path, make it absolute
@@ -542,7 +543,7 @@ class Database(object):
self._assert_db_is_initialized()
tags_p = Database._get_all_tags(self._db)
if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
return Tags(tags_p, self)
def create_query(self, querystring):
@@ -636,7 +637,7 @@ class Directory(object):
"""Raises a NotmuchError(:attr:`STATUS`.NOT_INITIALIZED)
if dir_p is None"""
if not self._dir_p:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
def __init__(self, path, dir_p, parent):
"""
@@ -797,7 +798,7 @@ class Filenames(object):
def __next__(self):
if not self._files_p:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
if not self._valid(self._files_p):
self._files_p = None
@@ -824,7 +825,7 @@ class Filenames(object):
for file in files: print file
"""
if not self._files_p:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
i = 0
while self._valid(self._files_p):
diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py
index 322e6bf..353eb76 100644
--- a/bindings/python/notmuch/filename.py
+++ b/bindings/python/notmuch/filename.py
@@ -17,8 +17,14 @@ along with notmuch. If not, see .
Copyright 2010 Sebastian Spaeth '
"""
from ctypes import c_char_p
-from notmuch.globals import (nmlib, STATUS, NotmuchError,
- NotmuchFilenamesP, NotmuchMessageP, Python3StringMixIn)
+from notmuch.globals import (
+ nmlib,
+ NullPointerError,
+ NotInitializedError,
+ NotmuchMessageP,
+ NotmuchFilenamesP,
+ Python3StringMixIn,
+)
class Filenames(Python3StringMixIn):
@@ -29,9 +35,9 @@ class Filenames(Python3StringMixIn):
iterator over a list of notmuch filenames. Do note that the underlying
library only provides a one-time iterator (it cannot reset the iterator to
the start). Thus iterating over the function will "exhaust" the list of
- tags, and a subsequent iteration attempt will raise a :exc:`NotmuchError`
- STATUS.NOT_INITIALIZED. Also note, that any function that uses iteration
- (nearly all) will also exhaust the tags. So both::
+ tags, and a subsequent iteration attempt will raise a
+ :exc:`NotInitializedError`. Also note, that any function that uses
+ iteration (nearly all) will also exhaust the tags. So both::
for name in filenames: print name
@@ -61,8 +67,8 @@ class Filenames(Python3StringMixIn):
will almost never instantiate a :class:`Tags` object
herself. They are usually handed back as a result,
e.g. in :meth:`Database.get_all_tags`. *tags_p* must be
- valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
+ valid, we will raise an :exc:`NullPointerError`
+ if it is `None`.
:type files_p: :class:`ctypes.c_void_p`
:param parent: The parent object (ie :class:`Message` these
filenames are derived from, and saves a
@@ -70,7 +76,7 @@ class Filenames(Python3StringMixIn):
once all derived objects are dead.
"""
if not files_p:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
self._files = files_p
#save reference to parent object so we keep it alive
@@ -90,7 +96,7 @@ class Filenames(Python3StringMixIn):
This is the main function that will usually be used by the
user."""
if not self._files:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
while self._valid(self._files):
yield Filenames._get(self._files).decode('utf-8', 'ignore')
@@ -104,7 +110,7 @@ class Filenames(Python3StringMixIn):
.. note:: As this iterates over the filenames, we will not be
able to iterate over them again (as in retrieve them)! If
the tags have been exhausted already, this will raise a
- :exc:`NotmuchError` STATUS.NOT_INITIALIZED on subsequent
+ :exc:`NotInitializedError` on subsequent
attempts. However, you can use
:meth:`Message.get_filenames` repeatedly to perform
various actions on filenames.
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index 28723c1..b291f9f 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -22,8 +22,19 @@ Copyright 2010 Sebastian Spaeth '
from ctypes import c_char_p, c_long, c_uint, c_int
from datetime import date
from notmuch.globals import (
- nmlib, STATUS, NotmuchError, Enum, _str, Python3StringMixIn,
- NotmuchTagsP, NotmuchMessagesP, NotmuchMessageP, NotmuchFilenamesP)
+ nmlib,
+ Enum,
+ _str,
+ Python3StringMixIn,
+ STATUS,
+ NotmuchError,
+ NullPointerError,
+ NotInitializedError,
+ NotmuchTagsP,
+ NotmuchMessageP,
+ NotmuchMessagesP,
+ NotmuchFilenamesP,
+)
from notmuch.tag import Tags
from notmuch.filename import Filenames
import sys
@@ -43,7 +54,7 @@ class Messages(object):
only provides a one-time iterator (it cannot reset the iterator to
the start). Thus iterating over the function will "exhaust" the list
of messages, and a subsequent iteration attempt will raise a
- :exc:`NotmuchError` STATUS.NOT_INITIALIZED. If you need to
+ :exc:`NotInitializedError`. If you need to
re-iterate over a list of messages you will need to retrieve a new
:class:`Messages` object or cache your :class:`Message`\s in a list
via::
@@ -107,8 +118,8 @@ class Messages(object):
will almost never instantiate a :class:`Messages` object
herself. They are usually handed back as a result,
e.g. in :meth:`Query.search_messages`. *msgs_p* must be
- valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
+ valid, we will raise an :exc:`NullPointerError` if it is
+ `None`.
:type msgs_p: :class:`ctypes.c_void_p`
:param parent: The parent object
(ie :class:`Query`) these tags are derived from. It saves
@@ -118,7 +129,7 @@ class Messages(object):
the Python object.(?)
"""
if not msgs_p:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
self._msgs = msgs_p
#store parent, so we keep them alive as long as self is alive
@@ -128,7 +139,7 @@ class Messages(object):
"""Return the unique :class:`Tags` in the contained messages
:returns: :class:`Tags`
- :exceptions: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if not init'ed
+ :exceptions: :exc:`NotInitializedError` if not init'ed
.. note::
@@ -136,7 +147,7 @@ class Messages(object):
will not allow further iterations.
"""
if not self._msgs:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
# collect all tags (returns NULL on error)
tags_p = Messages._collect_tags(self._msgs)
@@ -144,7 +155,7 @@ class Messages(object):
self._msgs = None
if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
return Tags(tags_p, self)
def __iter__(self):
@@ -161,7 +172,7 @@ class Messages(object):
def __next__(self):
if not self._msgs:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
if not self._valid(self._msgs):
self._msgs = None
@@ -341,8 +352,8 @@ class Message(Python3StringMixIn):
def __init__(self, msg_p, parent=None):
"""
:param msg_p: A pointer to an internal notmuch_message_t
- Structure. If it is `None`, we will raise an :exc:`NotmuchError`
- STATUS.NULL_POINTER.
+ Structure. If it is `None`, we will raise an
+ :exc:`NullPointerError`.
:param parent: A 'parent' object is passed which this message is
derived from. We save a reference to it, so we can
@@ -350,7 +361,7 @@ class Message(Python3StringMixIn):
objects are dead.
"""
if not msg_p:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
self._msg = msg_p
#keep reference to parent, so we keep it alive
self._parent = parent
@@ -359,11 +370,11 @@ class Message(Python3StringMixIn):
"""Returns the message ID
:returns: String with a message ID
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Message._get_message_id(self._msg).decode('utf-8', 'ignore')
def get_thread_id(self):
@@ -376,11 +387,11 @@ class Message(Python3StringMixIn):
message belongs to a single thread.
:returns: String with a thread ID
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Message._get_thread_id(self._msg).decode('utf-8', 'ignore')
@@ -399,11 +410,11 @@ class Message(Python3StringMixIn):
an empty Messages iterator.
:returns: :class:`Messages`.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
msgs_p = Message._get_replies(self._msg)
@@ -421,11 +432,11 @@ class Message(Python3StringMixIn):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Message._get_date(self._msg)
def get_header(self, header):
@@ -441,30 +452,28 @@ class Message(Python3StringMixIn):
It is not case-sensitive.
:type header: str
:returns: The header value as string
- :exception: :exc:`NotmuchError`
-
- * STATUS.NOT_INITIALIZED if the message
- is not initialized.
- * STATUS.NULL_POINTER if any error occured.
+ :raises: :exc:`NotInitializedError` if the message is not
+ initialized
+ :raises: :exc:`NullPointerError` if any error occured
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
#Returns NULL if any error occurs.
header = Message._get_header(self._msg, _str(header))
if header == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
return header.decode('UTF-8', 'ignore')
def get_filename(self):
"""Returns the file path of the message file
:returns: Absolute file path & name of the message file
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Message._get_filename(self._msg).decode('utf-8', 'ignore')
def get_filenames(self):
@@ -474,7 +483,7 @@ class Message(Python3StringMixIn):
messages recorded to have the same Message-ID. These files must
not necessarily have identical content."""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
files_p = Message._get_filenames(self._msg)
@@ -490,11 +499,11 @@ class Message(Python3StringMixIn):
:param flag: One of the :attr:`Message.FLAG` values (currently only
*Message.FLAG.MATCH*
:returns: An unsigned int (0/1), indicating whether the flag is set.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Message._get_flag(self._msg, flag)
def set_flag(self, flag, value):
@@ -505,29 +514,27 @@ class Message(Python3StringMixIn):
:param value: A bool indicating whether to set or unset the flag.
:returns: Nothing
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
self._set_flag(self._msg, flag, value)
def get_tags(self):
"""Returns the message tags
:returns: A :class:`Tags` iterator.
- :exception: :exc:`NotmuchError`
-
- * STATUS.NOT_INITIALIZED if the message
- is not initialized.
- * STATUS.NULL_POINTER, on error
+ :raises: :exc:`NotInitializedError` if the message is not
+ initialized
+ :raises: :exc:`NullPointerError` if any error occured
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
tags_p = Message._get_tags(self._msg)
if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
return Tags(tags_p, self)
_add_tag = nmlib.notmuch_message_add_tag
@@ -552,21 +559,16 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the tag was successfully added.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.NULL_POINTER
- The 'tag' argument is NULL
- STATUS.TAG_TOO_LONG
- The length of 'tag' is too long
- (exceeds Message.NOTMUCH_TAG_MAX)
- STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot be
- modified.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
- """
+ :raises: :exc:`NullPointerError` if the `tag` argument is NULL
+ :raises: :exc:`TagTooLongError` if the length of `tag` exceeds
+ Message.NOTMUCH_TAG_MAX)
+ :raises: :exc:`ReadOnlyDatabaseError` if the database was opened
+ in read-only mode so message cannot be modified
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
+ """
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
status = self._add_tag(self._msg, _str(tag))
@@ -600,21 +602,16 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the tag was successfully removed or if
the message had no such tag.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.NULL_POINTER
- The 'tag' argument is NULL
- STATUS.TAG_TOO_LONG
- The length of 'tag' is too long
- (exceeds NOTMUCH_TAG_MAX)
- STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot
- be modified.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
+ :raises: :exc:`NullPointerError` if the `tag` argument is NULL
+ :raises: :exc:`TagTooLongError` if the length of `tag` exceeds
+ Message.NOTMUCH_TAG_MAX)
+ :raises: :exc:`ReadOnlyDatabaseError` if the database was opened
+ in read-only mode so message cannot be modified
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
status = self._remove_tag(self._msg, _str(tag))
# bail out on error
@@ -646,16 +643,13 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the tags were successfully removed.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot
- be modified.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
+ :raises: :exc:`ReadOnlyDatabaseError` if the database was opened
+ in read-only mode so message cannot be modified
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
status = self._remove_all_tags(self._msg)
@@ -704,16 +698,13 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the message was successfully frozen.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot
- be modified.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
+ :raises: :exc:`ReadOnlyDatabaseError` if the database was opened
+ in read-only mode so message cannot be modified
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
status = self._freeze(self._msg)
@@ -742,17 +733,15 @@ class Message(Python3StringMixIn):
:returns: STATUS.SUCCESS if the message was successfully frozen.
Raises an exception otherwise.
- :exception: :exc:`NotmuchError`. They have the following meaning:
-
- STATUS.UNBALANCED_FREEZE_THAW
- An attempt was made to thaw an unfrozen message.
- That is, there have been an unbalanced number of calls
- to :meth:`freeze` and :meth:`thaw`.
- STATUS.NOT_INITIALIZED
- The message has not been initialized.
+ :raises: :exc:`UnbalancedFreezeThawError` if an attempt was made
+ to thaw an unfrozen message. That is, there have been
+ an unbalanced number of calls to :meth:`freeze` and
+ :meth:`thaw`.
+ :raises: :exc:`NotInitializedError` if message has not been
+ initialized
"""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
status = self._thaw(self._msg)
@@ -788,7 +777,7 @@ class Message(Python3StringMixIn):
:returns: a :class:`STATUS` value. In short, you want to see
notmuch.STATUS.SUCCESS here. See there for details."""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Message._tags_to_maildir_flags(self._msg)
def maildir_flags_to_tags(self):
@@ -815,7 +804,7 @@ class Message(Python3StringMixIn):
:returns: a :class:`STATUS`. In short, you want to see
notmuch.STATUS.SUCCESS here. See there for details."""
if not self._msg:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Message._tags_to_maildir_flags(self._msg)
def __repr__(self):
diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
index d0f7bb4..526e51c 100644
--- a/bindings/python/notmuch/tag.py
+++ b/bindings/python/notmuch/tag.py
@@ -17,7 +17,13 @@ along with notmuch. If not, see .
Copyright 2010 Sebastian Spaeth '
"""
from ctypes import c_char_p
-from notmuch.globals import nmlib, STATUS, NotmuchError, NotmuchTagsP, Python3StringMixIn
+from notmuch.globals import (
+ nmlib,
+ Python3StringMixIn,
+ NullPointerError,
+ NotInitializedError,
+ NotmuchTagsP,
+)
class Tags(Python3StringMixIn):
@@ -29,9 +35,9 @@ class Tags(Python3StringMixIn):
Do note that the underlying library only provides a one-time
iterator (it cannot reset the iterator to the start). Thus iterating
over the function will "exhaust" the list of tags, and a subsequent
- iteration attempt will raise a :exc:`NotmuchError`
- STATUS.NOT_INITIALIZED. Also note, that any function that uses
- iteration (nearly all) will also exhaust the tags. So both::
+ iteration attempt will raise a :exc:`NotInitializedError`.
+ Also note, that any function that uses iteration (nearly all) will
+ also exhaust the tags. So both::
for tag in tags: print tag
@@ -60,8 +66,8 @@ class Tags(Python3StringMixIn):
will almost never instantiate a :class:`Tags` object
herself. They are usually handed back as a result,
e.g. in :meth:`Database.get_all_tags`. *tags_p* must be
- valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
+ valid, we will raise an :exc:`NullPointerError` if it is
+ `None`.
:type tags_p: :class:`ctypes.c_void_p`
:param parent: The parent object (ie :class:`Database` or
:class:`Message` these tags are derived from, and saves a
@@ -71,7 +77,7 @@ class Tags(Python3StringMixIn):
cache the tags in the Python object(?)
"""
if not tags_p:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
self._tags = tags_p
#save reference to parent object so we keep it alive
@@ -91,7 +97,7 @@ class Tags(Python3StringMixIn):
def __next__(self):
if not self._tags:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
if not self._valid(self._tags):
self._tags = None
raise StopIteration
@@ -118,8 +124,8 @@ class Tags(Python3StringMixIn):
As this iterates over the tags, we will not be able to iterate over
them again (as in retrieve them)! If the tags have been exhausted
- already, this will raise a :exc:`NotmuchError`
- STATUS.NOT_INITIALIZED on subsequent attempts.
+ already, this will raise a :exc:`NotInitializedError`on subsequent
+ attempts.
"""
return " ".join(self)
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index c2347fe..5c58028 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -18,9 +18,16 @@ Copyright 2010 Sebastian Spaeth '
"""
from ctypes import c_char_p, c_long, c_int
-from notmuch.globals import (nmlib, STATUS,
- NotmuchError, NotmuchThreadP, NotmuchThreadsP, NotmuchMessagesP,
- NotmuchTagsP, Python3StringMixIn)
+from notmuch.globals import (
+ nmlib,
+ Python3StringMixIn,
+ NullPointerError,
+ NotInitializedError,
+ NotmuchThreadP,
+ NotmuchThreadsP,
+ NotmuchMessagesP,
+ NotmuchTagsP,
+)
from notmuch.message import Messages
from notmuch.tag import Tags
from datetime import date
@@ -35,7 +42,7 @@ class Threads(Python3StringMixIn):
library only provides a one-time iterator (it cannot reset the
iterator to the start). Thus iterating over the function will
"exhaust" the list of threads, and a subsequent iteration attempt
- will raise a :exc:`NotmuchError` STATUS.NOT_INITIALIZED. Also
+ will raise a :exc:`NotInitializedError`. Also
note, that any function that uses iteration will also
exhaust the messages. So both::
@@ -87,8 +94,8 @@ class Threads(Python3StringMixIn):
will almost never instantiate a :class:`Threads` object
herself. They are usually handed back as a result,
e.g. in :meth:`Query.search_threads`. *threads_p* must be
- valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
+ valid, we will raise an :exc:`NullPointerError` if it is
+ `None`.
:type threads_p: :class:`ctypes.c_void_p`
:param parent: The parent object
(ie :class:`Query`) these tags are derived from. It saves
@@ -98,7 +105,7 @@ class Threads(Python3StringMixIn):
the Python object.(?)
"""
if not threads_p:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
self._threads = threads_p
#store parent, so we keep them alive as long as self is alive
@@ -118,7 +125,7 @@ class Threads(Python3StringMixIn):
def __next__(self):
if not self._threads:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
if not self._valid(self._threads):
self._threads = None
@@ -138,11 +145,11 @@ class Threads(Python3StringMixIn):
#THIS FAILS
threads = Database().create_query('').search_threads()
if len(threads) > 0: #this 'exhausts' threads
- # next line raises NotmuchError(STATUS.NOT_INITIALIZED)!!!
+ # next line raises :exc:`NotInitializedError`!!!
for thread in threads: print thread
"""
if not self._threads:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
i = 0
# returns 'bool'. On out-of-memory it returns None
@@ -220,8 +227,8 @@ class Thread(object):
will almost never instantiate a :class:`Thread` object
herself. They are usually handed back as a result,
e.g. when iterating through :class:`Threads`. *thread_p*
- must be valid, we will raise an :exc:`NotmuchError`
- (STATUS.NULL_POINTER) if it is `None`.
+ must be valid, we will raise an :exc:`NullPointerError`
+ if it is `None`.
:param parent: A 'parent' object is passed which this message is
derived from. We save a reference to it, so we can
@@ -229,7 +236,7 @@ class Thread(object):
objects are dead.
"""
if not thread_p:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
self._thread = thread_p
#keep reference to parent, so we keep it alive
self._parent = parent
@@ -241,11 +248,11 @@ class Thread(object):
for as long as the thread is valid.
:returns: String with a message ID
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
+ :exception: :exc:`NotInitializedError` if the thread
is not initialized.
"""
if not self._thread:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Thread._get_thread_id(self._thread).decode('utf-8', 'ignore')
_get_total_messages = nmlib.notmuch_thread_get_total_messages
@@ -258,11 +265,11 @@ class Thread(object):
:returns: The number of all messages in the database
belonging to this thread. Contrast with
:meth:`get_matched_messages`.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
+ :exception: :exc:`NotInitializedError` if the thread
is not initialized.
"""
if not self._thread:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return self._get_total_messages(self._thread)
def get_toplevel_messages(self):
@@ -279,18 +286,16 @@ class Thread(object):
messages, etc.).
:returns: :class:`Messages`
- :exception: :exc:`NotmuchError`
-
- * STATUS.NOT_INITIALIZED if query is not inited
- * STATUS.NULL_POINTER if search_messages failed
+ :raises: :exc:`NotInitializedError` if query is not initialized
+ :raises: :exc:`NullPointerError` if search_messages failed
"""
if not self._thread:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
msgs_p = Thread._get_toplevel_messages(self._thread)
if not msgs_p:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
return Messages(msgs_p, self)
@@ -304,11 +309,11 @@ class Thread(object):
:returns: The number of all messages belonging to this thread that
matched the :class:`Query`from which this thread was created.
Contrast with :meth:`get_total_messages`.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
+ :exception: :exc:`NotInitializedError` if the thread
is not initialized.
"""
if not self._thread:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return self._get_matched_messages(self._thread)
def get_authors(self):
@@ -322,7 +327,7 @@ class Thread(object):
as long as this Thread() is not deleted.
"""
if not self._thread:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
authors = Thread._get_authors(self._thread)
if not authors:
return None
@@ -335,7 +340,7 @@ class Thread(object):
as long as this Thread() is not deleted.
"""
if not self._thread:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
subject = Thread._get_subject(self._thread)
if not subject:
return None
@@ -346,11 +351,11 @@ class Thread(object):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._thread:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Thread._get_newest_date(self._thread)
def get_oldest_date(self):
@@ -358,11 +363,11 @@ class Thread(object):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._thread:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
return Thread._get_oldest_date(self._thread)
def get_tags(self):
@@ -378,18 +383,15 @@ class Thread(object):
query from which it derived is explicitely deleted).
:returns: A :class:`Tags` iterator.
- :exception: :exc:`NotmuchError`
-
- * STATUS.NOT_INITIALIZED if the thread
- is not initialized.
- * STATUS.NULL_POINTER, on error
+ :raises: :exc:`NotInitializedError` if query is not initialized
+ :raises: :exc:`NullPointerError` if search_messages failed
"""
if not self._thread:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
tags_p = Thread._get_tags(self._thread)
if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
return Tags(tags_p, self)
def __unicode__(self):
--
cgit v1.2.3
From 798b74e859734d12c953390bca0753f8e5e1d67c Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Tue, 21 Feb 2012 00:01:23 +0100
Subject: python: harmonize the sphinx keyword for exceptions
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/database.py | 24 ++++++++++++------------
bindings/python/notmuch/message.py | 14 +++++++-------
bindings/python/notmuch/query.py | 6 +++---
bindings/python/notmuch/thread.py | 10 +++++-----
4 files changed, 27 insertions(+), 27 deletions(-)
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 3de0f2b..42a4442 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -140,7 +140,7 @@ class Database(object):
:param mode: Mode to open a database in. Is always
:attr:`MODE`.READ_WRITE when creating a new one.
:type mode: :attr:`MODE`
- :exception: :exc:`NotmuchError` or derived exception in case of
+ :raises: :exc:`NotmuchError` or derived exception in case of
failure.
"""
self._db = None
@@ -177,7 +177,7 @@ class Database(object):
:param path: A directory in which we should create the database.
:type path: str
:returns: Nothing
- :exception: :exc:`NotmuchError` in case of any failure
+ :raises: :exc:`NotmuchError` in case of any failure
(possibly after printing an error message on stderr).
"""
if self._db is not None:
@@ -201,7 +201,7 @@ class Database(object):
:param status: Open the database in read-only or read-write mode
:type status: :attr:`MODE`
:returns: Nothing
- :exception: Raises :exc:`NotmuchError` in case of any failure
+ :raises: Raises :exc:`NotmuchError` in case of any failure
(possibly after printing an error message on stderr).
"""
res = Database._open(_str(path), mode)
@@ -296,7 +296,7 @@ class Database(object):
neither begin nor end necessarily flush modifications to disk.
:returns: :attr:`STATUS`.SUCCESS or raises
- :exception: :exc:`NotmuchError`: :attr:`STATUS`.XAPIAN_EXCEPTION
+ :raises: :exc:`NotmuchError`: :attr:`STATUS`.XAPIAN_EXCEPTION
Xapian exception occurred; atomic section not entered.
*Added in notmuch 0.9*"""
@@ -317,7 +317,7 @@ class Database(object):
:returns: :attr:`STATUS`.SUCCESS or raises
- :exception:
+ :raises:
:exc:`NotmuchError`:
:attr:`STATUS`.XAPIAN_EXCEPTION
A Xapian exception occurred; atomic section not
@@ -346,7 +346,7 @@ class Database(object):
of database (see :meth:`get_path`), or else should be an absolute
path with initial components that match the path of 'database'.
:returns: :class:`Directory` or raises an exception.
- :exception:
+ :raises:
:exc:`NotmuchError` with :attr:`STATUS`.FILE_ERROR
If path is not relative database or absolute with initial
components same as database.
@@ -410,7 +410,7 @@ class Database(object):
:rtype: 2-tuple(:class:`Message`, :attr:`STATUS`)
- :exception: Raises a :exc:`NotmuchError` with the following meaning.
+ :raises: Raises a :exc:`NotmuchError` with the following meaning.
If such an exception occurs, nothing was added to the database.
:attr:`STATUS`.FILE_ERROR
@@ -460,7 +460,7 @@ class Database(object):
This filename was removed but the message persists in the
database with at least one other filename.
- :exception: Raises a :exc:`NotmuchError` with the following meaning.
+ :raises: Raises a :exc:`NotmuchError` with the following meaning.
If such an exception occurs, nothing was removed from the
database.
@@ -479,7 +479,7 @@ class Database(object):
:param msgid: The message ID
:type msgid: unicode or str
:returns: :class:`Message` or `None` if no message is found.
- :exception:
+ :raises:
:exc:`OutOfMemoryError`
If an Out-of-memory occured while constructing the message.
:exc:`XapianError`
@@ -512,7 +512,7 @@ class Database(object):
function returns None if no message is found with the given
filename.
- :exception:
+ :raises:
:exc:`OutOfMemoryError`
If an Out-of-memory occured while constructing the message.
:exc:`XapianError`
@@ -681,7 +681,7 @@ class Directory(object):
:param mtime: A (time_t) timestamp
:returns: Nothing on success, raising an exception on failure.
- :exception: :exc:`NotmuchError`:
+ :raises: :exc:`NotmuchError`:
:attr:`STATUS`.XAPIAN_EXCEPTION
A Xapian exception occurred, mtime not stored.
@@ -708,7 +708,7 @@ class Directory(object):
:param mtime: A (time_t) timestamp
:returns: Nothing on success, raising an exception on failure.
- :exception: :exc:`NotmuchError`:
+ :raises: :exc:`NotmuchError`:
:attr:`STATUS`.NOT_INITIALIZED
The directory has not been initialized
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index b291f9f..ce7cb88 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -370,7 +370,7 @@ class Message(Python3StringMixIn):
"""Returns the message ID
:returns: String with a message ID
- :exception: :exc:`NotInitializedError` if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
@@ -387,7 +387,7 @@ class Message(Python3StringMixIn):
message belongs to a single thread.
:returns: String with a thread ID
- :exception: :exc:`NotInitializedError` if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
@@ -410,7 +410,7 @@ class Message(Python3StringMixIn):
an empty Messages iterator.
:returns: :class:`Messages`.
- :exception: :exc:`NotInitializedError` if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
@@ -432,7 +432,7 @@ class Message(Python3StringMixIn):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotInitializedError` if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
@@ -469,7 +469,7 @@ class Message(Python3StringMixIn):
"""Returns the file path of the message file
:returns: Absolute file path & name of the message file
- :exception: :exc:`NotInitializedError` if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
@@ -499,7 +499,7 @@ class Message(Python3StringMixIn):
:param flag: One of the :attr:`Message.FLAG` values (currently only
*Message.FLAG.MATCH*
:returns: An unsigned int (0/1), indicating whether the flag is set.
- :exception: :exc:`NotInitializedError` if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
@@ -514,7 +514,7 @@ class Message(Python3StringMixIn):
:param value: A bool indicating whether to set or unset the flag.
:returns: Nothing
- :exception: :exc:`NotInitializedError` if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._msg:
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index 6132ca0..25b9e78 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -89,7 +89,7 @@ class Query(object):
:param querystr: The query string
:type querystr: utf-8 encoded str or unicode
:returns: Nothing
- :exception:
+ :raises:
:exc:`NullPointerError` if the query creation failed
(e.g. too little memory).
:exc:`NotInitializedError` if the underlying db was not
@@ -134,7 +134,7 @@ class Query(object):
to get the value of this flag.
:returns: :class:`Threads`
- :exception: :exc:`NullPointerError` if search_threads failed
+ :raises: :exc:`NullPointerError` if search_threads failed
"""
self._assert_query_is_initialized()
threads_p = Query._search_threads(self._query)
@@ -153,7 +153,7 @@ class Query(object):
:class:`Messages` in the defined sort order
:returns: :class:`Messages`
- :exception: :exc:`NullPointerError` if search_messages failed
+ :raises: :exc:`NullPointerError` if search_messages failed
"""
self._assert_query_is_initialized()
msgs_p = Query._search_messages(self._query)
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index 5c58028..d1ba3e5 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -248,7 +248,7 @@ class Thread(object):
for as long as the thread is valid.
:returns: String with a message ID
- :exception: :exc:`NotInitializedError` if the thread
+ :raises: :exc:`NotInitializedError` if the thread
is not initialized.
"""
if not self._thread:
@@ -265,7 +265,7 @@ class Thread(object):
:returns: The number of all messages in the database
belonging to this thread. Contrast with
:meth:`get_matched_messages`.
- :exception: :exc:`NotInitializedError` if the thread
+ :raises: :exc:`NotInitializedError` if the thread
is not initialized.
"""
if not self._thread:
@@ -309,7 +309,7 @@ class Thread(object):
:returns: The number of all messages belonging to this thread that
matched the :class:`Query`from which this thread was created.
Contrast with :meth:`get_total_messages`.
- :exception: :exc:`NotInitializedError` if the thread
+ :raises: :exc:`NotInitializedError` if the thread
is not initialized.
"""
if not self._thread:
@@ -351,7 +351,7 @@ class Thread(object):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotInitializedError` if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._thread:
@@ -363,7 +363,7 @@ class Thread(object):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotInitializedError` if the message
+ :raises: :exc:`NotInitializedError` if the message
is not initialized.
"""
if not self._thread:
--
cgit v1.2.3
From 69f077898a65c10453d08dd94bf4c94efc69b91b Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Wed, 22 Feb 2012 22:34:40 +0100
Subject: python: move Messages class into its own file
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/__init__.py | 3 +-
bindings/python/notmuch/message.py | 242 +--------------------------------
bindings/python/notmuch/messages.py | 262 ++++++++++++++++++++++++++++++++++++
bindings/python/notmuch/query.py | 2 +-
bindings/python/notmuch/thread.py | 2 +-
5 files changed, 272 insertions(+), 239 deletions(-)
create mode 100644 bindings/python/notmuch/messages.py
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py
index 8de73d5..b8f3610 100644
--- a/bindings/python/notmuch/__init__.py
+++ b/bindings/python/notmuch/__init__.py
@@ -54,7 +54,8 @@ Copyright 2010-2011 Sebastian Spaeth
from .database import Database
from .directory import Directory
from .filename import Filenames
-from .message import Messages, Message
+from .message import Message
+from .messages import Messages
from .query import Query
from .tag import Tags
from .thread import Threads, Thread
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index 9ebb53d..20ba9cb 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -21,7 +21,7 @@ Copyright 2010 Sebastian Spaeth '
from ctypes import c_char_p, c_long, c_uint, c_int
from datetime import date
-from notmuch.globals import (
+from .globals import (
nmlib,
Enum,
_str,
@@ -35,9 +35,9 @@ from notmuch.globals import (
NotmuchMessagesP,
NotmuchFilenamesP,
)
-from notmuch.tag import Tags
-from notmuch.filename import Filenames
-import sys
+from .tag import Tags
+from .filename import Filenames
+
import email
try:
import simplejson as json
@@ -45,238 +45,6 @@ except ImportError:
import json
-class Messages(object):
- """Represents a list of notmuch messages
-
- This object provides an iterator over a list of notmuch messages
- (Technically, it provides a wrapper for the underlying
- *notmuch_messages_t* structure). Do note that the underlying library
- only provides a one-time iterator (it cannot reset the iterator to
- the start). Thus iterating over the function will "exhaust" the list
- of messages, and a subsequent iteration attempt will raise a
- :exc:`NotInitializedError`. If you need to
- re-iterate over a list of messages you will need to retrieve a new
- :class:`Messages` object or cache your :class:`Message`\s in a list
- via::
-
- msglist = list(msgs)
-
- You can store and reuse the single :class:`Message` objects as often
- as you want as long as you keep the parent :class:`Messages` object
- around. (Due to hierarchical memory allocation, all derived
- :class:`Message` objects will be invalid when we delete the parent
- :class:`Messages` object, even if it was already exhausted.) So
- this works::
-
- db = Database()
- msgs = Query(db,'').search_messages() #get a Messages() object
- msglist = list(msgs)
-
- # msgs is "exhausted" now and msgs.next() will raise an exception.
- # However it will be kept alive until all retrieved Message()
- # objects are also deleted. If you do e.g. an explicit del(msgs)
- # here, the following lines would fail.
-
- # You can reiterate over *msglist* however as often as you want.
- # It is simply a list with :class:`Message`s.
-
- print (msglist[0].get_filename())
- print (msglist[1].get_filename())
- print (msglist[0].get_message_id())
-
-
- As :class:`Message` implements both __hash__() and __cmp__(), it is
- possible to make sets out of :class:`Messages` and use set
- arithmetic (this happens in python and will of course be *much*
- slower than redoing a proper query with the appropriate filters::
-
- s1, s2 = set(msgs1), set(msgs2)
- s.union(s2)
- s1 -= s2
- ...
-
- Be careful when using set arithmetic between message sets derived
- from different Databases (ie the same database reopened after
- messages have changed). If messages have added or removed associated
- files in the meantime, it is possible that the same message would be
- considered as a different object (as it points to a different file).
- """
-
- #notmuch_messages_get
- _get = nmlib.notmuch_messages_get
- _get.argtypes = [NotmuchMessagesP]
- _get.restype = NotmuchMessageP
-
- _collect_tags = nmlib.notmuch_messages_collect_tags
- _collect_tags.argtypes = [NotmuchMessagesP]
- _collect_tags.restype = NotmuchTagsP
-
- def __init__(self, msgs_p, parent=None):
- """
- :param msgs_p: A pointer to an underlying *notmuch_messages_t*
- structure. These are not publically exposed, so a user
- will almost never instantiate a :class:`Messages` object
- herself. They are usually handed back as a result,
- e.g. in :meth:`Query.search_messages`. *msgs_p* must be
- valid, we will raise an :exc:`NullPointerError` if it is
- `None`.
- :type msgs_p: :class:`ctypes.c_void_p`
- :param parent: The parent object
- (ie :class:`Query`) these tags are derived from. It saves
- a reference to it, so we can automatically delete the db
- object once all derived objects are dead.
- :TODO: Make the iterator work more than once and cache the tags in
- the Python object.(?)
- """
- if not msgs_p:
- raise NullPointerError()
-
- self._msgs = msgs_p
- #store parent, so we keep them alive as long as self is alive
- self._parent = parent
-
- def collect_tags(self):
- """Return the unique :class:`Tags` in the contained messages
-
- :returns: :class:`Tags`
- :exceptions: :exc:`NotInitializedError` if not init'ed
-
- .. note::
-
- :meth:`collect_tags` will iterate over the messages and therefore
- will not allow further iterations.
- """
- if not self._msgs:
- raise NotInitializedError()
-
- # collect all tags (returns NULL on error)
- tags_p = Messages._collect_tags(self._msgs)
- #reset _msgs as we iterated over it and can do so only once
- self._msgs = None
-
- if tags_p == None:
- raise NullPointerError()
- return Tags(tags_p, self)
-
- def __iter__(self):
- """ Make Messages an iterator """
- return self
-
- _valid = nmlib.notmuch_messages_valid
- _valid.argtypes = [NotmuchMessagesP]
- _valid.restype = bool
-
- _move_to_next = nmlib.notmuch_messages_move_to_next
- _move_to_next.argtypes = [NotmuchMessagesP]
- _move_to_next.restype = None
-
- def __next__(self):
- if not self._msgs:
- raise NotInitializedError()
-
- if not self._valid(self._msgs):
- self._msgs = None
- raise StopIteration
-
- msg = Message(Messages._get(self._msgs), self)
- self._move_to_next(self._msgs)
- return msg
- next = __next__ # python2.x iterator protocol compatibility
-
- def __nonzero__(self):
- """
- :return: True if there is at least one more thread in the
- Iterator, False if not."""
- return self._msgs is not None and \
- self._valid(self._msgs) > 0
-
- _destroy = nmlib.notmuch_messages_destroy
- _destroy.argtypes = [NotmuchMessagesP]
- _destroy.restype = None
-
- def __del__(self):
- """Close and free the notmuch Messages"""
- if self._msgs is not None:
- self._destroy(self._msgs)
-
- def format_messages(self, format, indent=0, entire_thread=False):
- """Formats messages as needed for 'notmuch show'.
-
- :param format: A string of either 'text' or 'json'.
- :param indent: A number indicating the reply depth of these messages.
- :param entire_thread: A bool, indicating whether we want to output
- whole threads or only the matching messages.
- :return: a list of lines
- """
- result = list()
-
- if format.lower() == "text":
- set_start = ""
- set_end = ""
- set_sep = ""
- elif format.lower() == "json":
- set_start = "["
- set_end = "]"
- set_sep = ", "
- else:
- raise TypeError("format must be either 'text' or 'json'")
-
- first_set = True
-
- result.append(set_start)
-
- # iterate through all toplevel messages in this thread
- for msg in self:
- # if not msg:
- # break
- if not first_set:
- result.append(set_sep)
- first_set = False
-
- result.append(set_start)
- match = msg.is_match()
- next_indent = indent
-
- if (match or entire_thread):
- if format.lower() == "text":
- result.append(msg.format_message_as_text(indent))
- else:
- result.append(msg.format_message_as_json(indent))
- next_indent = indent + 1
-
- # get replies and print them also out (if there are any)
- replies = msg.get_replies().format_messages(format, next_indent, entire_thread)
- if replies:
- result.append(set_sep)
- result.extend(replies)
-
- result.append(set_end)
- result.append(set_end)
-
- return result
-
- def print_messages(self, format, indent=0, entire_thread=False, handle=sys.stdout):
- """Outputs messages as needed for 'notmuch show' to a file like object.
-
- :param format: A string of either 'text' or 'json'.
- :param handle: A file like object to print to (default is sys.stdout).
- :param indent: A number indicating the reply depth of these messages.
- :param entire_thread: A bool, indicating whether we want to output
- whole threads or only the matching messages.
- """
- handle.write(''.join(self.format_messages(format, indent, entire_thread)))
-
-
-class EmptyMessagesResult(Messages):
- def __init__(self, parent):
- self._msgs = None
- self._parent = parent
-
- def __next__(self):
- raise StopIteration()
- next = __next__
-
-
class Message(Python3StringMixIn):
"""Represents a single Email message
@@ -418,6 +186,8 @@ class Message(Python3StringMixIn):
msgs_p = Message._get_replies(self._msg)
+ from .messages import Messages, EmptyMessagesResult
+
if not msgs_p:
return EmptyMessagesResult(self)
diff --git a/bindings/python/notmuch/messages.py b/bindings/python/notmuch/messages.py
new file mode 100644
index 0000000..20d3632
--- /dev/null
+++ b/bindings/python/notmuch/messages.py
@@ -0,0 +1,262 @@
+"""
+This file is part of notmuch.
+
+Notmuch is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Notmuch is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with notmuch. If not, see .
+
+Copyright 2010 Sebastian Spaeth '
+ Jesse Rosenthal
+"""
+
+from .globals import (
+ nmlib,
+ NullPointerError,
+ NotInitializedError,
+ NotmuchTagsP,
+ NotmuchMessageP,
+ NotmuchMessagesP,
+)
+from .tag import Tags
+from .message import Message
+
+import sys
+
+class Messages(object):
+ """Represents a list of notmuch messages
+
+ This object provides an iterator over a list of notmuch messages
+ (Technically, it provides a wrapper for the underlying
+ *notmuch_messages_t* structure). Do note that the underlying library
+ only provides a one-time iterator (it cannot reset the iterator to
+ the start). Thus iterating over the function will "exhaust" the list
+ of messages, and a subsequent iteration attempt will raise a
+ :exc:`NotInitializedError`. If you need to
+ re-iterate over a list of messages you will need to retrieve a new
+ :class:`Messages` object or cache your :class:`Message`\s in a list
+ via::
+
+ msglist = list(msgs)
+
+ You can store and reuse the single :class:`Message` objects as often
+ as you want as long as you keep the parent :class:`Messages` object
+ around. (Due to hierarchical memory allocation, all derived
+ :class:`Message` objects will be invalid when we delete the parent
+ :class:`Messages` object, even if it was already exhausted.) So
+ this works::
+
+ db = Database()
+ msgs = Query(db,'').search_messages() #get a Messages() object
+ msglist = list(msgs)
+
+ # msgs is "exhausted" now and msgs.next() will raise an exception.
+ # However it will be kept alive until all retrieved Message()
+ # objects are also deleted. If you do e.g. an explicit del(msgs)
+ # here, the following lines would fail.
+
+ # You can reiterate over *msglist* however as often as you want.
+ # It is simply a list with :class:`Message`s.
+
+ print (msglist[0].get_filename())
+ print (msglist[1].get_filename())
+ print (msglist[0].get_message_id())
+
+
+ As :class:`Message` implements both __hash__() and __cmp__(), it is
+ possible to make sets out of :class:`Messages` and use set
+ arithmetic (this happens in python and will of course be *much*
+ slower than redoing a proper query with the appropriate filters::
+
+ s1, s2 = set(msgs1), set(msgs2)
+ s.union(s2)
+ s1 -= s2
+ ...
+
+ Be careful when using set arithmetic between message sets derived
+ from different Databases (ie the same database reopened after
+ messages have changed). If messages have added or removed associated
+ files in the meantime, it is possible that the same message would be
+ considered as a different object (as it points to a different file).
+ """
+
+ #notmuch_messages_get
+ _get = nmlib.notmuch_messages_get
+ _get.argtypes = [NotmuchMessagesP]
+ _get.restype = NotmuchMessageP
+
+ _collect_tags = nmlib.notmuch_messages_collect_tags
+ _collect_tags.argtypes = [NotmuchMessagesP]
+ _collect_tags.restype = NotmuchTagsP
+
+ def __init__(self, msgs_p, parent=None):
+ """
+ :param msgs_p: A pointer to an underlying *notmuch_messages_t*
+ structure. These are not publically exposed, so a user
+ will almost never instantiate a :class:`Messages` object
+ herself. They are usually handed back as a result,
+ e.g. in :meth:`Query.search_messages`. *msgs_p* must be
+ valid, we will raise an :exc:`NullPointerError` if it is
+ `None`.
+ :type msgs_p: :class:`ctypes.c_void_p`
+ :param parent: The parent object
+ (ie :class:`Query`) these tags are derived from. It saves
+ a reference to it, so we can automatically delete the db
+ object once all derived objects are dead.
+ :TODO: Make the iterator work more than once and cache the tags in
+ the Python object.(?)
+ """
+ if not msgs_p:
+ raise NullPointerError()
+
+ self._msgs = msgs_p
+ #store parent, so we keep them alive as long as self is alive
+ self._parent = parent
+
+ def collect_tags(self):
+ """Return the unique :class:`Tags` in the contained messages
+
+ :returns: :class:`Tags`
+ :exceptions: :exc:`NotInitializedError` if not init'ed
+
+ .. note::
+
+ :meth:`collect_tags` will iterate over the messages and therefore
+ will not allow further iterations.
+ """
+ if not self._msgs:
+ raise NotInitializedError()
+
+ # collect all tags (returns NULL on error)
+ tags_p = Messages._collect_tags(self._msgs)
+ #reset _msgs as we iterated over it and can do so only once
+ self._msgs = None
+
+ if tags_p == None:
+ raise NullPointerError()
+ return Tags(tags_p, self)
+
+ def __iter__(self):
+ """ Make Messages an iterator """
+ return self
+
+ _valid = nmlib.notmuch_messages_valid
+ _valid.argtypes = [NotmuchMessagesP]
+ _valid.restype = bool
+
+ _move_to_next = nmlib.notmuch_messages_move_to_next
+ _move_to_next.argtypes = [NotmuchMessagesP]
+ _move_to_next.restype = None
+
+ def __next__(self):
+ if not self._msgs:
+ raise NotInitializedError()
+
+ if not self._valid(self._msgs):
+ self._msgs = None
+ raise StopIteration
+
+ msg = Message(Messages._get(self._msgs), self)
+ self._move_to_next(self._msgs)
+ return msg
+ next = __next__ # python2.x iterator protocol compatibility
+
+ def __nonzero__(self):
+ """
+ :return: True if there is at least one more thread in the
+ Iterator, False if not."""
+ return self._msgs is not None and \
+ self._valid(self._msgs) > 0
+
+ _destroy = nmlib.notmuch_messages_destroy
+ _destroy.argtypes = [NotmuchMessagesP]
+ _destroy.restype = None
+
+ def __del__(self):
+ """Close and free the notmuch Messages"""
+ if self._msgs is not None:
+ self._destroy(self._msgs)
+
+ def format_messages(self, format, indent=0, entire_thread=False):
+ """Formats messages as needed for 'notmuch show'.
+
+ :param format: A string of either 'text' or 'json'.
+ :param indent: A number indicating the reply depth of these messages.
+ :param entire_thread: A bool, indicating whether we want to output
+ whole threads or only the matching messages.
+ :return: a list of lines
+ """
+ result = list()
+
+ if format.lower() == "text":
+ set_start = ""
+ set_end = ""
+ set_sep = ""
+ elif format.lower() == "json":
+ set_start = "["
+ set_end = "]"
+ set_sep = ", "
+ else:
+ raise TypeError("format must be either 'text' or 'json'")
+
+ first_set = True
+
+ result.append(set_start)
+
+ # iterate through all toplevel messages in this thread
+ for msg in self:
+ # if not msg:
+ # break
+ if not first_set:
+ result.append(set_sep)
+ first_set = False
+
+ result.append(set_start)
+ match = msg.is_match()
+ next_indent = indent
+
+ if (match or entire_thread):
+ if format.lower() == "text":
+ result.append(msg.format_message_as_text(indent))
+ else:
+ result.append(msg.format_message_as_json(indent))
+ next_indent = indent + 1
+
+ # get replies and print them also out (if there are any)
+ replies = msg.get_replies().format_messages(format, next_indent, entire_thread)
+ if replies:
+ result.append(set_sep)
+ result.extend(replies)
+
+ result.append(set_end)
+ result.append(set_end)
+
+ return result
+
+ def print_messages(self, format, indent=0, entire_thread=False, handle=sys.stdout):
+ """Outputs messages as needed for 'notmuch show' to a file like object.
+
+ :param format: A string of either 'text' or 'json'.
+ :param handle: A file like object to print to (default is sys.stdout).
+ :param indent: A number indicating the reply depth of these messages.
+ :param entire_thread: A bool, indicating whether we want to output
+ whole threads or only the matching messages.
+ """
+ handle.write(''.join(self.format_messages(format, indent, entire_thread)))
+
+class EmptyMessagesResult(Messages):
+ def __init__(self, parent):
+ self._msgs = None
+ self._parent = parent
+
+ def __next__(self):
+ raise StopIteration()
+ next = __next__
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index 15ed153..b669a3e 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -30,7 +30,7 @@ from notmuch.globals import (
NotInitializedError,
)
from notmuch.thread import Threads
-from notmuch.message import Messages
+from .messages import Messages
class Query(object):
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index d1ba3e5..c599bcb 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -28,7 +28,7 @@ from notmuch.globals import (
NotmuchMessagesP,
NotmuchTagsP,
)
-from notmuch.message import Messages
+from .messages import Messages
from notmuch.tag import Tags
from datetime import date
--
cgit v1.2.3
From 76a2db3d7b92bc1a8be75f673dc384c46cf02fab Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Wed, 22 Feb 2012 22:39:52 +0100
Subject: python: move Threads class into its own file
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/__init__.py | 3 +-
bindings/python/notmuch/query.py | 2 +-
bindings/python/notmuch/thread.py | 154 -------------------------------
bindings/python/notmuch/threads.py | 178 ++++++++++++++++++++++++++++++++++++
4 files changed, 181 insertions(+), 156 deletions(-)
create mode 100644 bindings/python/notmuch/threads.py
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py
index b8f3610..89b9849 100644
--- a/bindings/python/notmuch/__init__.py
+++ b/bindings/python/notmuch/__init__.py
@@ -58,7 +58,8 @@ from .message import Message
from .messages import Messages
from .query import Query
from .tag import Tags
-from .thread import Threads, Thread
+from .thread import Thread
+from .threads import Threads
from .globals import (
nmlib,
STATUS,
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index b669a3e..fcd67e5 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -29,7 +29,7 @@ from notmuch.globals import (
NullPointerError,
NotInitializedError,
)
-from notmuch.thread import Threads
+from .threads import Threads
from .messages import Messages
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index c599bcb..0dac522 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -20,11 +20,9 @@ Copyright 2010 Sebastian Spaeth '
from ctypes import c_char_p, c_long, c_int
from notmuch.globals import (
nmlib,
- Python3StringMixIn,
NullPointerError,
NotInitializedError,
NotmuchThreadP,
- NotmuchThreadsP,
NotmuchMessagesP,
NotmuchTagsP,
)
@@ -32,158 +30,6 @@ from .messages import Messages
from notmuch.tag import Tags
from datetime import date
-
-class Threads(Python3StringMixIn):
- """Represents a list of notmuch threads
-
- This object provides an iterator over a list of notmuch threads
- (Technically, it provides a wrapper for the underlying
- *notmuch_threads_t* structure). Do note that the underlying
- library only provides a one-time iterator (it cannot reset the
- iterator to the start). Thus iterating over the function will
- "exhaust" the list of threads, and a subsequent iteration attempt
- will raise a :exc:`NotInitializedError`. Also
- note, that any function that uses iteration will also
- exhaust the messages. So both::
-
- for thread in threads: print thread
-
- as well as::
-
- number_of_msgs = len(threads)
-
- will "exhaust" the threads. If you need to re-iterate over a list of
- messages you will need to retrieve a new :class:`Threads` object.
-
- Things are not as bad as it seems though, you can store and reuse
- the single Thread objects as often as you want as long as you
- keep the parent Threads object around. (Recall that due to
- hierarchical memory allocation, all derived Threads objects will
- be invalid when we delete the parent Threads() object, even if it
- was already "exhausted".) So this works::
-
- db = Database()
- threads = Query(db,'').search_threads() #get a Threads() object
- threadlist = []
- for thread in threads:
- threadlist.append(thread)
-
- # threads is "exhausted" now and even len(threads) will raise an
- # exception.
- # However it will be kept around until all retrieved Thread() objects are
- # also deleted. If you did e.g. an explicit del(threads) here, the
- # following lines would fail.
-
- # You can reiterate over *threadlist* however as often as you want.
- # It is simply a list with Thread objects.
-
- print (threadlist[0].get_thread_id())
- print (threadlist[1].get_thread_id())
- print (threadlist[0].get_total_messages())
- """
-
- #notmuch_threads_get
- _get = nmlib.notmuch_threads_get
- _get.argtypes = [NotmuchThreadsP]
- _get.restype = NotmuchThreadP
-
- def __init__(self, threads_p, parent=None):
- """
- :param threads_p: A pointer to an underlying *notmuch_threads_t*
- structure. These are not publically exposed, so a user
- will almost never instantiate a :class:`Threads` object
- herself. They are usually handed back as a result,
- e.g. in :meth:`Query.search_threads`. *threads_p* must be
- valid, we will raise an :exc:`NullPointerError` if it is
- `None`.
- :type threads_p: :class:`ctypes.c_void_p`
- :param parent: The parent object
- (ie :class:`Query`) these tags are derived from. It saves
- a reference to it, so we can automatically delete the db
- object once all derived objects are dead.
- :TODO: Make the iterator work more than once and cache the tags in
- the Python object.(?)
- """
- if not threads_p:
- raise NullPointerError()
-
- self._threads = threads_p
- #store parent, so we keep them alive as long as self is alive
- self._parent = parent
-
- def __iter__(self):
- """ Make Threads an iterator """
- return self
-
- _valid = nmlib.notmuch_threads_valid
- _valid.argtypes = [NotmuchThreadsP]
- _valid.restype = bool
-
- _move_to_next = nmlib.notmuch_threads_move_to_next
- _move_to_next.argtypes = [NotmuchThreadsP]
- _move_to_next.restype = None
-
- def __next__(self):
- if not self._threads:
- raise NotInitializedError()
-
- if not self._valid(self._threads):
- self._threads = None
- raise StopIteration
-
- thread = Thread(Threads._get(self._threads), self)
- self._move_to_next(self._threads)
- return thread
- next = __next__ # python2.x iterator protocol compatibility
-
- def __len__(self):
- """len(:class:`Threads`) returns the number of contained Threads
-
- .. note:: As this iterates over the threads, we will not be able to
- iterate over them again! So this will fail::
-
- #THIS FAILS
- threads = Database().create_query('').search_threads()
- if len(threads) > 0: #this 'exhausts' threads
- # next line raises :exc:`NotInitializedError`!!!
- for thread in threads: print thread
- """
- if not self._threads:
- raise NotInitializedError()
-
- i = 0
- # returns 'bool'. On out-of-memory it returns None
- while self._valid(self._threads):
- self._move_to_next(self._threads)
- i += 1
- # reset self._threads to mark as "exhausted"
- self._threads = None
- return i
-
- def __nonzero__(self):
- """Check if :class:`Threads` contains at least one more valid thread
-
- The existence of this function makes 'if Threads: foo' work, as
- that will implicitely call len() exhausting the iterator if
- __nonzero__ does not exist. This function makes `bool(Threads())`
- work repeatedly.
-
- :return: True if there is at least one more thread in the
- Iterator, False if not. None on a "Out-of-memory" error.
- """
- return self._threads is not None and \
- self._valid(self._threads) > 0
-
- _destroy = nmlib.notmuch_threads_destroy
- _destroy.argtypes = [NotmuchThreadsP]
- _destroy.argtypes = None
-
- def __del__(self):
- """Close and free the notmuch Threads"""
- if self._threads is not None:
- self._destroy(self._threads)
-
-
class Thread(object):
"""Represents a single message thread."""
diff --git a/bindings/python/notmuch/threads.py b/bindings/python/notmuch/threads.py
new file mode 100644
index 0000000..9d305e2
--- /dev/null
+++ b/bindings/python/notmuch/threads.py
@@ -0,0 +1,178 @@
+"""
+This file is part of notmuch.
+
+Notmuch is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Notmuch is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with notmuch. If not, see .
+
+Copyright 2010 Sebastian Spaeth '
+"""
+
+from notmuch.globals import (
+ nmlib,
+ Python3StringMixIn,
+ NullPointerError,
+ NotInitializedError,
+ NotmuchThreadP,
+ NotmuchThreadsP,
+)
+from .thread import Thread
+
+class Threads(Python3StringMixIn):
+ """Represents a list of notmuch threads
+
+ This object provides an iterator over a list of notmuch threads
+ (Technically, it provides a wrapper for the underlying
+ *notmuch_threads_t* structure). Do note that the underlying
+ library only provides a one-time iterator (it cannot reset the
+ iterator to the start). Thus iterating over the function will
+ "exhaust" the list of threads, and a subsequent iteration attempt
+ will raise a :exc:`NotInitializedError`. Also
+ note, that any function that uses iteration will also
+ exhaust the messages. So both::
+
+ for thread in threads: print thread
+
+ as well as::
+
+ number_of_msgs = len(threads)
+
+ will "exhaust" the threads. If you need to re-iterate over a list of
+ messages you will need to retrieve a new :class:`Threads` object.
+
+ Things are not as bad as it seems though, you can store and reuse
+ the single Thread objects as often as you want as long as you
+ keep the parent Threads object around. (Recall that due to
+ hierarchical memory allocation, all derived Threads objects will
+ be invalid when we delete the parent Threads() object, even if it
+ was already "exhausted".) So this works::
+
+ db = Database()
+ threads = Query(db,'').search_threads() #get a Threads() object
+ threadlist = []
+ for thread in threads:
+ threadlist.append(thread)
+
+ # threads is "exhausted" now and even len(threads) will raise an
+ # exception.
+ # However it will be kept around until all retrieved Thread() objects are
+ # also deleted. If you did e.g. an explicit del(threads) here, the
+ # following lines would fail.
+
+ # You can reiterate over *threadlist* however as often as you want.
+ # It is simply a list with Thread objects.
+
+ print (threadlist[0].get_thread_id())
+ print (threadlist[1].get_thread_id())
+ print (threadlist[0].get_total_messages())
+ """
+
+ #notmuch_threads_get
+ _get = nmlib.notmuch_threads_get
+ _get.argtypes = [NotmuchThreadsP]
+ _get.restype = NotmuchThreadP
+
+ def __init__(self, threads_p, parent=None):
+ """
+ :param threads_p: A pointer to an underlying *notmuch_threads_t*
+ structure. These are not publically exposed, so a user
+ will almost never instantiate a :class:`Threads` object
+ herself. They are usually handed back as a result,
+ e.g. in :meth:`Query.search_threads`. *threads_p* must be
+ valid, we will raise an :exc:`NullPointerError` if it is
+ `None`.
+ :type threads_p: :class:`ctypes.c_void_p`
+ :param parent: The parent object
+ (ie :class:`Query`) these tags are derived from. It saves
+ a reference to it, so we can automatically delete the db
+ object once all derived objects are dead.
+ :TODO: Make the iterator work more than once and cache the tags in
+ the Python object.(?)
+ """
+ if not threads_p:
+ raise NullPointerError()
+
+ self._threads = threads_p
+ #store parent, so we keep them alive as long as self is alive
+ self._parent = parent
+
+ def __iter__(self):
+ """ Make Threads an iterator """
+ return self
+
+ _valid = nmlib.notmuch_threads_valid
+ _valid.argtypes = [NotmuchThreadsP]
+ _valid.restype = bool
+
+ _move_to_next = nmlib.notmuch_threads_move_to_next
+ _move_to_next.argtypes = [NotmuchThreadsP]
+ _move_to_next.restype = None
+
+ def __next__(self):
+ if not self._threads:
+ raise NotInitializedError()
+
+ if not self._valid(self._threads):
+ self._threads = None
+ raise StopIteration
+
+ thread = Thread(Threads._get(self._threads), self)
+ self._move_to_next(self._threads)
+ return thread
+ next = __next__ # python2.x iterator protocol compatibility
+
+ def __len__(self):
+ """len(:class:`Threads`) returns the number of contained Threads
+
+ .. note:: As this iterates over the threads, we will not be able to
+ iterate over them again! So this will fail::
+
+ #THIS FAILS
+ threads = Database().create_query('').search_threads()
+ if len(threads) > 0: #this 'exhausts' threads
+ # next line raises :exc:`NotInitializedError`!!!
+ for thread in threads: print thread
+ """
+ if not self._threads:
+ raise NotInitializedError()
+
+ i = 0
+ # returns 'bool'. On out-of-memory it returns None
+ while self._valid(self._threads):
+ self._move_to_next(self._threads)
+ i += 1
+ # reset self._threads to mark as "exhausted"
+ self._threads = None
+ return i
+
+ def __nonzero__(self):
+ """Check if :class:`Threads` contains at least one more valid thread
+
+ The existence of this function makes 'if Threads: foo' work, as
+ that will implicitely call len() exhausting the iterator if
+ __nonzero__ does not exist. This function makes `bool(Threads())`
+ work repeatedly.
+
+ :return: True if there is at least one more thread in the
+ Iterator, False if not. None on a "Out-of-memory" error.
+ """
+ return self._threads is not None and \
+ self._valid(self._threads) > 0
+
+ _destroy = nmlib.notmuch_threads_destroy
+ _destroy.argtypes = [NotmuchThreadsP]
+ _destroy.argtypes = None
+
+ def __del__(self):
+ """Close and free the notmuch Threads"""
+ if self._threads is not None:
+ self._destroy(self._threads)
--
cgit v1.2.3
From a7561cc20b17669784c3259afcbcef98029f93e9 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Thu, 23 Feb 2012 00:11:22 +0100
Subject: python: move the exception classes into error.py
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/__init__.py | 4 +-
bindings/python/notmuch/database.py | 14 +--
bindings/python/notmuch/directory.py | 6 +-
bindings/python/notmuch/errors.py | 183 +++++++++++++++++++++++++++++++++++
bindings/python/notmuch/filenames.py | 6 +-
bindings/python/notmuch/globals.py | 160 +-----------------------------
bindings/python/notmuch/message.py | 10 +-
bindings/python/notmuch/messages.py | 6 +-
bindings/python/notmuch/query.py | 2 +
bindings/python/notmuch/tag.py | 4 +-
bindings/python/notmuch/thread.py | 6 +-
bindings/python/notmuch/threads.py | 6 +-
12 files changed, 225 insertions(+), 182 deletions(-)
create mode 100644 bindings/python/notmuch/errors.py
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py
index fddc492..5561624 100644
--- a/bindings/python/notmuch/__init__.py
+++ b/bindings/python/notmuch/__init__.py
@@ -60,8 +60,8 @@ from .query import Query
from .tag import Tags
from .thread import Thread
from .threads import Threads
-from .globals import (
- nmlib,
+from .globals import nmlib
+from .errors import (
STATUS,
NotmuchError,
OutOfMemoryError,
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 800264b..44d40fd 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -22,12 +22,6 @@ import codecs
from ctypes import c_char_p, c_void_p, c_uint, byref, POINTER
from notmuch.globals import (
nmlib,
- STATUS,
- FileError,
- NotmuchError,
- NullPointerError,
- NotInitializedError,
- ReadOnlyDatabaseError,
Enum,
_str,
NotmuchDatabaseP,
@@ -35,6 +29,14 @@ from notmuch.globals import (
NotmuchMessageP,
NotmuchTagsP,
)
+from .errors import (
+ STATUS,
+ FileError,
+ NotmuchError,
+ NullPointerError,
+ NotInitializedError,
+ ReadOnlyDatabaseError,
+)
from notmuch.message import Message
from notmuch.tag import Tags
from .query import Query
diff --git a/bindings/python/notmuch/directory.py b/bindings/python/notmuch/directory.py
index b679aa2..0c5e015 100644
--- a/bindings/python/notmuch/directory.py
+++ b/bindings/python/notmuch/directory.py
@@ -20,11 +20,13 @@ Copyright 2010 Sebastian Spaeth '
from ctypes import c_uint, c_long
from notmuch.globals import (
nmlib,
+ NotmuchDirectoryP,
+ NotmuchFilenamesP
+)
+from .errors import (
STATUS,
NotmuchError,
NotInitializedError,
- NotmuchDirectoryP,
- NotmuchFilenamesP
)
from .filenames import Filenames
diff --git a/bindings/python/notmuch/errors.py b/bindings/python/notmuch/errors.py
new file mode 100644
index 0000000..f153a9c
--- /dev/null
+++ b/bindings/python/notmuch/errors.py
@@ -0,0 +1,183 @@
+"""
+This file is part of notmuch.
+
+Notmuch is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Notmuch is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with notmuch. If not, see .
+
+Copyright 2010 Sebastian Spaeth
+"""
+
+from ctypes import c_char_p, c_int
+
+from .globals import (
+ nmlib,
+ Enum,
+ Python3StringMixIn,
+)
+
+class Status(Enum):
+ """Enum with a string representation of a notmuch_status_t value."""
+ _status2str = nmlib.notmuch_status_to_string
+ _status2str.restype = c_char_p
+ _status2str.argtypes = [c_int]
+
+ def __init__(self, statuslist):
+ """It is initialized with a list of strings that are available as
+ Status().string1 - Status().stringn attributes.
+ """
+ super(Status, self).__init__(statuslist)
+
+ @classmethod
+ def status2str(self, status):
+ """Get a (unicode) string representation of a notmuch_status_t value."""
+ # define strings for custom error messages
+ if status == STATUS.NOT_INITIALIZED:
+ return "Operation on uninitialized object impossible."
+ return unicode(Status._status2str(status))
+
+STATUS = Status(['SUCCESS',
+ 'OUT_OF_MEMORY',
+ 'READ_ONLY_DATABASE',
+ 'XAPIAN_EXCEPTION',
+ 'FILE_ERROR',
+ 'FILE_NOT_EMAIL',
+ 'DUPLICATE_MESSAGE_ID',
+ 'NULL_POINTER',
+ 'TAG_TOO_LONG',
+ 'UNBALANCED_FREEZE_THAW',
+ 'UNBALANCED_ATOMIC',
+ 'NOT_INITIALIZED'])
+"""STATUS is a class, whose attributes provide constants that serve as return
+indicators for notmuch functions. Currently the following ones are defined. For
+possible return values and specific meaning for each method, see the method
+description.
+
+ * SUCCESS
+ * OUT_OF_MEMORY
+ * READ_ONLY_DATABASE
+ * XAPIAN_EXCEPTION
+ * FILE_ERROR
+ * FILE_NOT_EMAIL
+ * DUPLICATE_MESSAGE_ID
+ * NULL_POINTER
+ * TAG_TOO_LONG
+ * UNBALANCED_FREEZE_THAW
+ * UNBALANCED_ATOMIC
+ * NOT_INITIALIZED
+
+Invoke the class method `notmuch.STATUS.status2str` with a status value as
+argument to receive a human readable string"""
+STATUS.__name__ = 'STATUS'
+
+
+class NotmuchError(Exception, Python3StringMixIn):
+ """Is initiated with a (notmuch.STATUS[, message=None]). It will not
+ return an instance of the class NotmuchError, but a derived instance
+ of a more specific Error Message, e.g. OutOfMemoryError. Each status
+ but SUCCESS has a corresponding subclassed Exception."""
+
+ @classmethod
+ def get_exc_subclass(cls, status):
+ """Returns a fine grained Exception() type,
+ detailing the error status"""
+ subclasses = {
+ STATUS.OUT_OF_MEMORY: OutOfMemoryError,
+ STATUS.READ_ONLY_DATABASE: ReadOnlyDatabaseError,
+ STATUS.XAPIAN_EXCEPTION: XapianError,
+ STATUS.FILE_ERROR: FileError,
+ STATUS.FILE_NOT_EMAIL: FileNotEmailError,
+ STATUS.DUPLICATE_MESSAGE_ID: DuplicateMessageIdError,
+ STATUS.NULL_POINTER: NullPointerError,
+ STATUS.TAG_TOO_LONG: TagTooLongError,
+ STATUS.UNBALANCED_FREEZE_THAW: UnbalancedFreezeThawError,
+ STATUS.UNBALANCED_ATOMIC: UnbalancedAtomicError,
+ STATUS.NOT_INITIALIZED: NotInitializedError,
+ }
+ assert 0 < status <= len(subclasses)
+ return subclasses[status]
+
+ def __new__(cls, *args, **kwargs):
+ """Return a correct subclass of NotmuchError if needed
+
+ We return a NotmuchError instance if status is None (or 0) and a
+ subclass that inherits from NotmuchError depending on the
+ 'status' parameter otherwise."""
+ # get 'status'. Passed in as arg or kwarg?
+ status = args[0] if len(args) else kwargs.get('status', None)
+ # no 'status' or cls is subclass already, return 'cls' instance
+ if not status or cls != NotmuchError:
+ return super(NotmuchError, cls).__new__(cls)
+ subclass = cls.get_exc_subclass(status) # which class to use?
+ return subclass.__new__(subclass, *args, **kwargs)
+
+ def __init__(self, status=None, message=None):
+ self.status = status
+ self.message = message
+
+ def __unicode__(self):
+ if self.message is not None:
+ return self.message
+ elif self.status is not None:
+ return STATUS.status2str(self.status)
+ else:
+ return 'Unknown error'
+
+
+# List of Subclassed exceptions that correspond to STATUS values and are
+# subclasses of NotmuchError.
+class OutOfMemoryError(NotmuchError):
+ status = STATUS.OUT_OF_MEMORY
+
+
+class ReadOnlyDatabaseError(NotmuchError):
+ status = STATUS.READ_ONLY_DATABASE
+
+
+class XapianError(NotmuchError):
+ status = STATUS.XAPIAN_EXCEPTION
+
+
+class FileError(NotmuchError):
+ status = STATUS.FILE_ERROR
+
+
+class FileNotEmailError(NotmuchError):
+ status = STATUS.FILE_NOT_EMAIL
+
+
+class DuplicateMessageIdError(NotmuchError):
+ status = STATUS.DUPLICATE_MESSAGE_ID
+
+
+class NullPointerError(NotmuchError):
+ status = STATUS.NULL_POINTER
+
+
+class TagTooLongError(NotmuchError):
+ status = STATUS.TAG_TOO_LONG
+
+
+class UnbalancedFreezeThawError(NotmuchError):
+ status = STATUS.UNBALANCED_FREEZE_THAW
+
+
+class UnbalancedAtomicError(NotmuchError):
+ status = STATUS.UNBALANCED_ATOMIC
+
+
+class NotInitializedError(NotmuchError):
+ """Derived from NotmuchError, this occurs if the underlying data
+ structure (e.g. database is not initialized (yet) or an iterator has
+ been exhausted. You can test for NotmuchError with .status =
+ STATUS.NOT_INITIALIZED"""
+ status = STATUS.NOT_INITIALIZED
diff --git a/bindings/python/notmuch/filenames.py b/bindings/python/notmuch/filenames.py
index 232a9ed..12050df 100644
--- a/bindings/python/notmuch/filenames.py
+++ b/bindings/python/notmuch/filenames.py
@@ -19,12 +19,14 @@ Copyright 2010 Sebastian Spaeth '
from ctypes import c_char_p
from notmuch.globals import (
nmlib,
- NullPointerError,
- NotInitializedError,
NotmuchMessageP,
NotmuchFilenamesP,
Python3StringMixIn,
)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
class Filenames(Python3StringMixIn):
diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
index 4138460..442f3e3 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -17,7 +17,7 @@ along with notmuch. If not, see .
Copyright 2010 Sebastian Spaeth '
"""
import sys
-from ctypes import CDLL, c_char_p, c_int, Structure, POINTER
+from ctypes import CDLL, Structure, POINTER
#-----------------------------------------------------------------------------
#package-global instance of the notmuch library
@@ -66,164 +66,6 @@ class Enum(object):
setattr(self, name, number)
-class Status(Enum):
- """Enum with a string representation of a notmuch_status_t value."""
- _status2str = nmlib.notmuch_status_to_string
- _status2str.restype = c_char_p
- _status2str.argtypes = [c_int]
-
- def __init__(self, statuslist):
- """It is initialized with a list of strings that are available as
- Status().string1 - Status().stringn attributes.
- """
- super(Status, self).__init__(statuslist)
-
- @classmethod
- def status2str(self, status):
- """Get a (unicode) string representation of a notmuch_status_t value."""
- # define strings for custom error messages
- if status == STATUS.NOT_INITIALIZED:
- return "Operation on uninitialized object impossible."
- return unicode(Status._status2str(status))
-
-STATUS = Status(['SUCCESS',
- 'OUT_OF_MEMORY',
- 'READ_ONLY_DATABASE',
- 'XAPIAN_EXCEPTION',
- 'FILE_ERROR',
- 'FILE_NOT_EMAIL',
- 'DUPLICATE_MESSAGE_ID',
- 'NULL_POINTER',
- 'TAG_TOO_LONG',
- 'UNBALANCED_FREEZE_THAW',
- 'UNBALANCED_ATOMIC',
- 'NOT_INITIALIZED'])
-"""STATUS is a class, whose attributes provide constants that serve as return
-indicators for notmuch functions. Currently the following ones are defined. For
-possible return values and specific meaning for each method, see the method
-description.
-
- * SUCCESS
- * OUT_OF_MEMORY
- * READ_ONLY_DATABASE
- * XAPIAN_EXCEPTION
- * FILE_ERROR
- * FILE_NOT_EMAIL
- * DUPLICATE_MESSAGE_ID
- * NULL_POINTER
- * TAG_TOO_LONG
- * UNBALANCED_FREEZE_THAW
- * UNBALANCED_ATOMIC
- * NOT_INITIALIZED
-
-Invoke the class method `notmuch.STATUS.status2str` with a status value as
-argument to receive a human readable string"""
-STATUS.__name__ = 'STATUS'
-
-
-class NotmuchError(Exception, Python3StringMixIn):
- """Is initiated with a (notmuch.STATUS[, message=None]). It will not
- return an instance of the class NotmuchError, but a derived instance
- of a more specific Error Message, e.g. OutOfMemoryError. Each status
- but SUCCESS has a corresponding subclassed Exception."""
-
- @classmethod
- def get_exc_subclass(cls, status):
- """Returns a fine grained Exception() type,
- detailing the error status"""
- subclasses = {
- STATUS.OUT_OF_MEMORY: OutOfMemoryError,
- STATUS.READ_ONLY_DATABASE: ReadOnlyDatabaseError,
- STATUS.XAPIAN_EXCEPTION: XapianError,
- STATUS.FILE_ERROR: FileError,
- STATUS.FILE_NOT_EMAIL: FileNotEmailError,
- STATUS.DUPLICATE_MESSAGE_ID: DuplicateMessageIdError,
- STATUS.NULL_POINTER: NullPointerError,
- STATUS.TAG_TOO_LONG: TagTooLongError,
- STATUS.UNBALANCED_FREEZE_THAW: UnbalancedFreezeThawError,
- STATUS.UNBALANCED_ATOMIC: UnbalancedAtomicError,
- STATUS.NOT_INITIALIZED: NotInitializedError,
- }
- assert 0 < status <= len(subclasses)
- return subclasses[status]
-
- def __new__(cls, *args, **kwargs):
- """Return a correct subclass of NotmuchError if needed
-
- We return a NotmuchError instance if status is None (or 0) and a
- subclass that inherits from NotmuchError depending on the
- 'status' parameter otherwise."""
- # get 'status'. Passed in as arg or kwarg?
- status = args[0] if len(args) else kwargs.get('status', None)
- # no 'status' or cls is subclass already, return 'cls' instance
- if not status or cls != NotmuchError:
- return super(NotmuchError, cls).__new__(cls)
- subclass = cls.get_exc_subclass(status) # which class to use?
- return subclass.__new__(subclass, *args, **kwargs)
-
- def __init__(self, status=None, message=None):
- self.status = status
- self.message = message
-
- def __unicode__(self):
- if self.message is not None:
- return self.message
- elif self.status is not None:
- return STATUS.status2str(self.status)
- else:
- return 'Unknown error'
-
-
-# List of Subclassed exceptions that correspond to STATUS values and are
-# subclasses of NotmuchError.
-class OutOfMemoryError(NotmuchError):
- status = STATUS.OUT_OF_MEMORY
-
-
-class ReadOnlyDatabaseError(NotmuchError):
- status = STATUS.READ_ONLY_DATABASE
-
-
-class XapianError(NotmuchError):
- status = STATUS.XAPIAN_EXCEPTION
-
-
-class FileError(NotmuchError):
- status = STATUS.FILE_ERROR
-
-
-class FileNotEmailError(NotmuchError):
- status = STATUS.FILE_NOT_EMAIL
-
-
-class DuplicateMessageIdError(NotmuchError):
- status = STATUS.DUPLICATE_MESSAGE_ID
-
-
-class NullPointerError(NotmuchError):
- status = STATUS.NULL_POINTER
-
-
-class TagTooLongError(NotmuchError):
- status = STATUS.TAG_TOO_LONG
-
-
-class UnbalancedFreezeThawError(NotmuchError):
- status = STATUS.UNBALANCED_FREEZE_THAW
-
-
-class UnbalancedAtomicError(NotmuchError):
- status = STATUS.UNBALANCED_ATOMIC
-
-
-class NotInitializedError(NotmuchError):
- """Derived from NotmuchError, this occurs if the underlying data
- structure (e.g. database is not initialized (yet) or an iterator has
- been exhausted. You can test for NotmuchError with .status =
- STATUS.NOT_INITIALIZED"""
- status = STATUS.NOT_INITIALIZED
-
-
class NotmuchDatabaseS(Structure):
pass
NotmuchDatabaseP = POINTER(NotmuchDatabaseS)
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index d17b9bc..9eb4fee 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -26,15 +26,17 @@ from .globals import (
Enum,
_str,
Python3StringMixIn,
- STATUS,
- NotmuchError,
- NullPointerError,
- NotInitializedError,
NotmuchTagsP,
NotmuchMessageP,
NotmuchMessagesP,
NotmuchFilenamesP,
)
+from .errors import (
+ STATUS,
+ NotmuchError,
+ NullPointerError,
+ NotInitializedError,
+)
from .tag import Tags
from .filenames import Filenames
diff --git a/bindings/python/notmuch/messages.py b/bindings/python/notmuch/messages.py
index 20d3632..d94f91b 100644
--- a/bindings/python/notmuch/messages.py
+++ b/bindings/python/notmuch/messages.py
@@ -20,12 +20,14 @@ Copyright 2010 Sebastian Spaeth '
from .globals import (
nmlib,
- NullPointerError,
- NotInitializedError,
NotmuchTagsP,
NotmuchMessageP,
NotmuchMessagesP,
)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
from .tag import Tags
from .message import Message
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index fcd67e5..ddaf8e0 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -26,6 +26,8 @@ from notmuch.globals import (
NotmuchThreadsP,
NotmuchDatabaseP,
NotmuchMessagesP,
+)
+from .errors import (
NullPointerError,
NotInitializedError,
)
diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
index 526e51c..711bf53 100644
--- a/bindings/python/notmuch/tag.py
+++ b/bindings/python/notmuch/tag.py
@@ -20,9 +20,11 @@ from ctypes import c_char_p
from notmuch.globals import (
nmlib,
Python3StringMixIn,
+ NotmuchTagsP,
+)
+from .errors import (
NullPointerError,
NotInitializedError,
- NotmuchTagsP,
)
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index 0dac522..a759c90 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -20,12 +20,14 @@ Copyright 2010 Sebastian Spaeth '
from ctypes import c_char_p, c_long, c_int
from notmuch.globals import (
nmlib,
- NullPointerError,
- NotInitializedError,
NotmuchThreadP,
NotmuchMessagesP,
NotmuchTagsP,
)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
from .messages import Messages
from notmuch.tag import Tags
from datetime import date
diff --git a/bindings/python/notmuch/threads.py b/bindings/python/notmuch/threads.py
index 9d305e2..690206e 100644
--- a/bindings/python/notmuch/threads.py
+++ b/bindings/python/notmuch/threads.py
@@ -20,11 +20,13 @@ Copyright 2010 Sebastian Spaeth '
from notmuch.globals import (
nmlib,
Python3StringMixIn,
- NullPointerError,
- NotInitializedError,
NotmuchThreadP,
NotmuchThreadsP,
)
+from .errors import (
+ NullPointerError,
+ NotInitializedError,
+)
from .thread import Thread
class Threads(Python3StringMixIn):
--
cgit v1.2.3
From 1f08664a6b8f7cba63f63855833f877b66bbbe05 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Sun, 29 Apr 2012 16:33:06 +0200
Subject: python: strip superfluous single quote from copyright notices
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/database.py | 2 +-
bindings/python/notmuch/directory.py | 2 +-
bindings/python/notmuch/filenames.py | 2 +-
bindings/python/notmuch/globals.py | 2 +-
bindings/python/notmuch/message.py | 2 +-
bindings/python/notmuch/messages.py | 2 +-
bindings/python/notmuch/query.py | 2 +-
bindings/python/notmuch/tag.py | 2 +-
bindings/python/notmuch/thread.py | 2 +-
bindings/python/notmuch/threads.py | 2 +-
10 files changed, 10 insertions(+), 10 deletions(-)
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 268e952..0ac8b06 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
import os
diff --git a/bindings/python/notmuch/directory.py b/bindings/python/notmuch/directory.py
index 284cbdc..667d3a4 100644
--- a/bindings/python/notmuch/directory.py
+++ b/bindings/python/notmuch/directory.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_uint, c_long
diff --git a/bindings/python/notmuch/filenames.py b/bindings/python/notmuch/filenames.py
index 12050df..f3d761d 100644
--- a/bindings/python/notmuch/filenames.py
+++ b/bindings/python/notmuch/filenames.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_char_p
from notmuch.globals import (
diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
index 442f3e3..823c3e2 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
import sys
from ctypes import CDLL, Structure, POINTER
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index 9eb4fee..f1faf1d 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
Jesse Rosenthal
"""
diff --git a/bindings/python/notmuch/messages.py b/bindings/python/notmuch/messages.py
index d94f91b..6b024cb 100644
--- a/bindings/python/notmuch/messages.py
+++ b/bindings/python/notmuch/messages.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
Jesse Rosenthal
"""
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index ddaf8e0..27bc4df 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_char_p, c_uint
diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
index 711bf53..9b18160 100644
--- a/bindings/python/notmuch/tag.py
+++ b/bindings/python/notmuch/tag.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_char_p
from notmuch.globals import (
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index a759c90..a47b209 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_char_p, c_long, c_int
diff --git a/bindings/python/notmuch/threads.py b/bindings/python/notmuch/threads.py
index 225f524..fb053f9 100644
--- a/bindings/python/notmuch/threads.py
+++ b/bindings/python/notmuch/threads.py
@@ -14,7 +14,7 @@ for more details.
You should have received a copy of the GNU General Public License
along with notmuch. If not, see .
-Copyright 2010 Sebastian Spaeth '
+Copyright 2010 Sebastian Spaeth
"""
from notmuch.globals import (
--
cgit v1.2.3
From 162687a99e412098729d639ed7bc27f01372cb84 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Mon, 30 Apr 2012 18:52:35 +0200
Subject: python: fix NULL pointer tests
Fix the NULL pointer tests in the destructors of all classes and
Database.create.
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/database.py | 2 +-
bindings/python/notmuch/directory.py | 2 +-
bindings/python/notmuch/filenames.py | 2 +-
bindings/python/notmuch/message.py | 2 +-
bindings/python/notmuch/messages.py | 2 +-
bindings/python/notmuch/query.py | 2 +-
bindings/python/notmuch/tag.py | 2 +-
bindings/python/notmuch/thread.py | 2 +-
bindings/python/notmuch/threads.py | 2 +-
9 files changed, 9 insertions(+), 9 deletions(-)
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 0ac8b06..525f7c9 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -189,7 +189,7 @@ class Database(object):
:raises: :exc:`NotmuchError` in case of any failure
(possibly after printing an error message on stderr).
"""
- if self._db is not None:
+ if self._db:
raise NotmuchError(message="Cannot create db, this Database() "
"already has an open one.")
diff --git a/bindings/python/notmuch/directory.py b/bindings/python/notmuch/directory.py
index 667d3a4..ae115f8 100644
--- a/bindings/python/notmuch/directory.py
+++ b/bindings/python/notmuch/directory.py
@@ -181,5 +181,5 @@ class Directory(object):
def __del__(self):
"""Close and free the Directory"""
- if self._dir_p is not None:
+ if self._dir_p:
self._destroy(self._dir_p)
diff --git a/bindings/python/notmuch/filenames.py b/bindings/python/notmuch/filenames.py
index d201ae2..a0b2956 100644
--- a/bindings/python/notmuch/filenames.py
+++ b/bindings/python/notmuch/filenames.py
@@ -128,7 +128,7 @@ class Filenames(Python3StringMixIn):
def __del__(self):
"""Close and free the notmuch filenames"""
- if self._files_p is not None:
+ if self._files_p:
self._destroy(self._files_p)
def __len__(self):
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index 54c4e4b..4ec5147 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -741,5 +741,5 @@ class Message(Python3StringMixIn):
def __del__(self):
"""Close and free the notmuch Message"""
- if self._msg is not None:
+ if self._msg:
self._destroy(self._msg)
diff --git a/bindings/python/notmuch/messages.py b/bindings/python/notmuch/messages.py
index 6b024cb..251fa3a 100644
--- a/bindings/python/notmuch/messages.py
+++ b/bindings/python/notmuch/messages.py
@@ -184,7 +184,7 @@ class Messages(object):
def __del__(self):
"""Close and free the notmuch Messages"""
- if self._msgs is not None:
+ if self._msgs:
self._destroy(self._msgs)
def format_messages(self, format, indent=0, entire_thread=False):
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index 27bc4df..756e63b 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -203,5 +203,5 @@ class Query(object):
def __del__(self):
"""Close and free the Query"""
- if self._query is not None:
+ if self._query:
self._destroy(self._query)
diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
index 9b18160..e059813 100644
--- a/bindings/python/notmuch/tag.py
+++ b/bindings/python/notmuch/tag.py
@@ -137,5 +137,5 @@ class Tags(Python3StringMixIn):
def __del__(self):
"""Close and free the notmuch tags"""
- if self._tags is not None:
+ if self._tags:
self._destroy(self._tags)
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index a47b209..2f60d49 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -260,5 +260,5 @@ class Thread(object):
def __del__(self):
"""Close and free the notmuch Thread"""
- if self._thread is not None:
+ if self._thread:
self._destroy(self._thread)
diff --git a/bindings/python/notmuch/threads.py b/bindings/python/notmuch/threads.py
index fb053f9..a644164 100644
--- a/bindings/python/notmuch/threads.py
+++ b/bindings/python/notmuch/threads.py
@@ -176,5 +176,5 @@ class Threads(Python3StringMixIn):
def __del__(self):
"""Close and free the notmuch Threads"""
- if self._threads is not None:
+ if self._threads:
self._destroy(self._threads)
--
cgit v1.2.3
From 05c3e83bd272635ecc5e86d767250de1eb680a09 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Thu, 17 May 2012 16:58:53 +0200
Subject: python: use relative imports
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/database.py | 6 +++---
bindings/python/notmuch/directory.py | 2 +-
bindings/python/notmuch/filenames.py | 2 +-
bindings/python/notmuch/query.py | 2 +-
bindings/python/notmuch/tag.py | 2 +-
bindings/python/notmuch/thread.py | 4 ++--
bindings/python/notmuch/threads.py | 2 +-
7 files changed, 10 insertions(+), 10 deletions(-)
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 797554d..fb4c929 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -20,7 +20,7 @@ Copyright 2010 Sebastian Spaeth
import os
import codecs
from ctypes import c_char_p, c_void_p, c_uint, byref, POINTER
-from notmuch.globals import (
+from .globals import (
nmlib,
Enum,
_str,
@@ -37,8 +37,8 @@ from .errors import (
NotInitializedError,
ReadOnlyDatabaseError,
)
-from notmuch.message import Message
-from notmuch.tag import Tags
+from .message import Message
+from .tag import Tags
from .query import Query
from .directory import Directory
diff --git a/bindings/python/notmuch/directory.py b/bindings/python/notmuch/directory.py
index ae115f8..3b0a525 100644
--- a/bindings/python/notmuch/directory.py
+++ b/bindings/python/notmuch/directory.py
@@ -18,7 +18,7 @@ Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_uint, c_long
-from notmuch.globals import (
+from .globals import (
nmlib,
NotmuchDirectoryP,
NotmuchFilenamesP
diff --git a/bindings/python/notmuch/filenames.py b/bindings/python/notmuch/filenames.py
index a0b2956..229f414 100644
--- a/bindings/python/notmuch/filenames.py
+++ b/bindings/python/notmuch/filenames.py
@@ -17,7 +17,7 @@ along with notmuch. If not, see .
Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_char_p
-from notmuch.globals import (
+from .globals import (
nmlib,
NotmuchMessageP,
NotmuchFilenamesP,
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index 756e63b..4abba5b 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -18,7 +18,7 @@ Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_char_p, c_uint
-from notmuch.globals import (
+from .globals import (
nmlib,
Enum,
_str,
diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
index 363c348..1d52345 100644
--- a/bindings/python/notmuch/tag.py
+++ b/bindings/python/notmuch/tag.py
@@ -17,7 +17,7 @@ along with notmuch. If not, see .
Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_char_p
-from notmuch.globals import (
+from .globals import (
nmlib,
Python3StringMixIn,
NotmuchTagsP,
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index 2f60d49..789f9a0 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -18,7 +18,7 @@ Copyright 2010 Sebastian Spaeth
"""
from ctypes import c_char_p, c_long, c_int
-from notmuch.globals import (
+from .globals import (
nmlib,
NotmuchThreadP,
NotmuchMessagesP,
@@ -29,7 +29,7 @@ from .errors import (
NotInitializedError,
)
from .messages import Messages
-from notmuch.tag import Tags
+from .tag import Tags
from datetime import date
class Thread(object):
diff --git a/bindings/python/notmuch/threads.py b/bindings/python/notmuch/threads.py
index d2e0a91..f8ca34a 100644
--- a/bindings/python/notmuch/threads.py
+++ b/bindings/python/notmuch/threads.py
@@ -17,7 +17,7 @@ along with notmuch. If not, see .
Copyright 2010 Sebastian Spaeth
"""
-from notmuch.globals import (
+from .globals import (
nmlib,
Python3StringMixIn,
NotmuchThreadP,
--
cgit v1.2.3
From 8dc8495010057202b725ac029831c03f4e3ab6bd Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Thu, 17 May 2012 17:15:24 +0200
Subject: python: Fix the remaining broken NULL pointer tests
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
bindings/python/notmuch/database.py | 2 +-
bindings/python/notmuch/message.py | 4 ++--
bindings/python/notmuch/messages.py | 2 +-
bindings/python/notmuch/thread.py | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
(limited to 'bindings/python/notmuch/thread.py')
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index fb4c929..8f1b37f 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -558,7 +558,7 @@ class Database(object):
"""
self._assert_db_is_initialized()
tags_p = Database._get_all_tags(self._db)
- if tags_p == None:
+ if not tags_p:
raise NullPointerError()
return Tags(tags_p, self)
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index bdbe501..d7f029f 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -229,7 +229,7 @@ class Message(Python3StringMixIn):
#Returns NULL if any error occurs.
header = Message._get_header(self._msg, _str(header))
- if header == None:
+ if not header:
raise NullPointerError()
return header.decode('UTF-8', 'ignore')
@@ -300,7 +300,7 @@ class Message(Python3StringMixIn):
raise NotInitializedError()
tags_p = Message._get_tags(self._msg)
- if tags_p == None:
+ if not tags_p:
raise NullPointerError()
return Tags(tags_p, self)
diff --git a/bindings/python/notmuch/messages.py b/bindings/python/notmuch/messages.py
index 59ef40a..aee4a77 100644
--- a/bindings/python/notmuch/messages.py
+++ b/bindings/python/notmuch/messages.py
@@ -142,7 +142,7 @@ class Messages(object):
#reset _msgs as we iterated over it and can do so only once
self._msgs = None
- if tags_p == None:
+ if not tags_p:
raise NullPointerError()
return Tags(tags_p, self)
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index 789f9a0..009cb2b 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -238,7 +238,7 @@ class Thread(object):
raise NotInitializedError()
tags_p = Thread._get_tags(self._thread)
- if tags_p == None:
+ if not tags_p:
raise NullPointerError()
return Tags(tags_p, self)
--
cgit v1.2.3