Skip to content

Commit 550b478

Browse files
committed
B64IoDupSuber class and tests
1 parent e8dc2b4 commit 550b478

File tree

4 files changed

+341
-7
lines changed

4 files changed

+341
-7
lines changed

Diff for: src/keri/db/basing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2380,7 +2380,7 @@ def getUreLast(self, key):
23802380

23812381
def getUreItemIter(self, key=b''):
23822382
"""
2383-
Use sgKey()
2383+
Use snKey()
23842384
Return iterator of partial signed escrowed event triple items at next
23852385
key after key.
23862386
Items is (key, val) where proem has already been stripped from val

Diff for: src/keri/db/subing.py

+76-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
6565
OnIoDupSuber provides set of insertion ordered values where the where trailing
6666
part of key is serialized ordinal number so that the ordering within each
67-
key prefix is monotonically increasing numeric.
67+
key prefix is monotonically increasing numeric. Useful to provide omndices
68+
for sn ordering of superseding KEL events.
6869
6970
Each of these base types for managing the key space may be mixed with other
7071
Classes that provide different types of values these include.
@@ -638,6 +639,10 @@ class B64SuberBase(SuberBase):
638639
db (dbing.LMDBer): base LMDB db
639640
sdb (lmdb._Database): instance of lmdb named sub db for this Suber
640641
sep (str): separator for combining keys tuple of strs into key bytes
642+
for db key and also used to convert val iterator to val bytes
643+
Must not be Base64 character.
644+
default is self.Sep == '.'
645+
641646
"""
642647

643648
def __init__(self, *pa, **kwa):
@@ -759,8 +764,6 @@ class B64Suber(B64SuberBase, Suber):
759764
760765
.sep must not be Base64 character.
761766
762-
Each key consistes of pre joined with .sep to ordinal suffix
763-
764767
Assumes dupsort==False
765768
766769
"""
@@ -775,6 +778,7 @@ def __init__(self, *pa, **kwa):
775778
each key. Set to False
776779
sep (str): separator to convert keys iterator to key bytes for db key
777780
default is self.Sep == '.'
781+
also used to convert val iterator to val bytes
778782
Must not be Base64 character.
779783
verify (bool): True means reverify when ._des from db when applicable
780784
False means do not reverify. Default False
@@ -2158,13 +2162,44 @@ def getItemIter(self, keys: str | bytes | memoryview | Iterable = "",
21582162
yield (self._tokeys(key), self._des(val))
21592163

21602164

2165+
class B64IoDupSuber(B64SuberBase, IoDupSuber):
2166+
"""
2167+
Subclass of B64SuberBase and IoDupSuber that serializes and deserializes
2168+
values as .sep joined strings of Base64 components in insertion ordered
2169+
duplicates with leading value proem. Proem + .sep joined value and must fit
2170+
in 511 bytes of keyspace as duplicate
2171+
2172+
Assumes dupsort==True
2173+
2174+
"""
2175+
2176+
def __init__(self, *pa, **kwa):
2177+
"""
2178+
Inherited Parameters:
2179+
db (dbing.LMDBer): base db
2180+
subkey (str): LMDB sub database key
2181+
dupsort (bool): True means enable duplicates at each key
2182+
False (default) means do not enable duplicates at
2183+
each key. Set to False
2184+
sep (str): separator for combining keys tuple of strs into key bytes
2185+
for db key and also used to convert val iterator to val bytes
2186+
Must not be Base64 character.
2187+
default is self.Sep == '.'
2188+
verify (bool): True means reverify when ._des from db when applicable
2189+
False means do not reverify. Default False
2190+
"""
2191+
super(B64IoDupSuber, self).__init__(*pa, **kwa)
2192+
2193+
2194+
21612195
class OnIoDupSuber(OnSuberBase, IoDupSuber):
21622196
"""
21632197
Sub class of IoDupSuber and OnSuberBase that supports Insertion Ordering
21642198
(IoDup) of duplicates but where the trailing part of the key space is
21652199
a serialized monotonically increasing ordinal number. This is useful for
2166-
escrows of key events etc where duplicates of likely events are maintained
2167-
in insertion order.
2200+
escrows of key events which are ordinally numbered such as sn but where
2201+
duplicates of likely events are also maintained in insertion order.
2202+
21682203
Insertion order is maintained by automagically prepending and stripping an
21692204
ordinal ordering proem to/from each duplicate value at a given key.
21702205
@@ -2412,3 +2447,39 @@ def getOnItemBackIter(self, keys: str|bytes|memoryview|Iterable = "", on: int=0)
24122447
for keys, on, val in (self.db.getOnIoDupItemBackIter(db=self.sdb,
24132448
key=self._tokey(keys), on=on, sep=self.sep.encode())):
24142449
yield (self._tokeys(keys), on, self._des(val))
2450+
2451+
2452+
class B64OnIoDupSuber(B64SuberBase, OnIoDupSuber):
2453+
"""
2454+
Subclass of B64SuberBase and OnIoDupSuber that serializes and deserializes
2455+
values as .sep joined strings of Base64 components in insertion ordered
2456+
duplicates with leading value proem but where the trailing part of the
2457+
key space is a serialized monotonically increasing ordinal number.
2458+
Proem + .sep joined value and must fit n 511 bytes of keyspace as duplicate.
2459+
2460+
Insertion order is maintained by automagically prepending and stripping an
2461+
ordinal ordering proem to/from each duplicate value at a given key.
2462+
2463+
OnIoDupSuber adds the convenience methods from OnSuberBase to OnIoDupSuber
2464+
for those cases where the keyspace has a trailing ordinal part.
2465+
2466+
Assumes dupsort==True
2467+
2468+
"""
2469+
2470+
def __init__(self, *pa, **kwa):
2471+
"""
2472+
Inherited Parameters:
2473+
db (dbing.LMDBer): base db
2474+
subkey (str): LMDB sub database key
2475+
dupsort (bool): True means enable duplicates at each key
2476+
False (default) means do not enable duplicates at
2477+
each key. Set to False
2478+
sep (str): separator for combining keys tuple of strs into key bytes
2479+
for db key and also used to convert val iterator to val bytes
2480+
Must not be Base64 character.
2481+
default is self.Sep == '.'
2482+
verify (bool): True means reverify when ._des from db when applicable
2483+
False means do not reverify. Default False
2484+
"""
2485+
super(B64OnIoDupSuber, self).__init__(*pa, **kwa)

Diff for: src/keri/help/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
ogler = ogling.initOgler(prefix='keri', syslogged=False) # inits once only on first import
1818

1919
from .helping import (nowIso8601, toIso8601, fromIso8601,
20-
nonStringSequence, nonStringIterable)
20+
nonStringSequence, nonStringIterable, Reb64)

0 commit comments

Comments
 (0)