[PATCH 7/9] python: provide more exception classes

2011-09-30 Thread Justus Winter

Quoting Sebastian Spaeth (2011-09-30 14:00:36)
>On Mon, 26 Sep 2011 03:05:35 +0200, Justus Winter <4winter at 
>informatik.uni-hamburg.de> wrote:
>> To make the exception handling more effective in code using the
>> python bindings it is necessary to differentiate between the
>> different kind of failures.
>
>[master b6a0173] python: provide more exception classes
>
>Hi, I have taken your patch and used it as a template, modifying things
>slightly. I also converted database.py to make use of the new
>subclasses. Documentation will have to follow, but as users can use the
>code, just as they had done before, there is no urgency.
>
>Justus is that what you had in mind?

Yes, very nice. Thanks :)

Justus
-- next part --
A non-text attachment was scrubbed...
Name: .signature
Type: application/octet-stream
Size: 17 bytes
Desc: not available
URL: 



[PATCH 7/9] python: provide more exception classes

2011-09-30 Thread Sebastian Spaeth
On Mon, 26 Sep 2011 03:05:35 +0200, Justus Winter <4winter at 
informatik.uni-hamburg.de> wrote:
> To make the exception handling more effective in code using the
> python bindings it is necessary to differentiate between the
> different kind of failures.

[master b6a0173] python: provide more exception classes

Hi, I have taken your patch and used it as a template, modifying things
slightly. I also converted database.py to make use of the new
subclasses. Documentation will have to follow, but as users can use the
code, just as they had done before, there is no urgency.

Justus is that what you had in mind?

Sebastian
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 



Re: [PATCH 7/9] python: provide more exception classes

2011-09-30 Thread Justus Winter

Quoting Sebastian Spaeth (2011-09-30 14:00:36)
>On Mon, 26 Sep 2011 03:05:35 +0200, Justus Winter 
><4win...@informatik.uni-hamburg.de> wrote:
>> To make the exception handling more effective in code using the
>> python bindings it is necessary to differentiate between the
>> different kind of failures.
>
>[master b6a0173] python: provide more exception classes
>
>Hi, I have taken your patch and used it as a template, modifying things
>slightly. I also converted database.py to make use of the new
>subclasses. Documentation will have to follow, but as users can use the
>code, just as they had done before, there is no urgency.
>
>Justus is that what you had in mind?

Yes, very nice. Thanks :)

Justus


.signature
Description: Binary data
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 7/9] python: provide more exception classes

2011-09-30 Thread Sebastian Spaeth
On Mon, 26 Sep 2011 03:05:35 +0200, Justus Winter 
<4win...@informatik.uni-hamburg.de> wrote:
> To make the exception handling more effective in code using the
> python bindings it is necessary to differentiate between the
> different kind of failures.

[master b6a0173] python: provide more exception classes

Hi, I have taken your patch and used it as a template, modifying things
slightly. I also converted database.py to make use of the new
subclasses. Documentation will have to follow, but as users can use the
code, just as they had done before, there is no urgency.

Justus is that what you had in mind?

Sebastian


pgpMegYmcjZdl.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 7/9] python: provide more exception classes

2011-09-26 Thread Justus Winter
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 <4win...@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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 7/9] python: provide more exception classes

2011-09-26 Thread Justus Winter
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 at 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