Compare commits

...

2 Commits

Author SHA1 Message Date
nolash
6f1bf1ba1f
Proper classmethod parent invoke for account/person 2021-11-06 14:51:52 +01:00
nolash
0902d0c9b2
Extend serialization and deserialization with tags for person 2021-11-06 14:39:30 +01:00

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))
@classmethod
def deserialize(cls, person_data):
o = super(Account, cls).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()
@ -167,7 +184,6 @@ class FileUserStore:
logg.info(e) logg.info(e)
pass pass
#getter = MetadataRequestsHandler(MetadataPointer.PHONE, phone.encode('utf-8'))
r = None r = None
user_address = None user_address = None
try: try:
@ -195,6 +211,7 @@ class FileUserStore:
try: try:
person_data = person.deserialize(person_data=v) person_data = person.deserialize(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:
@ -217,7 +234,6 @@ class FileUserStore:
data = json.loads(r) data = json.loads(r)
person = Account() person = Account()
person_data = person.deserialize(person_data=data) person_data = person.deserialize(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 +244,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