Skip to content

Commit 1390983

Browse files
committed
Use ensure_text for LMDB decoding
1 parent 478912e commit 1390983

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

zarr/storage.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
from numcodecs.compat import (
3939
ensure_bytes,
40+
ensure_text,
4041
ensure_contiguous_ndarray
4142
)
4243
from numcodecs.registry import codec_registry
@@ -1770,16 +1771,6 @@ def __contains__(self, key):
17701771
return key in self.db
17711772

17721773

1773-
def _lmdb_decode_key_buffer(key):
1774-
# assume buffers=True
1775-
return key.tobytes().decode('ascii')
1776-
1777-
1778-
def _lmdb_decode_key_bytes(key):
1779-
# assume buffers=False
1780-
return key.decode('ascii')
1781-
1782-
17831774
class LMDBStore(MutableMapping):
17841775
"""Storage class using LMDB. Requires the `lmdb <http://lmdb.readthedocs.io/>`_
17851776
package to be installed.
@@ -1869,10 +1860,6 @@ def __init__(self, path, buffers=True, **kwargs):
18691860
self.db = lmdb.open(path, **kwargs)
18701861

18711862
# store properties
1872-
if buffers:
1873-
self.decode_key = _lmdb_decode_key_buffer
1874-
else:
1875-
self.decode_key = _lmdb_decode_key_bytes
18761863
self.buffers = buffers
18771864
self.path = path
18781865
self.kwargs = kwargs
@@ -1933,13 +1920,13 @@ def items(self):
19331920
with self.db.begin(buffers=self.buffers) as txn:
19341921
with txn.cursor() as cursor:
19351922
for k, v in cursor.iternext(keys=True, values=True):
1936-
yield self.decode_key(k), v
1923+
yield ensure_text(k, "ascii"), v
19371924

19381925
def keys(self):
19391926
with self.db.begin(buffers=self.buffers) as txn:
19401927
with txn.cursor() as cursor:
19411928
for k in cursor.iternext(keys=True, values=False):
1942-
yield self.decode_key(k)
1929+
yield ensure_text(k, "ascii")
19431930

19441931
def values(self):
19451932
with self.db.begin(buffers=self.buffers) as txn:

0 commit comments

Comments
 (0)