def get_settings(self):
# Try opening and loading the settings from file.
filename = os.path.join(self.__path, self.FILENAME)
try:
with open(filename, 'rb') as file:
settings = pickle.load(file)
# Test the pickle and check each setting inside it.
assert isinstance(settings, dict)
key_list = list(self.DEFAULT)
for key in settings:
assert isinstance(key, str)
assert key in self.DEFAULT
key_list.remove(key)
# Add new settings as needed (when new ones are created).
for key in key_list:
settings[key] = self.DEFAULT[key]
# Return old settings, or on error, the default settings.
return False, settings
except (IOError, pickle.UnpicklingError, AssertionError):
return True, self.DEFAULT
评论列表
文章目录