ADd method to resolve name string to state property
This commit is contained in:
parent
a95a25f745
commit
488687a8d8
@ -1,3 +1,7 @@
|
||||
- 0.0.17
|
||||
* Add reverse lookup method for name to state property
|
||||
- 0.0.16
|
||||
* Ensure store is present if path query for NEW is fired before any put
|
||||
- 0.0.15
|
||||
* Add missing store module in setup
|
||||
- 0.0.14
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = shep
|
||||
version = 0.0.15
|
||||
version = 0.0.17
|
||||
description = Multi-state key stores using bit masks
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -87,6 +87,8 @@ class PersistedState(State):
|
||||
def sync(self, state):
|
||||
k = self.name(state)
|
||||
|
||||
self.__ensure_store(k)
|
||||
|
||||
for o in self.__stores[k].list():
|
||||
self.__ensure_store(k)
|
||||
try:
|
||||
|
@ -35,12 +35,12 @@ class State:
|
||||
def __check_name_valid(self, k):
|
||||
if not k.isalpha():
|
||||
raise ValueError('only alpha')
|
||||
return k.upper()
|
||||
|
||||
|
||||
def __check_name(self, k):
|
||||
self.__check_name_valid(k)
|
||||
|
||||
k = k.upper()
|
||||
k = self.__check_name_valid(k)
|
||||
|
||||
try:
|
||||
getattr(self, k)
|
||||
raise StateExists(k)
|
||||
@ -140,6 +140,11 @@ class State:
|
||||
return k
|
||||
|
||||
|
||||
def from_name(self, k):
|
||||
k = self.__check_name_valid(k)
|
||||
return getattr(self, k)
|
||||
|
||||
|
||||
def match(self, v, pure=False):
|
||||
alias = None
|
||||
if not pure:
|
||||
|
@ -93,5 +93,11 @@ class TestState(unittest.TestCase):
|
||||
self.assertEqual(states.peek('abcd'))
|
||||
|
||||
|
||||
def test_from_name(self):
|
||||
states = State(3)
|
||||
states.add('foo')
|
||||
self.assertEqual(states.from_name('foo'), states.FOO)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user