Removed old, deprecated, dangerous, stupid method of saving data to a file.

This commit is contained in:
The Wobbler 2024-12-13 16:14:16 +01:00
parent d88f4964fe
commit 8a57a23048
3 changed files with 0 additions and 61 deletions

View file

@ -1 +0,0 @@
deprecated

View file

@ -18,9 +18,6 @@ setup(
packages=[
"wobbl_tools"
],
install_requires=[
"deprecated",
],
extras_require={
"pygame": ["pygame"],
},

View file

@ -6,63 +6,6 @@ Using this module, you can store data in files easily.
import os
import json
from deprecated import deprecated
@deprecated(reason="This function is not safe to use!!!")
class DictFile:
"""
This class is not safe to use!
Any code in the file will be executed!
"""
def __init__(self, path: str=None):
self.path = path
if path is None: # create empty settings dict if path is none else load settings from file
self.settings = {}
else:
self.load_from_file(path)
def load_from_file(self, path):
file = open(path, "r")
self.settings = eval(file.read())
file.close()
def save(self, path: str=None):
if path is None:
path = self.path
file = open(path, "w")
file.write(str(self))
file.close()
def __str__(self): # make the dict not be just one line
new_settings_str = "{\n"
for key in self.settings:
new_settings_str += "\t" + repr(key) + ": " + repr(self.settings[key]) + ",\n"
new_settings_str = new_settings_str[:-2] + "\n}"
return new_settings_str
def __repr__(self):
return repr(self.settings)
def __getitem__(self, key):
return self.settings[key]
def __setitem__(self, key, value):
self.settings[key] = value
def __delitem__(self, key):
self.settings.pop(key)
def __iter__(self):
return self.settings
def __len__(self):
return len(self.settings)
def load_dataclass_json(dataclass, file_path: str, builtin_save: bool=True):