Commit e0019f27 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Enum class now inherit from dict for integer/Item mapping.

Remove VALID_* definitions because checks are done in the protocol module when
getting the Item from the integer value.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1055 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 08849b8b
......@@ -49,7 +49,7 @@ class EnumItem(int):
def __repr__(self):
return '<EnumItem %r (%r) of %r>' % (self.name, int(self), self.enum)
class Enum(object):
class Enum(dict):
"""
C-style enumerated type support with extended typechecking.
Instantiate with a dict whose keys are variable names and values are
......@@ -62,7 +62,6 @@ class Enum(object):
"""
def __init__(self, value_dict):
global_dict = globals()
self.enum_dict = enum_dict = {}
self.str_enum_dict = str_enum_dict = {}
for key, value in value_dict.iteritems():
# Only integer types are supported. This should be enough, and
......@@ -71,18 +70,12 @@ class Enum(object):
if not isinstance(value, int):
raise TypeError, 'Enum class only support integer values.'
item = EnumItem(self, key, value)
global_dict[key] = enum_dict[value] = item
global_dict[key] = self[value] = item
str_enum_dict[key] = item
def get(self, value, default=None):
return self.enum_dict.get(value, default)
def getFromStr(self, value, default=None):
return self.str_enum_dict.get(value, default)
def __getitem__(self, value):
return self.enum_dict[value]
# The protocol version (major, minor).
PROTOCOL_VERSION = (4, 0)
......@@ -326,7 +319,6 @@ cluster_states = Enum({
'RUNNING': 4,
'STOPPING': 5,
})
VALID_CLUSTER_STATE_LIST = (BOOTING, RUNNING, STOPPING)
# Node types.
node_types = Enum({
......@@ -336,8 +328,6 @@ node_types = Enum({
'ADMIN_NODE_TYPE' : 4,
})
VALID_NODE_TYPE_LIST = (MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE)
# Node states.
node_states = Enum({
'RUNNING_STATE': 0,
......@@ -348,9 +338,6 @@ node_states = Enum({
'PENDING_STATE': 5,
})
VALID_NODE_STATE_LIST = (RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE,
BROKEN_STATE, HIDDEN_STATE, PENDING_STATE)
# Partition cell states.
partition_cell_states = Enum({
'UP_TO_DATE_STATE': 0,
......@@ -359,9 +346,6 @@ partition_cell_states = Enum({
'DISCARDED_STATE': 3,
})
VALID_CELL_STATE_LIST = (UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE,
DISCARDED_STATE)
# Other constants.
INVALID_UUID = '\0' * 16
INVALID_TID = '\0' * 8
......
......@@ -17,6 +17,7 @@
from neo import logging
from neo import protocol
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \
DISCARDED_STATE, RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
BROKEN_STATE, HIDDEN_STATE, PENDING_STATE
......@@ -98,7 +99,7 @@ class PartitionTable(object):
def getCellList(self, offset, readable=False, writable=False):
# allow all cell states
state_set = set(VALID_CELL_STATE_LIST)
state_set = set(protocol.partition_cell_states.values())
if readable or writable:
# except non readables
state_set.remove(DISCARDED_STATE)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment