From e1324c434f838bf886addc540a56b3626920458b Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Thu, 13 Jun 2019 15:12:08 +0200 Subject: [PATCH] iter_keys_upto_delimiter => iter_prefixes_upto_delimiter --- simplekv/__init__.py | 10 ++++++---- simplekv/decorator.py | 2 +- simplekv/fs.py | 8 ++++---- simplekv/net/azurestore.py | 2 +- tests/basic_store.py | 8 ++++---- tests/test_filesystem_store.py | 8 ++++---- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/simplekv/__init__.py b/simplekv/__init__.py index 2de24d20..9d88f3f5 100644 --- a/simplekv/__init__.py +++ b/simplekv/__init__.py @@ -108,12 +108,14 @@ def iter_keys(self, prefix=u""): """ raise NotImplementedError - def iter_keys_upto_delimiter(self, delimiter, prefix=u""): - """Returns an Iterator over all keys currently in the store, in any order. The keys are listed up to the given delimiter. + def iter_prefixes_upto_delimiter(self, delimiter, prefix=u""): + """Returns an Iterator over all prefixes currently in the store, in any order. The + prefixes are listed up to the given delimiter. - If the prefix contains the delimiter, the first delimiter after the prefix is used as a cut-off point. + If the prefix contains the delimiter, the first delimiter after the prefix is used + as a cut-off point. - The uniqueness of the keys is ensured. + The uniqueness of the prefixes is ensured. :raises exceptions.IOError: If there was an error accessing the store. """ diff --git a/simplekv/decorator.py b/simplekv/decorator.py index ee5c0b95..ccf9ea47 100644 --- a/simplekv/decorator.py +++ b/simplekv/decorator.py @@ -58,7 +58,7 @@ def iter_keys(self, prefix=u""): return (self._unmap_key(k) for k in self._dstore.iter_keys(self._map_key_prefix(prefix)) if self._filter(k)) - def iter_keys_upto_delimiter(self, delimiter, prefix=u""): + def iter_prefixes_upto_delimiter(self, delimiter, prefix=u""): dlen = len(delimiter) plen = len(prefix) memory = set() diff --git a/simplekv/fs.py b/simplekv/fs.py index 00b65ebe..ac3f72fd 100644 --- a/simplekv/fs.py +++ b/simplekv/fs.py @@ -154,15 +154,15 @@ def keys(self, prefix=u""): def iter_keys(self, prefix=u""): return iter(self.keys(prefix)) - def iter_keys_upto_delimiter(self, delimiter, prefix=u""): + def iter_prefixes_upto_delimiter(self, delimiter, prefix=u""): if delimiter != os.sep: - return super(FilesystemStore, self).iter_keys_upto_delimiter( + return super(FilesystemStore, self).iter_prefixes_upto_delimiter( delimiter, prefix, ) - return self._iter_keys_upto_delimiter_efficient(delimiter, prefix) + return self._iter_prefixes_upto_delimiter_efficient(delimiter, prefix) - def _iter_keys_upto_delimiter_efficient(self, delimiter, prefix=u""): + def _iter_prefixes_upto_delimiter_efficient(self, delimiter, prefix=u""): if delimiter in prefix: pos = prefix.rfind(delimiter) search_prefix = prefix[:pos] diff --git a/simplekv/net/azurestore.py b/simplekv/net/azurestore.py index 0452f4fc..b54193d2 100644 --- a/simplekv/net/azurestore.py +++ b/simplekv/net/azurestore.py @@ -123,7 +123,7 @@ def iter_keys(self, prefix=u""): return (blob.decode('utf-8') if isinstance(blob, binary_type) else blob for blob in blobs) - def iter_keys_upto_delimiter(self, delimiter, prefix=u""): + def iter_prefixes_upto_delimiter(self, delimiter, prefix=u""): if prefix == "": prefix = None with map_azure_exceptions(): diff --git a/tests/basic_store.py b/tests/basic_store.py index 236597ca..d517cc5d 100644 --- a/tests/basic_store.py +++ b/tests/basic_store.py @@ -221,7 +221,7 @@ def test_key_iterator_with_prefix(self, store, key, key2, value): l.sort() assert l == sorted([key_prefix_1, key_prefix_2]) - def test_key_iterator_upto_delimiter(self, store, value): + def test_prefix_iterator_upto_delimiter(self, store, value): delimiter = u"X" for k in [ u"X", @@ -237,13 +237,13 @@ def test_key_iterator_upto_delimiter(self, store, value): ]: store.put(k, value) - l = sorted(store.iter_keys_upto_delimiter(u"X")) + l = sorted(store.iter_prefixes_upto_delimiter(u"X")) assert l == [u"X", u"a1X", u"a2X", u"a3", u"a4X"] - l = sorted(store.iter_keys_upto_delimiter(u"X", prefix=u"a4X")) + l = sorted(store.iter_prefixes_upto_delimiter(u"X", prefix=u"a4X")) assert l == [u"a4Xb1X", u"a4Xb2X", u"a4Xb3"] - l = sorted(store.iter_keys_upto_delimiter(u"X", prefix=u"foo")) + l = sorted(store.iter_prefixes_upto_delimiter(u"X", prefix=u"foo")) assert l == [] def test_keys(self, store, key, key2, value, value2): diff --git a/tests/test_filesystem_store.py b/tests/test_filesystem_store.py index 61b245ef..869d5908 100644 --- a/tests/test_filesystem_store.py +++ b/tests/test_filesystem_store.py @@ -174,7 +174,7 @@ class ExtendedKeyspaceStore(ExtendedKeyspaceMixin, FilesystemStore): pass return ExtendedKeyspaceStore(tmpdir) - def test_key_iterator_upto_delimiter_ossep(self, store, value): + def test_prefix_iterator_upto_delimiter_ossep(self, store, value): delimiter = u"X" for k in [ u"a1" + os.sep + u"b1", @@ -188,7 +188,7 @@ def test_key_iterator_upto_delimiter_ossep(self, store, value): ]: store.put(k, value) - l = sorted(store.iter_keys_upto_delimiter(os.sep)) + l = sorted(store.iter_prefixes_upto_delimiter(os.sep)) assert l == [ u"a1" + os.sep, u"a2" + os.sep, @@ -196,7 +196,7 @@ def test_key_iterator_upto_delimiter_ossep(self, store, value): u"a4" + os.sep, ] - l = sorted(store.iter_keys_upto_delimiter( + l = sorted(store.iter_prefixes_upto_delimiter( os.sep, prefix=u"a4" + os.sep, )) @@ -206,7 +206,7 @@ def test_key_iterator_upto_delimiter_ossep(self, store, value): u"a4" + os.sep + "b3", ] - l = sorted(store.iter_keys_upto_delimiter( + l = sorted(store.iter_prefixes_upto_delimiter( os.sep, prefix=u"foo" + os.sep, ))