]> git.notmuchmail.org Git - notmuch/commitdiff
use __unicode__ for string representation
authorPatrick Totzke <patricktotzke@gmail.com>
Mon, 5 Dec 2011 22:51:10 +0000 (22:51 +0000)
committerSebastian Spaeth <Sebastian@SSpaeth.de>
Tue, 6 Dec 2011 12:27:08 +0000 (13:27 +0100)
bindings/python/notmuch/filename.py
bindings/python/notmuch/globals.py
bindings/python/notmuch/message.py
bindings/python/notmuch/tag.py

index 6b332a92a1733ce11793a7a1e514ec75bc181153..a7cd7e63d44bf03076b5e21087e77ae425761a7a 100644 (file)
@@ -99,6 +99,9 @@ class Filenames(object):
         self._files = None
 
     def __str__(self):
+        return unicode(self).encode('utf-8')
+
+    def __unicode__(self):
         """Represent Filenames() as newline-separated list of full paths
 
         .. note:: As this iterates over the filenames, we will not be
index f69c73d4cfe5985e5d8920fbd8a759a5d23451b8..54a49b2d3f16895a8a8ce0b9ffc459b58a7cadf2 100644 (file)
@@ -48,11 +48,11 @@ class Status(Enum):
 
     @classmethod
     def status2str(self, status):
-        """Get a string representation of a notmuch_status_t value."""
+        """Get a (unicode) string representation of a notmuch_status_t value."""
         # define strings for custom error messages
         if status == STATUS.NOT_INITIALIZED:
-            return "Operation on uninitialized object impossible."
-        return str(Status._status2str(status))
+            return u"Operation on uninitialized object impossible."
+        return unicode(Status._status2str(status))
 
 STATUS = Status(['SUCCESS',
   'OUT_OF_MEMORY',
@@ -134,12 +134,15 @@ class NotmuchError(Exception):
         self.message = message
 
     def __str__(self):
+        return unicode(self).encode('utf-8')
+
+    def __unicode__(self):
         if self.message is not None:
             return self.message
         elif self.status is not None:
             return STATUS.status2str(self.status)
         else:
-            return 'Unknown error'
+            return u'Unknown error'
 
 
 # List of Subclassed exceptions that correspond to STATUS values and are
index 6ee5ec95e0bae524ba54f453f87335dad64da5eb..a9ded8018489c082ae86888b7b3797f2f5d940b6 100644 (file)
@@ -796,12 +796,14 @@ class Message(object):
         return self.__str__()
 
     def __str__(self):
-        """A message() is represented by a 1-line summary"""
-        msg = {}
-        msg['from'] = self.get_header('from')
-        msg['tags'] = self.get_tags()
-        msg['date'] = date.fromtimestamp(self.get_date())
-        return "%(from)s (%(date)s) (%(tags)s)" % (msg)
+        return unicode(self).encode('utf-8')
+
+    def __unicode__(self):
+        format = "%(from)s (%(date)s) (%(tags)s)"
+        return format % (self.get_header('from'),
+                         self.get_tags(),
+                         date.fromtimestamp(self.get_date()),
+                        )
 
     def get_message_parts(self):
         """Output like notmuch show"""
index a77b68d7c507118dd29cbd9e8fce458585cc9b92..2fb7d3287a8413e295b1e9b5b2840d9d06bdb476 100644 (file)
@@ -111,7 +111,10 @@ class Tags(object):
         return self._valid(self._tags) > 0
 
     def __str__(self):
-        """The str() representation of Tags() is a space separated list of tags
+        return unicode(self).encode('utf-8')
+
+    def __unicode__(self):
+        """string representation of :class:`Tags`: a space separated list of tags
 
         .. note::