Encodings
Uwe Kleine-König
ukleinek at strlen.de
Wed Jul 13 00:04:47 PDT 2011
Hi Patrick,
On Tue, Jul 12, 2011 at 10:29:58PM +0100, Patrick Totzke wrote:
> I noticed that commit 687366b920caa5de6ea0b66b70cf2a11e5399f7b
> breaks things with Database.get_all_tags:
>
> -------------------------------------->%-------------------------------------
> AttributeError Traceback (most recent call last)
>
> /home/pazz/projects/alot/<ipython console> in <module>()
>
> /usr/local/lib/python2.7/dist-packages/notmuch/tag.pyc in next(self)
> 86 # No need to call nmlib.notmuch_tags_valid(self._tags);
>
> 87 # Tags._get safely returns None, if there is no more valid tag.
>
> ---> 88 tag = Tags._get(self._tags).decode('utf-8')
> 89 if tag is None:
> 90 self._tags = None
>
> AttributeError: 'NoneType' object has no attribute 'decode'
> ------------------------------------%<---------------------------------------
>
> The reason is that the Tags.next() tries to decode before it tests if tag is None.
> Now, we _could_ apply a patch like this one here:
>
> ---------------------------------->%-----------------------------------------
> diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py
> index 65a9118..2ae670d 100644
> --- a/bindings/python/notmuch/tag.py
> +++ b/bindings/python/notmuch/tag.py
> @@ -85,12 +85,12 @@ class Tags(object):
> raise NotmuchError(STATUS.NOT_INITIALIZED)
> # No need to call nmlib.notmuch_tags_valid(self._tags);
> # Tags._get safely returns None, if there is no more valid tag.
> - tag = Tags._get(self._tags).decode('utf-8')
> + tag = Tags._get(self._tags)
> if tag is None:
> self._tags = None
> raise StopIteration
> nmlib.notmuch_tags_move_to_next(self._tags)
> - return tag
> + return tag.decode('utf-8')
>
> def __nonzero__(self):
> """Implement bool(Tags) check that can be repeatedly used
> -------------------------------------------%<-----------------------------
>
> But as Carl sais, we cannot guarantee that a tag is utf8 encoded anyway.
I think it would be right to enforce that tags are utf-8 encoded.
Otherwise the users get strange results if they change their locale.
Best regards
Uwe
More information about the notmuch
mailing list