File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -63,17 +63,31 @@ def is_valid_key(self, k):
6363 return self ._key_filt (k )
6464
6565
66- class KeyStore :
67- def __init__ (self , id_of_key , key_of_id = None ):
66+ class ExpliticKeyTrans :
67+ def __init__ (self , id_of_key = None , key_of_id = None ):
68+ if id_of_key is None :
69+ if key_of_id is None :
70+ raise ValueError ("You need to specify at least one of these: id_of_key, or key_of_id (or both!)" )
71+ else :
72+ id_of_key = {k : _id for _id , k in key_of_id .items ()}
73+ elif key_of_id is None :
74+ key_of_id = {_id : k for k , _id in id_of_key .items ()}
6875 self .id_of_key = id_of_key
69- self .key_of_id = key_of_id or { _id : k for k , _id in id_of_key . items ()}
76+ self .key_of_id = key_of_id
7077
7178 def _key_of_id (self , _id ):
7279 return self .key_of_id [_id ]
7380
7481 def _id_of_key (self , k ):
7582 return self .id_of_key [k ]
7683
84+ # TODO: These two functions are general and should be placed in another Mixin or function
85+ def _test_key_id_key_invertability (self , k ):
86+ return k == self ._key_of_id (self ._id_of_key (k ))
87+
88+ def _test_id_key_id_invertability (self , _id ):
89+ return _id == self ._id_of_key (self ._key_of_id (_id ))
90+
7791
7892# TODO: Revisit ExplicitKeys and ExplicitKeysWithPrefixRelativization. Not extendible to full store!
7993class ExplicitKeys (KvCollection ):
You can’t perform that action at this time.
0 commit comments