[PATCH 3/9] python: reorder the arguments of NotmuchError.__init__()
Justus Winter
4winter at informatik.uni-hamburg.de
Sun Sep 25 18:05:31 PDT 2011
It is customary for subclasses of Exception to take a string as
the first argument that describes the problem.
Signed-off-by: Justus Winter <4winter at informatik.uni-hamburg.de>
---
bindings/python/notmuch/database.py | 48 ++++++++++++++--------------
bindings/python/notmuch/filename.py | 4 +-
bindings/python/notmuch/globals.py | 6 ++--
bindings/python/notmuch/message.py | 58 +++++++++++++++++-----------------
bindings/python/notmuch/tag.py | 4 +-
bindings/python/notmuch/thread.py | 32 +++++++++---------
6 files changed, 76 insertions(+), 76 deletions(-)
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index a462789..e174f55 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -108,7 +108,7 @@ class Database(object):
def _verify_initialized_db(self):
"""Raises a NotmuchError in case self._db is still None"""
if self._db is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
def create(self, path):
"""Creates a new notmuch database
@@ -247,9 +247,9 @@ 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 NotmuchError(message="Database().get_directory() called "
+ "with a wrong absolute path.",
+ status=STATUS.FILE_ERROR)
abs_dirpath = path
else:
#we got a relative path, make it absolute
@@ -319,7 +319,7 @@ class Database(object):
byref(msg_p))
if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:
- raise NotmuchError(status)
+ raise NotmuchError(status=status)
#construct Message() and return
msg = Message(msg_p, self)
@@ -398,7 +398,7 @@ class Database(object):
tags_p = Database._get_all_tags(self._db)
if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
return Tags(tags_p, self)
def create_query(self, querystring):
@@ -524,13 +524,13 @@ class Query(object):
(too little memory)
"""
if db.db_p is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
# create reference to parent db to keep it alive
self._db = db
# create query, return None if too little mem available
query_p = Query._create(db.db_p, _str(querystr))
if query_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
self._query = query_p
def set_sort(self, sort):
@@ -544,7 +544,7 @@ class Query(object):
been initialized.
"""
if self._query is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
self.sort = sort
nmlib.notmuch_query_set_sort(self._query, sort)
@@ -570,12 +570,12 @@ class Query(object):
* STATUS.NULL_POINTER if search_threads failed
"""
if self._query is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
threads_p = Query._search_threads(self._query)
if threads_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
return Threads(threads_p, self)
@@ -593,12 +593,12 @@ class Query(object):
* STATUS.NULL_POINTER if search_messages failed
"""
if self._query is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
msgs_p = Query._search_messages(self._query)
if msgs_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
return Messages(msgs_p, self)
@@ -618,7 +618,7 @@ class Query(object):
* STATUS.NOT_INITIALIZED if query is not inited
"""
if self._query is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return Query._count_messages(self._query)
@@ -659,9 +659,9 @@ class Directory(object):
_get_child_directories.restype = c_void_p
def _verify_dir_initialized(self):
- """Raises a NotmuchError(STATUS.NOT_INITIALIZED) if dir_p is None"""
+ """Raises a NotmuchError(status=STATUS.NOT_INITIALIZED) if dir_p is None"""
if self._dir_p is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
def __init__(self, path, dir_p, parent):
"""
@@ -713,7 +713,7 @@ class Directory(object):
STATUS.NOT_INITIALIZED
The directory has not been initialized
"""
- #Raise a NotmuchError(STATUS.NOT_INITIALIZED) if the dir_p is None
+ #Raise a NotmuchError(status=STATUS.NOT_INITIALIZED) if the dir_p is None
self._verify_dir_initialized()
#TODO: make sure, we convert the mtime parameter to a 'c_long'
@@ -723,7 +723,7 @@ class Directory(object):
if status == STATUS.SUCCESS:
return
#fail with Exception otherwise
- raise NotmuchError(status)
+ raise NotmuchError(status=status)
def get_mtime(self):
"""Gets the mtime value of this directory in the database
@@ -737,7 +737,7 @@ class Directory(object):
STATUS.NOT_INITIALIZED
The directory has not been initialized
"""
- #Raise a NotmuchError(STATUS.NOT_INITIALIZED) if self.dir_p is None
+ #Raise a NotmuchError(status=STATUS.NOT_INITIALIZED) if self.dir_p is None
self._verify_dir_initialized()
return Directory._get_mtime(self._dir_p)
@@ -756,7 +756,7 @@ class Directory(object):
The returned filenames will be the basename-entries only (not
complete paths.
"""
- #Raise a NotmuchError(STATUS.NOT_INITIALIZED) if self._dir_p is None
+ #Raise a NotmuchError(status=STATUS.NOT_INITIALIZED) if self._dir_p is None
self._verify_dir_initialized()
files_p = Directory._get_child_files(self._dir_p)
@@ -769,7 +769,7 @@ class Directory(object):
The returned filenames will be the basename-entries only (not
complete paths.
"""
- #Raise a NotmuchError(STATUS.NOT_INITIALIZED) if self._dir_p is None
+ #Raise a NotmuchError(status=STATUS.NOT_INITIALIZED) if self._dir_p is None
self._verify_dir_initialized()
files_p = Directory._get_child_directories(self._dir_p)
@@ -815,7 +815,7 @@ class Filenames(object):
def next(self):
if self._files_p is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
if not nmlib.notmuch_filenames_valid(self._files_p):
self._files_p = None
@@ -834,11 +834,11 @@ class Filenames(object):
#THIS FAILS
files = Database().get_directory('').get_child_files()
if len(files) > 0: #this 'exhausts' msgs
- # next line raises NotmuchError(STATUS.NOT_INITIALIZED)!!!
+ # next line raises NotmuchError(status=STATUS.NOT_INITIALIZED)!!!
for file in files: print file
"""
if self._files_p is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
i = 0
while nmlib.notmuch_filenames_valid(self._files_p):
diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py
index a16e717..c5dfd94 100644
--- a/bindings/python/notmuch/filename.py
+++ b/bindings/python/notmuch/filename.py
@@ -68,7 +68,7 @@ class Filenames(object):
once all derived objects are dead.
"""
if files_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
self._files = files_p
#save reference to parent object so we keep it alive
@@ -80,7 +80,7 @@ class Filenames(object):
This is the main function that will usually be used by the
user."""
if self._files is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
if not nmlib.notmuch_filenames_valid(self._files):
self._files = None
diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
index 779ba5f..dd0c858 100644
--- a/bindings/python/notmuch/globals.py
+++ b/bindings/python/notmuch/globals.py
@@ -89,10 +89,10 @@ STATUS.__name__ = 'STATUS'
class NotmuchError(Exception):
- def __init__(self, status=None, message=None):
- """Is initiated with a (notmuch.STATUS[,message=None])"""
- self.status = status
+ def __init__(self, message=None, status=None):
+ """Is initiated with a (message=None[,status=notmuch.STATUS])"""
self.message = message
+ self.status = status
def __str__(self):
if self.message is not None:
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index a48900c..5cc3175 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -115,7 +115,7 @@ class Messages(object):
the Python object.(?)
"""
if msgs_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
self._msgs = msgs_p
#store parent, so we keep them alive as long as self is alive
@@ -131,7 +131,7 @@ class Messages(object):
therefore will not allow further iterations.
"""
if self._msgs is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
# collect all tags (returns NULL on error)
tags_p = Messages._collect_tags(self._msgs)
@@ -139,7 +139,7 @@ class Messages(object):
self._msgs = None
if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
return Tags(tags_p, self)
def __iter__(self):
@@ -148,7 +148,7 @@ class Messages(object):
def next(self):
if self._msgs is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
if not nmlib.notmuch_messages_valid(self._msgs):
self._msgs = None
@@ -292,7 +292,7 @@ class Message(object):
objects are dead.
"""
if msg_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
self._msg = msg_p
#keep reference to parent, so we keep it alive
self._parent = parent
@@ -305,7 +305,7 @@ class Message(object):
is not initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return Message._get_message_id(self._msg)
def get_thread_id(self):
@@ -322,7 +322,7 @@ class Message(object):
is not initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return Message._get_thread_id(self._msg)
@@ -345,7 +345,7 @@ class Message(object):
is not initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
msgs_p = Message._get_replies(self._msg)
@@ -367,7 +367,7 @@ class Message(object):
is not initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return Message._get_date(self._msg)
def get_header(self, header):
@@ -389,12 +389,12 @@ class Message(object):
* STATUS.NULL_POINTER, if no header was found
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
#Returns NULL if any error occurs.
header = Message._get_header(self._msg, header)
if header == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
return header.decode('UTF-8')
def get_filename(self):
@@ -405,7 +405,7 @@ class Message(object):
is not initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return Message._get_filename(self._msg)
def get_filenames(self):
@@ -415,7 +415,7 @@ class Message(object):
messages recorded to have the same Message-ID. These files must
not necessarily have identical content."""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
files_p = Message._get_filenames(self._msg)
@@ -435,7 +435,7 @@ class Message(object):
is not initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return Message._get_flag(self._msg, flag)
def set_flag(self, flag, value):
@@ -450,7 +450,7 @@ class Message(object):
is not initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
nmlib.notmuch_message_set_flag(self._msg, flag, value)
def get_tags(self):
@@ -464,11 +464,11 @@ class Message(object):
* STATUS.NULL_POINTER, on error
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
tags_p = Message._get_tags(self._msg)
if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
return Tags(tags_p, self)
def add_tag(self, tag, sync_maildir_flags=False):
@@ -503,13 +503,13 @@ class Message(object):
The message has not been initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
status = nmlib.notmuch_message_add_tag(self._msg, _str(tag))
# bail out on failure
if status != STATUS.SUCCESS:
- raise NotmuchError(status)
+ raise NotmuchError(status=status)
if sync_maildir_flags:
self.tags_to_maildir_flags()
@@ -547,12 +547,12 @@ class Message(object):
The message has not been initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
status = nmlib.notmuch_message_remove_tag(self._msg, _str(tag))
# bail out on error
if status != STATUS.SUCCESS:
- raise NotmuchError(status)
+ raise NotmuchError(status=status)
if sync_maildir_flags:
self.tags_to_maildir_flags()
@@ -584,13 +584,13 @@ class Message(object):
The message has not been initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
status = nmlib.notmuch_message_remove_all_tags(self._msg)
# bail out on error
if status != STATUS.SUCCESS:
- raise NotmuchError(status)
+ raise NotmuchError(status=status)
if sync_maildir_flags:
self.tags_to_maildir_flags()
@@ -638,7 +638,7 @@ class Message(object):
The message has not been initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
status = nmlib.notmuch_message_freeze(self._msg)
@@ -646,7 +646,7 @@ class Message(object):
# return on success
return status
- raise NotmuchError(status)
+ raise NotmuchError(status=status)
def thaw(self):
"""Thaws the current 'message'
@@ -673,7 +673,7 @@ class Message(object):
The message has not been initialized.
"""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
status = nmlib.notmuch_message_thaw(self._msg)
@@ -681,7 +681,7 @@ class Message(object):
# return on success
return status
- raise NotmuchError(status)
+ raise NotmuchError(status=status)
def is_match(self):
"""(Not implemented)"""
@@ -709,7 +709,7 @@ class Message(object):
:returns: a :class:`STATUS`. In short, you want to see
notmuch.STATUS.SUCCESS here. See there for details."""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
status = Message._tags_to_maildir_flags(self._msg)
def maildir_flags_to_tags(self):
@@ -736,7 +736,7 @@ class Message(object):
:returns: a :class:`STATUS`. In short, you want to see
notmuch.STATUS.SUCCESS here. See there for details."""
if self._msg is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
status = 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 50e3686..9ca871a 100644
--- a/bindings/python/notmuch/tag.py
+++ b/bindings/python/notmuch/tag.py
@@ -70,7 +70,7 @@ class Tags(object):
cache the tags in the Python object(?)
"""
if tags_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
self._tags = tags_p
#save reference to parent object so we keep it alive
@@ -82,7 +82,7 @@ class Tags(object):
def next(self):
if self._tags is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
if not nmlib.notmuch_tags_valid(self._tags):
self._tags = None
raise StopIteration
diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py
index 5e08eb3..93089d0 100644
--- a/bindings/python/notmuch/thread.py
+++ b/bindings/python/notmuch/thread.py
@@ -95,7 +95,7 @@ class Threads(object):
the Python object.(?)
"""
if threads_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
self._threads = threads_p
#store parent, so we keep them alive as long as self is alive
@@ -107,7 +107,7 @@ class Threads(object):
def next(self):
if self._threads is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
if not nmlib.notmuch_threads_valid(self._threads):
self._threads = None
@@ -126,11 +126,11 @@ class Threads(object):
#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 NotmuchError(status=STATUS.NOT_INITIALIZED)!!!
for thread in threads: print thread
"""
if self._threads is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
i = 0
# returns 'bool'. On out-of-memory it returns None
@@ -206,7 +206,7 @@ class Thread(object):
objects are dead.
"""
if thread_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
self._thread = thread_p
#keep reference to parent, so we keep it alive
self._parent = parent
@@ -222,7 +222,7 @@ class Thread(object):
is not initialized.
"""
if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return Thread._get_thread_id(self._thread)
def get_total_messages(self):
@@ -235,7 +235,7 @@ class Thread(object):
is not initialized.
"""
if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return nmlib.notmuch_thread_get_total_messages(self._thread)
def get_toplevel_messages(self):
@@ -258,12 +258,12 @@ class Thread(object):
* STATUS.NULL_POINTER if search_messages failed
"""
if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
msgs_p = Thread._get_toplevel_messages(self._thread)
if msgs_p is None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
return Messages(msgs_p, self)
@@ -277,7 +277,7 @@ class Thread(object):
is not initialized.
"""
if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return nmlib.notmuch_thread_get_matched_messages(self._thread)
def get_authors(self):
@@ -291,7 +291,7 @@ class Thread(object):
as long as this Thread() is not deleted.
"""
if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
authors = Thread._get_authors(self._thread)
if authors is None:
return None
@@ -304,7 +304,7 @@ class Thread(object):
as long as this Thread() is not deleted.
"""
if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
subject = Thread._get_subject(self._thread)
if subject is None:
return None
@@ -319,7 +319,7 @@ class Thread(object):
is not initialized.
"""
if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return Thread._get_newest_date(self._thread)
def get_oldest_date(self):
@@ -331,7 +331,7 @@ class Thread(object):
is not initialized.
"""
if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
return Thread._get_oldest_date(self._thread)
def get_tags(self):
@@ -354,11 +354,11 @@ class Thread(object):
* STATUS.NULL_POINTER, on error
"""
if self._thread is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(status=STATUS.NOT_INITIALIZED)
tags_p = Thread._get_tags(self._thread)
if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NotmuchError(status=STATUS.NULL_POINTER)
return Tags(tags_p, self)
def __str__(self):
--
1.7.6.3
More information about the notmuch
mailing list