Add list by state
This commit is contained in:
parent
2a09b508b3
commit
60dee4167e
@ -1,3 +1,6 @@
|
|||||||
|
- 0.0.9
|
||||||
|
* Add optional overwrite of contents
|
||||||
|
* Add list all keys by state
|
||||||
- 0.0.8
|
- 0.0.8
|
||||||
* Add single bit transition to aliases
|
* Add single bit transition to aliases
|
||||||
- 0.0.7
|
- 0.0.7
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = shep
|
name = shep
|
||||||
version = 0.0.8
|
version = 0.0.9
|
||||||
description = Multi-state key stores using bit masks
|
description = Multi-state key stores using bit masks
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
@ -47,10 +47,3 @@ class PersistedState(State):
|
|||||||
|
|
||||||
self.__stores[k].remove(key)
|
self.__stores[k].remove(key)
|
||||||
super(PersistedState, self).purge(key)
|
super(PersistedState, self).purge(key)
|
||||||
|
|
||||||
|
|
||||||
def get(self, key=None):
|
|
||||||
state = self.state(key)
|
|
||||||
k = self.name(state)
|
|
||||||
|
|
||||||
return self.__stores[k].get(key)
|
|
||||||
|
@ -249,5 +249,11 @@ class State:
|
|||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key=None):
|
||||||
return self.__contents.get(key)
|
return self.__contents.get(key)
|
||||||
|
|
||||||
|
|
||||||
|
def list(self, state):
|
||||||
|
if self.__reverse.get(state) == None:
|
||||||
|
raise StateInvalid(state)
|
||||||
|
return self.__keys[state]
|
||||||
|
@ -50,5 +50,23 @@ class TestStateReport(unittest.TestCase):
|
|||||||
self.assertEqual(self.states.get('abcd'), 'bar')
|
self.assertEqual(self.states.get('abcd'), 'bar')
|
||||||
|
|
||||||
|
|
||||||
|
def test_list(self):
|
||||||
|
self.states.put('abcd', state=self.states.FOO)
|
||||||
|
self.states.put('xx!', state=self.states.FOO)
|
||||||
|
self.states.put('1234', state=self.states.BAR)
|
||||||
|
keys = self.states.list(self.states.FOO)
|
||||||
|
self.assertIn('abcd', keys)
|
||||||
|
self.assertIn('xx!', keys)
|
||||||
|
self.assertNotIn('1234', keys)
|
||||||
|
|
||||||
|
self.states.alias('xyzzy', self.states.BAR | self.states.FOO)
|
||||||
|
self.states.put('yyy', state=self.states.XYZZY)
|
||||||
|
|
||||||
|
keys = self.states.list(self.states.XYZZY)
|
||||||
|
self.assertIn('yyy', keys)
|
||||||
|
self.assertNotIn('1234', keys)
|
||||||
|
self.assertNotIn('xx!', keys)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user