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
1 changed files with 23 additions and 4 deletions

View File

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