Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id B1942429E33 for ; Mon, 5 Dec 2011 13:19:45 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Pk3NldykS3Uo for ; Mon, 5 Dec 2011 13:19:44 -0800 (PST) Received: from mail-ey0-f181.google.com (mail-ey0-f181.google.com [209.85.215.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 327BC429E2E for ; Mon, 5 Dec 2011 13:19:44 -0800 (PST) Received: by eaal13 with SMTP id l13so1423797eaa.26 for ; Mon, 05 Dec 2011 13:19:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=vUwYoksc2ah1I9qse9lGqpLit8xB069G+mYdGUe+vfI=; b=LGMCisDMM1PEh9F0JhRnoGcSgW7E22aU5dlDfC/QjnsliJZN+M9IKJ+2kGL0enT7CR cJbjsN0pPql39kWjbO+4JJKwhUjk/RHwv0eYu32tTZYf8N/OiG0VG696tSuWXjz5jpd9 Fom1wcUJsztfbFimcGK0yr5S8cq6zz5Yq1ETI= Received: by 10.213.3.146 with SMTP id 18mr1397898ebn.6.1323119982817; Mon, 05 Dec 2011 13:19:42 -0800 (PST) Received: from localhost (cpc1-sgyl2-0-0-cust548.18-2.cable.virginmedia.com. [82.41.10.37]) by mx.google.com with ESMTPS id v3sm63207905eej.7.2011.12.05.13.19.40 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Dec 2011 13:19:41 -0800 (PST) From: Patrick Totzke To: notmuch@notmuchmail.org Subject: [PATCH 2/3] use __unicode__ for string representation Date: Mon, 5 Dec 2011 21:19:28 +0000 Message-Id: <1323119969-1485-3-git-send-email-patricktotzke@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1323119969-1485-1-git-send-email-patricktotzke@gmail.com> References: <1323119969-1485-1-git-send-email-patricktotzke@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Dec 2011 21:19:46 -0000 --- bindings/python/notmuch/filename.py | 3 +++ bindings/python/notmuch/globals.py | 11 +++++++---- bindings/python/notmuch/message.py | 14 ++++++++------ bindings/python/notmuch/tag.py | 7 +++++-- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/filename.py index 077754e..80755ee 100644 --- a/bindings/python/notmuch/filename.py +++ b/bindings/python/notmuch/filename.py @@ -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 diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py index 36354fc..62b2df1 100644 --- a/bindings/python/notmuch/globals.py +++ b/bindings/python/notmuch/globals.py @@ -49,11 +49,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', @@ -133,12 +133,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 # subclasses of NotmuchError. diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py index e0c7eda..fac575c 100644 --- a/bindings/python/notmuch/message.py +++ b/bindings/python/notmuch/message.py @@ -794,12 +794,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""" diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py index f3a3d27..36aeeed 100644 --- a/bindings/python/notmuch/tag.py +++ b/bindings/python/notmuch/tag.py @@ -95,7 +95,7 @@ class Tags(object): if not self._valid(self._tags): self._tags = None raise StopIteration - tag = Tags._get(self._tags).decode('UTF-8') + tag = Tags._get(self._tags) self._move_to_next(self._tags) return tag @@ -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:: As this iterates over the tags, we will not be able to iterate over them again (as in retrieve them)! If -- 1.7.4.1