-
Notifications
You must be signed in to change notification settings - Fork 1
Data Structures
A lot of accessing is done trough keys.
Every Data_container represents a dict, often containing other dicts.
dict = {
"user": {
"email": "[email protected]",
"name": "The Name"
}
}
The key to the email value is user.email
.
Every key mentoined lateron has to be in that structure.
It is located in the modules pybot.data_container
The Data_container wraps a dict in a thread safe manner.
The pybot.shared_data
module represents a global Data_container
class Data_container(object):
def get(self, key) # Return a deepcopy of the value corresponding to key
def append(self, key, value) # Append value to a list corresponding to key
def pop(self, key, index) # Remove the index in a list correspondig to key
def remove(self, key, value) # Remove value from a list corresponding to key
def set(self, key, value) # Set the value corresponding to key
def get_data(self) # Return a deepcopy of the wrapped dict
def get_data_container(self, key): # Return a Data_container representing the dict corresponding to key
A Data_container can be created by passing it a dict to represent:
data_container = Data_container({})
It is located in the modules pybot.persistent_data
The Persistent_data_container represents a JSON file whichs top-level element has to be a dict.
All changes will be saved to that file, providing persistance between sessions.
The pybot.persistent_data
represents a global Persistent_data_container
class Persistent_data_container(object):
def set(self, key, value) # Set the value corresponding to key
def append(self, key, value) # Append value to a list corresponding to key
def pop(self, key, index) # Remove the index in a list correspondig to key
def remove(self, key, value) # Remove value from a list corresponding to key
def get(self, key) # Return a deepcopy of the value corresponding to key
def get_data(self) # Return a deepcopy of the wrapped dict
def get_data_container(self, key): # Return a Data_container representing the dict corresponding to key
A Persistent_data_container can be created by passing it the path to a vaild JSON-file or a non-existant file:
persistent_data = Persistent_data_container("../data.json")
It is located in the modules pybot.configuration
The Configuration_data_container is read-only and wraps a Persistent_data_container
The pybot.configuration
represents a global Configuration_data_container
class Configuration_data_container(object):
def get(self, key) # Return a deepcopy of the value corresponding to key
def get_data(self) # Return a deepcopy of the wrapped dict
def get_data_container(self, key): # Return a Data_container representing the dict corresponding to key
A Configuration_data_container can be created by passing it the path to a vaild JSON-file or a non-existant file:
configuration_data = Configuration_data_container("../data.json")