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 526D4431FD0 for ; Thu, 2 Jun 2011 02:43:34 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 2.6 X-Spam-Level: ** X-Spam-Status: No, score=2.6 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=0.001, RCVD_ILLEGAL_IP=3.399, 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 xzsKSHy9pscO for ; Thu, 2 Jun 2011 02:43:32 -0700 (PDT) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 512D1431FB6 for ; Thu, 2 Jun 2011 02:43:32 -0700 (PDT) Received: by bwg12 with SMTP id 12so856872bwg.26 for ; Thu, 02 Jun 2011 02:43:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microcomaustralia.com.au; s=google; h=domainkey-signature:mime-version:x-originating-ip:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=d2vf8rp+EL55xywuxwT/w285C7B0BUr+prvnnZVQzv8=; b=RJ9WN15wnMdNsg8QOOd+T3SqWe/X7+IJ9FuKRWy7ztBZK8lEjACXPTDv+PuqJgBVWI t/qc24eNDk2TVsQMhr7BlMcKbnkr5psYNPbApD0lCs6uvNbkZk3PcFtIn8Ga8+bnPqAw KN+PSgf6DwcbWTvlwk5P1UkWpiaZfBlurI9gQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=microcomaustralia.com.au; s=google; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:content-type; b=cv9/gREkSfNrQovus52/U3FXZP7elk5VZqN8NMVr7u4vU0L3qzOLdnRZWflRxNapf/ dBMYYdO1/BrkSu30WROdlKMpiqjyd7+JEpwE/j+8/nSQGYWE4HbGWP468+UJ5+4OB5E/ LSBSpJq+538efk7bcD1HOgMDZM8r4frNruUPE= MIME-Version: 1.0 Received: by 10.204.143.4 with SMTP id s4mr494087bku.98.1307007809620; Thu, 02 Jun 2011 02:43:29 -0700 (PDT) Received: by 10.204.82.147 with HTTP; Thu, 2 Jun 2011 02:43:29 -0700 (PDT) X-Originating-IP: [253.99.196.189] In-Reply-To: <87aae07lxi.fsf@SSpaeth.de> References: <1306588052-sup-9838@brick> <87aae07lxi.fsf@SSpaeth.de> Date: Thu, 2 Jun 2011 19:43:29 +1000 Message-ID: Subject: Re: [python] get all messages of a thread From: Brian May To: notmuch Content-Type: multipart/alternative; boundary=0015173fe9ba360c6d04a4b77874 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, 02 Jun 2011 09:43:34 -0000 --0015173fe9ba360c6d04a4b77874 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 2 June 2011 17:05, Sebastian Spaeth wrote: > What would be the best way to solve this (besides fixing the C api to > allow to reset the iterator ;-) ?) > > I am not really familiar with the code. So am I correct in making the following assumptions? * It is not easy to fix the C api to reset the iterator (what about repeating the search?) * The only accurate way to get the number of messages is to iterate through every search result and count them? If so, then len(...) I think might be very slow if there are a large number of elements. Maybe it might be easier/better to implement object.__nonzero__(self) instead of the object.__len__(self) method? http://docs.python.org/reference/datamodel.html object.__nonzero__(self) Called to implement truth value testing and the built-in operation bool(); should return False or True, or their integer equivalents 0 or 1. When this method is not defined, __len__() is called, if it is defined, and the objec= t is considered true if its result is nonzero. If a class defines neither __len__() nor __nonzero__(), all its instances are considered true. object.__len__(self) Called to implement the built-in function len(). Should return the length o= f the object, an integer >=3D 0. Also, an object that doesn=92t define a __nonzero__() method and whose __len__() method returns zero is considered to be false in a Boolean context. --=20 Brian May --0015173fe9ba360c6d04a4b77874 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
On 2 June 2011 17:05, Sebastian Spaeth <Sebastian@sspaeth.de> wrote:
What would be the best way to solve this (besides fixing = the C api to
allow to reset the iterator ;-) ?)


= =A0I am not really familiar with the code. So am I correct in making the fo= llowing assumptions?

* It is not easy to fix the C= api to reset the iterator (what about repeating the search?)

* The only accurate way to get the number of messages i= s to iterate through every search result and count them?

If so, then len(...) I think might be very slow if there are a large= number of elements.

Maybe it might be easier/better to implement=A0object._= _nonzero__(self) =A0instead of the object.__len__(self) method?
<= br>

object.__nonzero__(self)
Called to imple= ment truth value testing and the built-in operation bool(); should return F= alse or True, or their integer equivalents 0 or 1. When this method is not = defined, __len__() is called, if it is defined, and the object is considere= d true if its result is nonzero. If a class defines neither __len__() nor _= _nonzero__(), all its instances are considered true.

object.__len__(self)
Called to implement= the built-in function len(). Should return the length of the object, an in= teger >=3D 0. Also, an object that doesn=92t define a __nonzero__() meth= od and whose __len__() method returns zero is considered to be false in a B= oolean context.

--
Brian May <brian@microcomaustralia.com.au>
--0015173fe9ba360c6d04a4b77874--