Re: [PATCH] emacs: address completion, allow sender/recipient and filters
[notmuch-archives.git] / 6c / 4e4dd8a4b6f06d0bb9044e96e2910e4407ee75
1 Return-Path: <oxij@oxij.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5  by arlo.cworth.org (Postfix) with ESMTP id CFDBF6DE0B44\r
6  for <notmuch@notmuchmail.org>; Thu, 30 Jul 2015 18:44:05 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.001\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.001 tagged_above=-999 required=5\r
12  tests=[SPF_PASS=-0.001] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id LrlbbbVVE8Wv for <notmuch@notmuchmail.org>;\r
16  Thu, 30 Jul 2015 18:44:03 -0700 (PDT)\r
17 X-Greylist: delayed 437 seconds by postgrey-1.35 at arlo;\r
18  Thu, 30 Jul 2015 18:44:02 PDT\r
19 Received: from tricoro.koumakan.jp (tricoro.koumakan.jp [195.154.188.176])\r
20  by arlo.cworth.org (Postfix) with ESMTPS id BD9DD6DE0B20\r
21  for <notmuch@notmuchmail.org>; Thu, 30 Jul 2015 18:44:02 -0700 (PDT)\r
22 Received: from localhost (ppp91-122-53-24.pppoe.avangarddsl.ru [91.122.53.24])\r
23  (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\r
24  bits)) (No client certificate requested)\r
25  by tricoro.koumakan.jp (Postfix) with ESMTPSA id 9F1F6103D;\r
26  Fri, 31 Jul 2015 10:36:41 +0900 (JST)\r
27 From: Jan Malakhovski <oxij@oxij.org>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [PATCH] python: fix get_filenames() and make it actually usable\r
30 Date: Fri, 31 Jul 2015 01:36:26 +0000\r
31 Message-Id: <1438306586-7597-1-git-send-email-oxij@oxij.org>\r
32 X-Mailer: git-send-email 2.4.1\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.18\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37  <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
39  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
44  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Fri, 31 Jul 2015 01:44:05 -0000\r
46 \r
47 The problem with the previous implementation is that different\r
48 versions of python exhaust __iter__() differently and the\r
49 implementation that can be exhausted is not only absolutely unusable\r
50 in the user code, but it also can not be consistently used with both\r
51 python 2.* and 3.*.\r
52 \r
53 This doesn't change the interface.\r
54 ---\r
55  bindings/python/notmuch/filenames.py | 84 +++++++++++-------------------------\r
56  1 file changed, 26 insertions(+), 58 deletions(-)\r
57 \r
58 diff --git a/bindings/python/notmuch/filenames.py b/bindings/python/notmuch/filenames.py\r
59 index 229f414..e2b8886 100644\r
60 --- a/bindings/python/notmuch/filenames.py\r
61 +++ b/bindings/python/notmuch/filenames.py\r
62 @@ -65,6 +65,18 @@ class Filenames(Python3StringMixIn):\r
63      _get.argtypes = [NotmuchFilenamesP]\r
64      _get.restype = c_char_p\r
65  \r
66 +    _valid = nmlib.notmuch_filenames_valid\r
67 +    _valid.argtypes = [NotmuchFilenamesP]\r
68 +    _valid.restype = bool\r
69 +\r
70 +    _move_to_next = nmlib.notmuch_filenames_move_to_next\r
71 +    _move_to_next.argtypes = [NotmuchFilenamesP]\r
72 +    _move_to_next.restype = None\r
73 +\r
74 +    _destroy = nmlib.notmuch_filenames_destroy\r
75 +    _destroy.argtypes = [NotmuchFilenamesP]\r
76 +    _destroy.restype = None\r
77 +\r
78      def __init__(self, files_p, parent):\r
79          """\r
80          :param files_p: A pointer to an underlying *notmuch_tags_t*\r
81 @@ -83,68 +95,24 @@ class Filenames(Python3StringMixIn):\r
82          if not files_p:\r
83              raise NullPointerError()\r
84  \r
85 -        self._files_p = files_p\r
86 +        self._list = []\r
87 +        while self._valid(files_p):\r
88 +            file_ = self._get(files_p)\r
89 +            self._move_to_next(files_p)\r
90 +            self._list.append(file_.decode('utf-8', 'ignore'))\r
91 +        self._destroy(files_p)\r
92 +\r
93          #save reference to parent object so we keep it alive\r
94          self._parent = parent\r
95  \r
96      def __iter__(self):\r
97 -        """ Make Filenames an iterator """\r
98 -        return self\r
99 -\r
100 -    _valid = nmlib.notmuch_filenames_valid\r
101 -    _valid.argtypes = [NotmuchFilenamesP]\r
102 -    _valid.restype = bool\r
103 -\r
104 -    _move_to_next = nmlib.notmuch_filenames_move_to_next\r
105 -    _move_to_next.argtypes = [NotmuchFilenamesP]\r
106 -    _move_to_next.restype = None\r
107 -\r
108 -    def __next__(self):\r
109 -        if not self._files_p:\r
110 -            raise NotInitializedError()\r
111 -\r
112 -        if not self._valid(self._files_p):\r
113 -            self._files_p = None\r
114 -            raise StopIteration\r
115 -\r
116 -        file_ = Filenames._get(self._files_p)\r
117 -        self._move_to_next(self._files_p)\r
118 -        return file_.decode('utf-8', 'ignore')\r
119 -    next = __next__ # python2.x iterator protocol compatibility\r
120 -\r
121 -    def __unicode__(self):\r
122 -        """Represent Filenames() as newline-separated list of full paths\r
123 -\r
124 -        .. note::\r
125 -\r
126 -            This method exhausts the iterator object, so you will not be able to\r
127 -            iterate over them again.\r
128 -        """\r
129 -        return "\n".join(self)\r
130 -\r
131 -    _destroy = nmlib.notmuch_filenames_destroy\r
132 -    _destroy.argtypes = [NotmuchMessageP]\r
133 -    _destroy.restype = None\r
134 -\r
135 -    def __del__(self):\r
136 -        """Close and free the notmuch filenames"""\r
137 -        if self._files_p:\r
138 -            self._destroy(self._files_p)\r
139 +        """Make Filenames an iterator"""\r
140 +        return self._list.__iter__()\r
141  \r
142      def __len__(self):\r
143 -        """len(:class:`Filenames`) returns the number of contained files\r
144 +        """len(:class:`Filenames`) returns the number of contained files"""\r
145 +        return self._list.__len__()\r
146  \r
147 -        .. note::\r
148 -\r
149 -            This method exhausts the iterator object, so you will not be able to\r
150 -            iterate over them again.\r
151 -        """\r
152 -        if not self._files_p:\r
153 -            raise NotInitializedError()\r
154 -\r
155 -        i = 0\r
156 -        while self._valid(self._files_p):\r
157 -            self._move_to_next(self._files_p)\r
158 -            i += 1\r
159 -        self._files_p = None\r
160 -        return i\r
161 +    def __unicode__(self):\r
162 +        """Represent Filenames() as newline-separated list of full paths"""\r
163 +        return "\n".join(self)\r
164 -- \r
165 2.4.1\r
166 \r