ID-generating decorators¶
In cases where you want to generate IDs automatically, decorators are available. These should be the outermost decorators, as they change the signature of some of the put methods slightly.
>>> from simplekv.memory import DictStore
>>> from simplekv.idgen import HashDecorator
>>>
>>> store = HashDecorator(DictStore())
>>>
>>> key = store.put(None, b'my_data') # note the passing of 'None' as key
>>> print(key)
ab0c15b6029fdffce16b393f2d27ca839a76249e
-
class
simplekv.idgen.
HashDecorator
(decorated_store, hashfunc=<built-in function openssl_sha1>, template='{}')¶ Hash function decorator
Overrides
KeyValueStore.put()
andKeyValueStore.put_file()
. If a key of None is passed, the data/file is hashed usinghashfunc
, which defaults to hashlib.sha1.
-
class
simplekv.idgen.
UUIDDecorator
(store, template='{}')¶ UUID generating decorator
Overrides
KeyValueStore.put()
andKeyValueStore.put_file()
. If a key of None is passed, a new UUID will be generated as the key. The attribute uuidfunc determines which UUID-function to use and defaults to ‘uuid1’.