From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id CD54E6DE0183 for ; Thu, 7 Dec 2017 03:47:37 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.73 X-Spam-Level: X-Spam-Status: No, score=-0.73 tagged_above=-999 required=5 tests=[FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id amWRT8374Ety for ; Thu, 7 Dec 2017 03:47:36 -0800 (PST) X-Greylist: delayed 343 seconds by postgrey-1.36 at arlo; Thu, 07 Dec 2017 03:47:35 PST Received: from mout.web.de (mout.web.de [212.227.15.14]) by arlo.cworth.org (Postfix) with ESMTPS id 257526DE009B for ; Thu, 7 Dec 2017 03:47:35 -0800 (PST) Received: from localhost ([78.53.227.28]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M22Sh-1fByzW0ojT-00u29y; Thu, 07 Dec 2017 12:42:29 +0100 From: l-m-h@web.de To: notmuch@notmuchmail.org Cc: Lucas Hoffmann Subject: [PATCH 3/6] python: turn get_config_list into a generator Date: Thu, 7 Dec 2017 12:40:48 +0100 Message-Id: <9dd0a4eea760800426b3db18f1fa4a9678786d79.1512646265.git.l-m-h@web.de> X-Mailer: git-send-email 2.15.1 In-Reply-To: References: In-Reply-To: References: <8737am9w18.fsf@tethera.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.15.1" X-Provags-ID: V03:K0:5NUqkk9qtVWQCrVbCBakzraF4iYc60banN/h7dwNHmD7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-At: Thu, 07 Dec 2017 11:31:51 -0800 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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, 07 Dec 2017 11:47:37 -0000 From: Lucas Hoffmann This is a multi-part message in MIME format. --------------2.15.1 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit This mimics the behaviour of the underlying C function more closely as it also does not store all values in memory. --- bindings/python/notmuch/database.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) --------------2.15.1 Content-Type: text/x-patch; name="0003-python-turn-get_config_list-into-a-generator.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0003-python-turn-get_config_list-into-a-generator.patch" diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py index 54966307..32566620 100644 --- a/bindings/python/notmuch/database.py +++ b/bindings/python/notmuch/database.py @@ -690,24 +690,22 @@ class Database(object): _config_list_destroy.restype = None def get_config_list(self, prefix=''): - """Return a list of key, value pairs where the start of key matches the - given prefix + """Return a generator of key, value pairs where the start of key + matches the given prefix Note that only config values that are stored in the database are searched and returned. The config file is not read. If no `prefix` is given all config values are returned. - This could be used to get all config values or all named queries into a - dict for example:: + This could be used to get all named queries into a dict for example:: - config = {k: v for k, v in db.get_config_list()} queries = {k[6:]: v for k, v in db.get_config_list('query.')} :param prefix: a string by which the keys should be selected :type prefix: str - :returns: all key-value pairs where `prefix` matches the beginning + :yields: all key-value pairs where `prefix` matches the beginning of the key - :rtype: a list of pairs of str + :ytype: pairs of str :raises: :exc:`NotmuchError` in case of failure. """ @@ -717,13 +715,25 @@ class Database(object): byref(config_list_p)) if status != STATUS.SUCCESS: raise NotmuchError(status) - config_list = [] while self._config_list_valid(config_list_p): key = self._config_list_key(config_list_p).decode('utf-8') value = self._config_list_value(config_list_p).decode('utf-8') - config_list.append((key, value)) + yield key, value self._config_list_move_to_next(config_list_p) - return config_list + + def get_configs(self, prefix=''): + """Return a dict of key, value pairs where the start of key matches the + given prefix + + :param prefix: a string by which the keys should be selected + :type prefix: str + :returns: all key-value pairs where `prefix` matches the beginning + of the key + :rtype: a dict of str: str + :raises: :exc:`NotmuchError` in case of failure. + + """ + return dict(self.get_config_list(prefix)) """notmuch_database_set_config""" _set_config = nmlib.notmuch_database_set_config --------------2.15.1--