aboutsummaryrefslogtreecommitdiff
path: root/bindings/python-cffi/notmuch2
diff options
context:
space:
mode:
authorFloris Bruynooghe <flub@devork.be>2020-06-15 23:55:53 +0200
committerDavid Bremner <david@tethera.net>2020-06-15 21:50:03 -0300
commit1bca41698a03980b701558fb5c481ef0a340460d (patch)
tree43da814b06de63b57c0bafa92483b1bb66d37c75 /bindings/python-cffi/notmuch2
parent5a58754841f4d3e62d104ad338c8ca2c481dc32e (diff)
python config access: fix style and KeyError bug
This fixes some minor style/pep8 things and adds tests for the new config support. Also fixes a bug where KeyError was never raised on a missing key.
Diffstat (limited to 'bindings/python-cffi/notmuch2')
-rw-r--r--bindings/python-cffi/notmuch2/_config.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/bindings/python-cffi/notmuch2/_config.py b/bindings/python-cffi/notmuch2/_config.py
index 58383c16..29de6495 100644
--- a/bindings/python-cffi/notmuch2/_config.py
+++ b/bindings/python-cffi/notmuch2/_config.py
@@ -4,9 +4,12 @@ import notmuch2._base as base
import notmuch2._capi as capi
import notmuch2._errors as errors
+
__all__ = ['ConfigMapping']
+
class ConfigIter(base.NotmuchIter):
+
def __init__(self, parent, iter_p):
super().__init__(
parent, iter_p,
@@ -19,6 +22,7 @@ class ConfigIter(base.NotmuchIter):
item = super().__next__()
return base.BinString.from_cffi(item)
+
class ConfigMapping(base.NotmuchObject, collections.abc.MutableMapping):
"""The config key/value pairs stored in the database.
@@ -50,11 +54,10 @@ class ConfigMapping(base.NotmuchObject, collections.abc.MutableMapping):
ret = capi.lib.notmuch_database_get_config(self._ptr(), key, val_pp)
if ret != capi.lib.NOTMUCH_STATUS_SUCCESS:
raise errors.NotmuchError(ret)
- if val_pp[0] == "":
- capi.lib.free(val_pp[0])
- raise KeyError
val = base.BinString.from_cffi(val_pp[0])
capi.lib.free(val_pp[0])
+ if val == '':
+ raise KeyError
return val
def __setitem__(self, key, val):