Encodings

Patrick Totzke patricktotzke at googlemail.com
Tue Jul 12 14:29:58 PDT 2011


Hiya,

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.
So i'd suggest we just revore the commit in question.
best,
/p
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20110712/ffd88188/attachment.pgp>


More information about the notmuch mailing list