Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 39 / 3a1b08ebe0fa5520071934774b64feb047355e
1 Return-Path: <teythoon@jade-hamburg.de>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 27432429E21\r
6         for <notmuch@notmuchmail.org>; Sun, 25 Sep 2011 18:06:42 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id bL8CmSzLNKQ3 for <notmuch@notmuchmail.org>;\r
16         Sun, 25 Sep 2011 18:06:41 -0700 (PDT)\r
17 Received: from mail.cryptobitch.de (cryptobitch.de [88.198.7.68])\r
18         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 4B663431FD0\r
21         for <notmuch@notmuchmail.org>; Sun, 25 Sep 2011 18:06:41 -0700 (PDT)\r
22 Received: from mail.jade-hamburg.de (unknown [85.183.11.228])\r
23         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
24         (No client certificate requested)\r
25         by mail.cryptobitch.de (Postfix) with ESMTPSA id 1A61A505B24\r
26         for <notmuch@notmuchmail.org>; Mon, 26 Sep 2011 03:06:40 +0200 (CEST)\r
27 Received: by mail.jade-hamburg.de (Postfix, from userid 401)\r
28         id 91800DF2A1; Mon, 26 Sep 2011 03:06:39 +0200 (CEST)\r
29 Received: from thinkbox.jade-hamburg.de (unknown [10.1.1.109])\r
30         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
31         (No client certificate requested) (Authenticated sender: teythoon)\r
32         by mail.jade-hamburg.de (Postfix) with ESMTPSA id 71B71DF2A3;\r
33         Mon, 26 Sep 2011 03:06:14 +0200 (CEST)\r
34 Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.76)\r
35         (envelope-from <teythoon@thinkbox.jade-hamburg.de>)\r
36         id 1R7ze5-0007OV-Lt; Mon, 26 Sep 2011 03:06:09 +0200\r
37 From: Justus Winter <4winter@informatik.uni-hamburg.de>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 7/9] python: provide more exception classes\r
40 Date: Mon, 26 Sep 2011 03:05:35 +0200\r
41 Message-Id:\r
42  <1316999137-28257-7-git-send-email-4winter@informatik.uni-hamburg.de>\r
43 X-Mailer: git-send-email 1.7.6.3\r
44 In-Reply-To:\r
45  <1316999137-28257-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
46 References:\r
47  <1316999137-28257-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
48 X-Mailman-Approved-At: Mon, 26 Sep 2011 09:17:56 -0700\r
49 Cc: Justus Winter <4winter@informatik.uni-hamburg.de>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Mon, 26 Sep 2011 01:06:42 -0000\r
63 \r
64 To make the exception handling more effective in code using the\r
65 python bindings it is necessary to differentiate between the\r
66 different kind of failures.\r
67 \r
68 Add an exception class for each status code and add a decode\r
69 classmethod to the NotmuchError class that acts as a factory.\r
70 \r
71 Import the new classes in __init__.py so they can be easily\r
72 imported by anyone.\r
73 \r
74 Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>\r
75 ---\r
76  bindings/python/notmuch/__init__.py |   16 ++++++++++++++-\r
77  bindings/python/notmuch/globals.py  |   37 +++++++++++++++++++++++++++++++++++\r
78  2 files changed, 52 insertions(+), 1 deletions(-)\r
79 \r
80 diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/__init__.py\r
81 index a7b558f..7e6a68c 100644\r
82 --- a/bindings/python/notmuch/__init__.py\r
83 +++ b/bindings/python/notmuch/__init__.py\r
84 @@ -56,7 +56,21 @@ from notmuch.database import Database, Query\r
85  from notmuch.message import Messages, Message\r
86  from notmuch.thread import Threads, Thread\r
87  from notmuch.tag import Tags\r
88 -from notmuch.globals import nmlib, STATUS, NotmuchError\r
89 +from notmuch.globals import (\r
90 +    nmlib,\r
91 +    STATUS,\r
92 +    NotmuchError,\r
93 +    OutOfMemoryError,\r
94 +    ReadOnlyDatabaseError,\r
95 +    XapianError,\r
96 +    FileError,\r
97 +    FileNotEmailError,\r
98 +    DuplicateMessageIdError,\r
99 +    NullPointerError,\r
100 +    TagTooLongError,\r
101 +    UnbalancedFreezeThawError,\r
102 +    NotInitializedError\r
103 +)\r
104  from notmuch.version import __VERSION__\r
105  __LICENSE__ = "GPL v3+"\r
106  __AUTHOR__ = 'Sebastian Spaeth <Sebastian@SSpaeth.de>'\r
107 diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py\r
108 index 8b73f91..e454384 100644\r
109 --- a/bindings/python/notmuch/globals.py\r
110 +++ b/bindings/python/notmuch/globals.py\r
111 @@ -102,6 +102,43 @@ class NotmuchError(Exception):\r
112          else:\r
113              return 'Unknown error'\r
114  \r
115 +    @classmethod\r
116 +    def decode(cls, status, message=None):\r
117 +        assert 0 < status <= 10\r
118 +        return [\r
119 +            OutOfMemoryError,\r
120 +            ReadOnlyDatabaseError,\r
121 +            XapianError,\r
122 +            FileError,\r
123 +            FileNotEmailError,\r
124 +            DuplicateMessageIdError,\r
125 +            NullPointerError,\r
126 +            TagTooLongError,\r
127 +            UnbalancedFreezeThawError,\r
128 +            NotInitializedError\r
129 +        ][status - 1](message)\r
130 +\r
131 +class OutOfMemoryError(NotmuchError):\r
132 +    status = 1\r
133 +class ReadOnlyDatabaseError(NotmuchError):\r
134 +    status = 2\r
135 +class XapianError(NotmuchError):\r
136 +    status = 3\r
137 +class FileError(NotmuchError):\r
138 +    status = 4\r
139 +class FileNotEmailError(NotmuchError):\r
140 +    status = 5\r
141 +class DuplicateMessageIdError(NotmuchError):\r
142 +    status = 6\r
143 +class NullPointerError(NotmuchError):\r
144 +    status = 7\r
145 +class TagTooLongError(NotmuchError):\r
146 +    status = 8\r
147 +class UnbalancedFreezeThawError(NotmuchError):\r
148 +    status = 9\r
149 +class NotInitializedError(NotmuchError):\r
150 +    status = 10\r
151 +\r
152  def _str(value):\r
153      """Ensure a nicely utf-8 encoded string to pass to libnotmuch\r
154  \r
155 -- \r
156 1.7.6.3\r
157 \r