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 2B99F429E29 for ; Thu, 16 Jun 2011 04:00:01 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.09 X-Spam-Level: X-Spam-Status: No, score=-0.09 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, T_MIME_NO_TEXT=0.01] 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 d37GEihSFHO3 for ; Thu, 16 Jun 2011 03:59:58 -0700 (PDT) Received: from homiemail-a21.g.dreamhost.com (caiajhbdcaid.dreamhost.com [208.97.132.83]) by olra.theworths.org (Postfix) with ESMTP id C5689431FB6 for ; Thu, 16 Jun 2011 03:59:58 -0700 (PDT) Received: from homiemail-a21.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTP id F0191300061 for ; Thu, 16 Jun 2011 03:59:57 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=SSpaeth.de; h=from:to:subject :date:message-id:mime-version:content-type; q=dns; s=sspaeth.de; b=MXvwIOIgrnLdiJhQInPMDzStupofZEYwVO11qpH95UvQY9XvACLBHhdSvEk0t 6bHmgSdkSHEBJwneAJra1uB2QeQb3I1S8mi26UQhxRcwM5Ckm559HI31yLSwHU3+ wPEH/xOzHUbcveAJs+jXhxtcbm4NzZ+zRsTEDa5dAgVq9A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=SSpaeth.de; h=from:to :subject:date:message-id:mime-version:content-type; s=sspaeth.de ; bh=cTWBgg+qw1f+8eYsnBuSY5E2CXM=; b=C8P07GX1XMy+aH7B1AzelxNIY+W uWVfX7qksTHoi2VomxSINqDJyyT2ArMo+ETOuIfWtOeyyuPmDIb6GOjmE2V4kArU I8xFcWuppVb43a1+Dk9fhgD4DaYTvaAZzTqxR7iHTAC8mXeklK9eXXAI0LXvuTIW oVjXpdsQUf2JrRkk= Received: from spaetzbook.sspaeth.de (unknown [62.48.121.245]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: fax@sspaeth.de) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTPSA id 5E0F2300074 for ; Thu, 16 Jun 2011 03:59:55 -0700 (PDT) Received: by spaetzbook.sspaeth.de (sSMTP sendmail emulation); Thu, 16 Jun 2011 12:59:52 +0200 From: Sebastian Spaeth To: Notmuch developer list Subject: Python updates User-Agent: Notmuch/0.5-233-gb404931 (http://notmuchmail.org) Emacs/23.2.1 (x86_64-pc-linux-gnu) Date: Thu, 16 Jun 2011 12:59:47 +0200 Message-ID: <87k4cmavoc.fsf@SSpaeth.de> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" 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: Thu, 16 Jun 2011 11:00:01 -0000 --=-=-= Content-Transfer-Encoding: quoted-printable Hi all, I just wanted to keep everyone updated on the python API changes that are in the master branch. With one exception everything is backwards compatible. Feel free to stuff this into the .6 release notes :). =2D Messages() can now be "listified" with a simple: msglist =3D list(...) in case you plan to keep doing stuff with the contained messages. For this to work, the API had to be broken: __len__ function was implicitly invoked by list(), exhausting the iterator. By removing __len__ (and implementing __nonzero__ instead), the list() function works now fine on a Messages() instance. If you need the length of your Messages() object, you can use: - Query(...).count_messages() #for a pretty close approximation - len(list(Messages())) #for the precise count (exhausting the iterator) - bool(Messages()) to see if still at least one more Message() is contained in the iterator. =2D Message() now has a get_filenames() method which returns an iterator (generator function to be precise), pointing to all filenames that are recorded for that message ID. list(msg1.get_filenames()) will return all recorded names as a list. =2D Message() now implements _cmp_ and _hash_. This enables a) comparison of Messages: msgs1 =3D=3D msgs2 is True if they both 1) contain a Message object with the same Message-ID and 2) if the list of contained file names is identical. Another implication is that set() arithmetic on Messages() is now possible: db=3D notmuch.Database() msgs1=3D set(notmuch.Query(db, 'from:Sebastian').search_messages()) msgs2=3D set(notmuch.Query(db, 'not to:notmuch').search_messages()) msgs3 =3D msgs1.union(msgs2) msgs3 =3D msgs1.difference(msgs2) etc... I don't need to mention that the performance of set arithmetic (being completely done in python) is going to be abysmal compared to redoing proper Querys, yet, it might come in handy here or there. It also means you can do things like: msgs1=3D list(notmuch.Query(db, 'from:Sebastian').search_messages()) msg=3D list(notmuch.Query(db, 'not to:notmuch').search_messages())[0] =20=20 if msg in msgs1: #Yes!!! =2D Both Message() and Messages() implement now __nonzero__() which is used for boolean testing. To see whether a Message() actually contains a Message, you can now do: bool(msg) or if msg: ... More useful, for Messages() you can check if your iterator still contains at least one more Message(): msgs =3D notmuch.Query(db, 'from:Sebastian').search_messages() while msgs: msg =3D msgs.next() #yes, this will work we still had one! and also: msgs =3D notmuch.Query(db, 'from:quackydiquack').search_messages() if not msgs: print "Oh my, no search result for this weird query" Have fun Sebastian --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk354iMACgkQVYX1jMgnoGKzNgCfR9np3YQgg/XWy1B/HkN5RbQ2 FGQAn1bOhFhSaLHS+4iEOFvHnxve3CIR =l+Lg -----END PGP SIGNATURE----- --=-=-=--