in common/configdb.h [176:225]
if type(value) is list:
raw_data[key+'@'] = ','.join(value)
else:
raw_data[key] = str(value)
return raw_data
# Note: we could not use a class variable for KEY_SEPARATOR, but original dependent code is using
# these static functions. So we implement both static and instance functions with the same name.
# The static function will behave according to ConfigDB separators.
@staticmethod
def serialize_key(key, separator='|'):
if type(key) is tuple:
return separator.join(key)
else:
return str(key)
def _serialize_key(self, key):
return ConfigDBConnector.serialize_key(key, self.KEY_SEPARATOR)
@staticmethod
def deserialize_key(key, separator='|'):
tokens = key.split(separator)
if len(tokens) > 1:
return tuple(tokens)
else:
return key
def _deserialize_key(self, key):
return ConfigDBConnector.deserialize_key(key, self.KEY_SEPARATOR)
def __fire(self, table, key, data):
if table in self.handlers:
handler = self.handlers[table]
handler(table, key, data)
def subscribe(self, table, handler, fire_init_data=False):
self.handlers[table] = handler
self.fire_init_data[table] = fire_init_data
def unsubscribe(self, table):
if table in self.handlers:
self.handlers.pop(table)
def set_entry(self, table, key, data):
key = self.serialize_key(key)
raw_data = self.typed_to_raw(data)
super(ConfigDBConnector, self).set_entry(table, key, raw_data)
def mod_config(self, data):
raw_config = {}