comparison libervia/server/session_iface.py @ 1509:106bae41f5c8

massive refactoring from camelCase -> snake_case. See backend commit log for more details
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:44:11 +0200
parents ce879da7fcf7
children
comparison
equal deleted inserted replaced
1508:ec3ad9abf9f9 1509:106bae41f5c8
137 137
138 @classmethod 138 @classmethod
139 def get_profile_sessions(cls, profile: str) -> List["WebSession"]: 139 def get_profile_sessions(cls, profile: str) -> List["WebSession"]:
140 return cls.profiles_map.get(profile, []) 140 return cls.profiles_map.get(profile, [])
141 141
142 def getPageData(self, page, key): 142 def get_page_data(self, page, key):
143 """get session data for a page 143 """get session data for a page
144 144
145 @param page(LiberviaPage): instance of the page 145 @param page(LiberviaPage): instance of the page
146 @param key(object): data key 146 @param key(object): data key
147 return (None, object): value of the key 147 return (None, object): value of the key
148 None if not found or page_data doesn't exist 148 None if not found or page_data doesn't exist
149 """ 149 """
150 return self.pages_data.get(page, {}).get(key) 150 return self.pages_data.get(page, {}).get(key)
151 151
152 def popPageData(self, page, key, default=None): 152 def pop_page_data(self, page, key, default=None):
153 """like getPageData, but remove key once value is gotten 153 """like get_page_data, but remove key once value is gotten
154 154
155 @param page(LiberviaPage): instance of the page 155 @param page(LiberviaPage): instance of the page
156 @param key(object): data key 156 @param key(object): data key
157 @param default(object): value to return if key is not found 157 @param default(object): value to return if key is not found
158 @return (object): found value or default 158 @return (object): found value or default
164 if not page_data: 164 if not page_data:
165 # no need to keep unused page_data 165 # no need to keep unused page_data
166 del self.pages_data[page] 166 del self.pages_data[page]
167 return value 167 return value
168 168
169 def setPageData(self, page, key, value): 169 def set_page_data(self, page, key, value):
170 """set data to persist on reload 170 """set data to persist on reload
171 171
172 @param page(LiberviaPage): instance of the page 172 @param page(LiberviaPage): instance of the page
173 @param key(object): data key 173 @param key(object): data key
174 @param value(object): value to set 174 @param value(object): value to set
176 """ 176 """
177 page_data = self.pages_data.setdefault(page, {}) 177 page_data = self.pages_data.setdefault(page, {})
178 page_data[key] = value 178 page_data[key] = value
179 return value 179 return value
180 180
181 def setPageFlag(self, page, flag): 181 def set_page_flag(self, page, flag):
182 """set a flag for this page 182 """set a flag for this page
183 183
184 @param page(LiberviaPage): instance of the page 184 @param page(LiberviaPage): instance of the page
185 @param flag(unicode): flag to set 185 @param flag(unicode): flag to set
186 """ 186 """
187 flags = self.getPageData(page, FLAGS_KEY) 187 flags = self.get_page_data(page, FLAGS_KEY)
188 if flags is None: 188 if flags is None:
189 flags = self.setPageData(page, FLAGS_KEY, set()) 189 flags = self.set_page_data(page, FLAGS_KEY, set())
190 flags.add(flag) 190 flags.add(flag)
191 191
192 def popPageFlag(self, page, flag): 192 def pop_page_flag(self, page, flag):
193 """return True if flag is set 193 """return True if flag is set
194 194
195 flag is removed if it was set 195 flag is removed if it was set
196 @param page(LiberviaPage): instance of the page 196 @param page(LiberviaPage): instance of the page
197 @param flag(unicode): flag to set 197 @param flag(unicode): flag to set
210 del self.pages_data[page] 210 del self.pages_data[page]
211 return True 211 return True
212 else: 212 else:
213 return False 213 return False
214 214
215 def setPageNotification(self, page, message, level=C.LVL_INFO): 215 def set_page_notification(self, page, message, level=C.LVL_INFO):
216 """set a flag for this page 216 """set a flag for this page
217 217
218 @param page(LiberviaPage): instance of the page 218 @param page(LiberviaPage): instance of the page
219 @param flag(unicode): flag to set 219 @param flag(unicode): flag to set
220 """ 220 """
221 notif = Notification(message, level) 221 notif = Notification(message, level)
222 notifs = self.getPageData(page, NOTIFICATIONS_KEY) 222 notifs = self.get_page_data(page, NOTIFICATIONS_KEY)
223 if notifs is None: 223 if notifs is None:
224 notifs = self.setPageData(page, NOTIFICATIONS_KEY, []) 224 notifs = self.set_page_data(page, NOTIFICATIONS_KEY, [])
225 notifs.append(notif) 225 notifs.append(notif)
226 226
227 def popPageNotifications(self, page): 227 def pop_page_notifications(self, page):
228 """Return and remove last page notification 228 """Return and remove last page notification
229 229
230 @param page(LiberviaPage): instance of the page 230 @param page(LiberviaPage): instance of the page
231 @return (list[Notification]): notifications if any 231 @return (list[Notification]): notifications if any
232 """ 232 """
236 return [] 236 return []
237 ret = notifs[:] 237 ret = notifs[:]
238 del notifs[:] 238 del notifs[:]
239 return ret 239 return ret
240 240
241 def getAffiliation(self, service, node): 241 def get_affiliation(self, service, node):
242 """retrieve affiliation for a pubsub node 242 """retrieve affiliation for a pubsub node
243 243
244 @param service(jid.JID): pubsub service 244 @param service(jid.JID): pubsub service
245 @param node(unicode): pubsub node 245 @param node(unicode): pubsub node
246 @return (unicode, None): affiliation, or None if it is not in cache 246 @return (unicode, None): affiliation, or None if it is not in cache
257 # we replace at the top to get the most recently used on top 257 # we replace at the top to get the most recently used on top
258 # so less recently used will be removed if cache is full 258 # so less recently used will be removed if cache is full
259 self.affiliations[(service, node)] = affiliation 259 self.affiliations[(service, node)] = affiliation
260 return affiliation 260 return affiliation
261 261
262 def setAffiliation(self, service, node, affiliation): 262 def set_affiliation(self, service, node, affiliation):
263 """cache affiliation for a node 263 """cache affiliation for a node
264 264
265 will empty cache when it become too big 265 will empty cache when it become too big
266 @param service(jid.JID): pubsub service 266 @param service(jid.JID): pubsub service
267 @param node(unicode): pubsub node 267 @param node(unicode): pubsub node