Skip to content

Commit

Permalink
Add not str keys for dict
Browse files Browse the repository at this point in the history
Updated to 0.0.7a0
  • Loading branch information
GigantPro committed Apr 3, 2023
1 parent ee499fc commit d040871
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
26 changes: 12 additions & 14 deletions frozenclass/dataparser/data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,31 @@ def parse_file_content(self, file_name: str | None = None) -> dict[Any]:
def _encoding_dict_keys(self) -> None:
res = []
for var_decription in self.saved_data['var']:
if var_decription['var_type'] != 'dict':
continue
for key in var_decription['var_value']: # FIX ME PLS!!!!
print(type(var_decription['var_value']), var_decription['var_value'], '@frozenclass|' in var_decription['var_value'])
if '@frozenclass|' in key:
print(1)
new_key = self.__parse_value_name(key)
new_var_desc = var_decription
new_var_desc['var_value'] = new_key
else:
res.append(var_decription)
new_var = var_decription
if var_decription['var_type'] == 'dict':
new_value = {}
for key in var_decription['var_value']:
if '@frozenclass|' not in key:
continue

new_value[self.__parse_value_name(key)] = \
var_decription['var_value'][key]
new_var['var_value'] = new_value
res.append(new_var)
self.saved_data['var'] = res
print(self.saved_data)

def __parse_value_name(self, key: str) -> str:
key_value, description = key.split('@')
new_key = ''

name, args = description.split('|')[0]
name, args = description.split('|')
if name != 'frozenclass':
return key

for specif in args.split(';'):
if specif.strip() == '':
continue

print(specif)
spec_type, spec_value = specif.split(':')

if spec_type == 'type':
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "frozenclass"
version = "0.0.6a1"
version = "0.0.7a0"
description = "Python module for convenient storage of classes in files."
authors = ["GigantPro <[email protected]>"]
license = "The GPLv3 License (GPLv3)"
Expand Down
21 changes: 9 additions & 12 deletions tests/test_save_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@
("asd", "qwe", "zxcasd"),
([1, 2, 3], ['1', '2', '3'], (3, 4, 5)),
([1, '2', ['3', '4']], 1, 2),
([1, '2', ['3', '4']], {1: 2, 2: ['123']}, ('a', '', 'qwe')),
],
)
def test_save_load(fst, sec, thrd):
# class Test:
# pass
class Test:
pass

save_name = ''.join([choice(ascii_letters) for _ in range(10)])

# ts_object = Test()
ts_object = Test()

# setattr(ts_object, "fst", fst)
# setattr(ts_object, "sec", sec)
# setattr(ts_object, "thrd", thrd)
setattr(ts_object, "fst", fst)
setattr(ts_object, "sec", sec)
setattr(ts_object, "thrd", thrd)

controller = DataController("test_saves")

# save_name = controller.freeze_class(ts_object)
controller.freeze_class(ts_object, save_name)

# new_class = controller.load_save(save_name) #48210001663
new_class = controller.load_save('48210001663')
new_class = controller.load_save(save_name)

assert new_class.fst == fst and new_class.sec == sec and new_class.thrd == thrd

test_save_load([1, '2', ['3', '4']], {1: 2, 2: ['123']}, ('a', '', 'qwe'))

0 comments on commit d040871

Please sign in to comment.