comparison libervia/backend/tools/common/data_objects.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 32388d743348
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
53 if attachments: 53 if attachments:
54 for attachment in attachments: 54 for attachment in attachments:
55 if "url" not in attachment: 55 if "url" not in attachment:
56 try: 56 try:
57 attachment["url"] = next( 57 attachment["url"] = next(
58 s['url'] for s in attachment["sources"] if 'url' in s 58 s["url"] for s in attachment["sources"] if "url" in s
59 ) 59 )
60 except (StopIteration, KeyError): 60 except (StopIteration, KeyError):
61 log.warning( 61 log.warning(f"An attachment has no URL: {attachment}")
62 f"An attachment has no URL: {attachment}"
63 )
64 62
65 @property 63 @property
66 def id(self): 64 def id(self):
67 return self._uid 65 return self._uid
68 66
122 return safe(next(iter(self._html.values()))) 120 return safe(next(iter(self._html.values())))
123 121
124 @property 122 @property
125 def attachments(self): 123 def attachments(self):
126 return self.extra.get("attachments", []) 124 return self.extra.get("attachments", [])
127
128 125
129 126
130 class Messages(object): 127 class Messages(object):
131 def __init__(self, msgs_data): 128 def __init__(self, msgs_data):
132 self.messages = [Message(m) for m in msgs_data] 129 self.messages = [Message(m) for m in msgs_data]
164 self.data = data if data is not None else {} 161 self.data = data if data is not None else {}
165 162
166 @property 163 @property
167 def avatar_basename(self): 164 def avatar_basename(self):
168 try: 165 try:
169 return basename(self.data['avatar']['path']) 166 return basename(self.data["avatar"]["path"])
170 except (TypeError, KeyError): 167 except (TypeError, KeyError):
171 return None 168 return None
172 169
173 def __getitem__(self, key): 170 def __getitem__(self, key):
174 return self.data[key] 171 return self.data[key]