Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 27432429E21 for ; Sun, 25 Sep 2011 18:06:42 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bL8CmSzLNKQ3 for ; Sun, 25 Sep 2011 18:06:41 -0700 (PDT) Received: from mail.cryptobitch.de (cryptobitch.de [88.198.7.68]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 4B663431FD0 for ; Sun, 25 Sep 2011 18:06:41 -0700 (PDT) Received: from mail.jade-hamburg.de (unknown [85.183.11.228]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.cryptobitch.de (Postfix) with ESMTPSA id 1A61A505B24 for ; Mon, 26 Sep 2011 03:06:40 +0200 (CEST) Received: by mail.jade-hamburg.de (Postfix, from userid 401) id 91800DF2A1; Mon, 26 Sep 2011 03:06:39 +0200 (CEST) Received: from thinkbox.jade-hamburg.de (unknown [10.1.1.109]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: teythoon) by mail.jade-hamburg.de (Postfix) with ESMTPSA id 71B71DF2A3; Mon, 26 Sep 2011 03:06:14 +0200 (CEST) Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.76) (envelope-from ) id 1R7ze5-0007OV-Lt; Mon, 26 Sep 2011 03:06:09 +0200 From: Justus Winter <4winter@informatik.uni-hamburg.de> To: notmuch@notmuchmail.org Subject: [PATCH 7/9] python: provide more exception classes Date: Mon, 26 Sep 2011 03:05:35 +0200 Message-Id: <1316999137-28257-7-git-send-email-4winter@informatik.uni-hamburg.de> X-Mailer: git-send-email 1.7.6.3 In-Reply-To: <1316999137-28257-1-git-send-email-4winter@informatik.uni-hamburg.de> References: <1316999137-28257-1-git-send-email-4winter@informatik.uni-hamburg.de> X-Mailman-Approved-At: Mon, 26 Sep 2011 09:17:56 -0700 Cc: Justus Winter <4winter@informatik.uni-hamburg.de> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Sep 2011 01:06:42 -0000 To make the exception handling more effective in code using the python bindings it is necessary to differentiate between the different kind of failures. Add an exception class for each status code and add a decode classmethod to the NotmuchError class that acts as a factory. Import the new classes in __init__.py so they can be easily imported by anyone. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de> --- bindings/python/notmuch/__init__.py | 16 ++++++++++++++- bindings/python/notmuch/globals.py | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletions(-) diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py index a7b558f..7e6a68c 100644 --- a/bindings/python/notmuch/__init__.py +++ b/bindings/python/notmuch/__init__.py @@ -56,7 +56,21 @@ from notmuch.database import Database, Query from notmuch.message import Messages, Message from notmuch.thread import Threads, Thread from notmuch.tag import Tags -from notmuch.globals import nmlib, STATUS, NotmuchError +from notmuch.globals import ( + nmlib, + STATUS, + NotmuchError, + OutOfMemoryError, + ReadOnlyDatabaseError, + XapianError, + FileError, + FileNotEmailError, + DuplicateMessageIdError, + NullPointerError, + TagTooLongError, + UnbalancedFreezeThawError, + NotInitializedError +) from notmuch.version import __VERSION__ __LICENSE__ = "GPL v3+" __AUTHOR__ = 'Sebastian Spaeth ' diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py index 8b73f91..e454384 100644 --- a/bindings/python/notmuch/globals.py +++ b/bindings/python/notmuch/globals.py @@ -102,6 +102,43 @@ class NotmuchError(Exception): else: return 'Unknown error' + @classmethod + def decode(cls, status, message=None): + assert 0 < status <= 10 + return [ + OutOfMemoryError, + ReadOnlyDatabaseError, + XapianError, + FileError, + FileNotEmailError, + DuplicateMessageIdError, + NullPointerError, + TagTooLongError, + UnbalancedFreezeThawError, + NotInitializedError + ][status - 1](message) + +class OutOfMemoryError(NotmuchError): + status = 1 +class ReadOnlyDatabaseError(NotmuchError): + status = 2 +class XapianError(NotmuchError): + status = 3 +class FileError(NotmuchError): + status = 4 +class FileNotEmailError(NotmuchError): + status = 5 +class DuplicateMessageIdError(NotmuchError): + status = 6 +class NullPointerError(NotmuchError): + status = 7 +class TagTooLongError(NotmuchError): + status = 8 +class UnbalancedFreezeThawError(NotmuchError): + status = 9 +class NotInitializedError(NotmuchError): + status = 10 + def _str(value): """Ensure a nicely utf-8 encoded string to pass to libnotmuch -- 1.7.6.3