Replace composite state name concat with dots
This commit is contained in:
parent
2b614b00ef
commit
4dcd6dee39
@ -152,7 +152,7 @@ class State:
|
|||||||
self.__keys_reverse[item] = state
|
self.__keys_reverse[item] = state
|
||||||
if self.__reverse.get(state) == None and not self.check_alias:
|
if self.__reverse.get(state) == None and not self.check_alias:
|
||||||
s = self.elements(state)
|
s = self.elements(state)
|
||||||
self.alias(s, state)
|
self.__alias(s, state)
|
||||||
|
|
||||||
|
|
||||||
def __state_list_index(self, item, state_list):
|
def __state_list_index(self, item, state_list):
|
||||||
@ -185,6 +185,16 @@ class State:
|
|||||||
self.__set(k, v)
|
self.__set(k, v)
|
||||||
|
|
||||||
|
|
||||||
|
def __alias(self, k, *args):
|
||||||
|
v = 0
|
||||||
|
for a in args:
|
||||||
|
a = self.__check_value_cursor(a)
|
||||||
|
v = self.__check_limit(v | a, pure=False)
|
||||||
|
if self.__is_pure(v):
|
||||||
|
raise ValueError('use add to add pure values')
|
||||||
|
return self.__set(k, v)
|
||||||
|
|
||||||
|
|
||||||
def alias(self, k, *args):
|
def alias(self, k, *args):
|
||||||
"""Add an alias for a combination of states in the store.
|
"""Add an alias for a combination of states in the store.
|
||||||
|
|
||||||
@ -198,13 +208,7 @@ class State:
|
|||||||
:raises ValueError: Attempt to use bit value as alias
|
:raises ValueError: Attempt to use bit value as alias
|
||||||
"""
|
"""
|
||||||
k = self.__check_name(k)
|
k = self.__check_name(k)
|
||||||
v = 0
|
return self.__alias(k, *args)
|
||||||
for a in args:
|
|
||||||
a = self.__check_value_cursor(a)
|
|
||||||
v = self.__check_limit(v | a, pure=False)
|
|
||||||
if self.__is_pure(v):
|
|
||||||
raise ValueError('use add to add pure values')
|
|
||||||
self.__set(k, v)
|
|
||||||
|
|
||||||
|
|
||||||
def all(self, pure=False):
|
def all(self, pure=False):
|
||||||
@ -237,14 +241,14 @@ class State:
|
|||||||
if v & c > 0:
|
if v & c > 0:
|
||||||
r.append(self.name(c))
|
r.append(self.name(c))
|
||||||
c <<= 1
|
c <<= 1
|
||||||
return '_' + '_'.join(r)
|
return '_' + '.'.join(r)
|
||||||
|
|
||||||
|
|
||||||
def from_elements(self, k):
|
def from_elements(self, k):
|
||||||
r = 0
|
r = 0
|
||||||
if k[0] != '_':
|
if k[0] != '_':
|
||||||
raise ValueError('elements string must start with underscore (_), got {}'.format(k))
|
raise ValueError('elements string must start with underscore (_), got {}'.format(k))
|
||||||
for v in k[1:].split('_'):
|
for v in k[1:].split('.'):
|
||||||
r |= self.from_name(v)
|
r |= self.from_name(v)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class TestState(unittest.TestCase):
|
|||||||
states.set('abcd', states.BAZ)
|
states.set('abcd', states.BAZ)
|
||||||
v = states.state('abcd')
|
v = states.state('abcd')
|
||||||
s = states.name(v)
|
s = states.name(v)
|
||||||
self.assertEqual(s, '_FOO_BAZ')
|
self.assertEqual(s, '_FOO.BAZ')
|
||||||
|
|
||||||
|
|
||||||
def test_peek(self):
|
def test_peek(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user