Extend serialization and deserialization with tags for person

This commit is contained in:
nolash 2021-11-06 14:39:30 +01:00
parent 8568e352be
commit 0902d0c9b2
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746

View File

@ -36,6 +36,22 @@ class Account(Person):
logg.debug('tags are now {}'.format(self.tags)) logg.debug('tags are now {}'.format(self.tags))
@staticmethod
def from_person_data(person_data):
o = Account.deserialize(person_data)
try:
o.tags = person_data['custom']['tags']
except KeyError as e:
pass
return o
def serialize(self):
o = super(Account, self).serialize()
o['custom'] = {}
o['custom']['tags'] = self.tags
return o
class FileUserStore: class FileUserStore:
@ -94,7 +110,6 @@ class FileUserStore:
sp = os.path.join(s_h, '.stick_' + s_t) sp = os.path.join(s_h, '.stick_' + s_t)
f = open(sp, 'w') f = open(sp, 'w')
f.close() f.close()
logg.debug('wrote {}'.format(sp))
def __is_sticky(self, p): def __is_sticky(self, p):
@ -147,6 +162,8 @@ class FileUserStore:
f = open(p, 'r') f = open(p, 'r')
r = f.read() r = f.read()
f.close() f.close()
logg.debug('retrieved {} from {}'.format(k, p))
return r.strip() return r.strip()
@ -193,8 +210,9 @@ class FileUserStore:
v = json.loads(v) v = json.loads(v)
person = Account() person = Account()
try: try:
person_data = person.deserialize(person_data=v) person_data = person.from_person_data(person_data=v)
except Exception as e: except Exception as e:
logg.error('e {}'.format(e))
person_data = v person_data = v
return person_data return person_data
except FileNotFoundError: except FileNotFoundError:
@ -216,8 +234,7 @@ class FileUserStore:
data = json.loads(r) data = json.loads(r)
person = Account() person = Account()
person_data = person.deserialize(person_data=data) person_data = person.from_person_data(person_data=data)
self.put(address, json.dumps(person_data.serialize()), force=update)
ptr = generate_metadata_pointer(bytes.fromhex(address), MetadataPointer.CUSTOM) ptr = generate_metadata_pointer(bytes.fromhex(address), MetadataPointer.CUSTOM)
r = None r = None
@ -228,4 +245,6 @@ class FileUserStore:
except Exception as e: except Exception as e:
pass pass
self.put(address, json.dumps(person_data.serialize()), force=update)
return person_data return person_data