Mercurial > libervia-backend
comparison sat/test/helpers_plugins.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | be6d91572633 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
46 @param nick: nick to be used in the room | 46 @param nick: nick to be used in the room |
47 @param options: joining options | 47 @param options: joining options |
48 @param profile_key: the profile key of the user joining the room | 48 @param profile_key: the profile key of the user joining the room |
49 @return: the deferred joined wokkel.muc.Room instance | 49 @return: the deferred joined wokkel.muc.Room instance |
50 """ | 50 """ |
51 profile = self.host.memory.getProfileName(profile_key) | 51 profile = self.host.memory.get_profile_name(profile_key) |
52 roster = {} | 52 roster = {} |
53 | 53 |
54 # ask the other profiles to fill our roster | 54 # ask the other profiles to fill our roster |
55 for i in range(0, len(C.PROFILE)): | 55 for i in range(0, len(C.PROFILE)): |
56 other_profile = C.PROFILE[i] | 56 other_profile = C.PROFILE[i] |
99 """ | 99 """ |
100 @param roomJID: the room JID | 100 @param roomJID: the room JID |
101 @param profile_key: the profile key of the user joining the room | 101 @param profile_key: the profile key of the user joining the room |
102 @return: a dummy deferred | 102 @return: a dummy deferred |
103 """ | 103 """ |
104 profile = self.host.memory.getProfileName(profile_key) | 104 profile = self.host.memory.get_profile_name(profile_key) |
105 room = self.joined_rooms[roomJID] | 105 room = self.joined_rooms[roomJID] |
106 # remove ourself from the other rosters | 106 # remove ourself from the other rosters |
107 for i in range(0, len(C.PROFILE)): | 107 for i in range(0, len(C.PROFILE)): |
108 other_profile = C.PROFILE[i] | 108 other_profile = C.PROFILE[i] |
109 if other_profile == profile: | 109 if other_profile == profile: |
132 @param nick: nick to be used in the room | 132 @param nick: nick to be used in the room |
133 @param options: ignore | 133 @param options: ignore |
134 @param profile_key: the profile of the user joining the room | 134 @param profile_key: the profile of the user joining the room |
135 @return: the deferred joined wokkel.muc.Room instance or None | 135 @return: the deferred joined wokkel.muc.Room instance or None |
136 """ | 136 """ |
137 profile = self.host.memory.getProfileName(profile_key) | 137 profile = self.host.memory.get_profile_name(profile_key) |
138 if room_jid in self.clients[profile].joined_rooms: | 138 if room_jid in self.clients[profile].joined_rooms: |
139 return defer.succeed(None) | 139 return defer.succeed(None) |
140 room = self.clients[profile].join(room_jid, nick, profile_key=profile) | 140 room = self.clients[profile].join(room_jid, nick, profile_key=profile) |
141 return room | 141 return room |
142 | 142 |
143 def joinRoom(self, muc_index, user_index): | 143 def join_room(self, muc_index, user_index): |
144 """Called by tests | 144 """Called by tests |
145 @return: the nickname of the user who joined room""" | 145 @return: the nickname of the user who joined room""" |
146 muc_jid = C.MUC[muc_index] | 146 muc_jid = C.MUC[muc_index] |
147 nick = C.JID[user_index].user | 147 nick = C.JID[user_index].user |
148 profile = C.PROFILE[user_index] | 148 profile = C.PROFILE[user_index] |
149 self.join(muc_jid, nick, profile_key=profile) | 149 self.join(muc_jid, nick, profile_key=profile) |
150 return self.getNick(muc_index, user_index) | 150 return self.get_nick(muc_index, user_index) |
151 | 151 |
152 def leave(self, room_jid, profile_key="@DEFAULT@"): | 152 def leave(self, room_jid, profile_key="@DEFAULT@"): |
153 """ | 153 """ |
154 @param roomJID: the room JID | 154 @param roomJID: the room JID |
155 @param profile_key: the profile of the user leaving the room | 155 @param profile_key: the profile of the user leaving the room |
156 @return: a dummy deferred | 156 @return: a dummy deferred |
157 """ | 157 """ |
158 profile = self.host.memory.getProfileName(profile_key) | 158 profile = self.host.memory.get_profile_name(profile_key) |
159 if room_jid not in self.clients[profile].joined_rooms: | 159 if room_jid not in self.clients[profile].joined_rooms: |
160 raise plugin_xep_0045.UnknownRoom("This room has not been joined") | 160 raise plugin_xep_0045.UnknownRoom("This room has not been joined") |
161 return self.clients[profile].leave(room_jid, profile) | 161 return self.clients[profile].leave(room_jid, profile) |
162 | 162 |
163 def leaveRoom(self, muc_index, user_index): | 163 def leave_room(self, muc_index, user_index): |
164 """Called by tests | 164 """Called by tests |
165 @return: the nickname of the user who left the room""" | 165 @return: the nickname of the user who left the room""" |
166 muc_jid = C.MUC[muc_index] | 166 muc_jid = C.MUC[muc_index] |
167 nick = self.getNick(muc_index, user_index) | 167 nick = self.get_nick(muc_index, user_index) |
168 profile = C.PROFILE[user_index] | 168 profile = C.PROFILE[user_index] |
169 self.leave(muc_jid, profile_key=profile) | 169 self.leave(muc_jid, profile_key=profile) |
170 return nick | 170 return nick |
171 | 171 |
172 def getRoom(self, muc_index, user_index): | 172 def get_room(self, muc_index, user_index): |
173 """Called by tests | 173 """Called by tests |
174 @return: a wokkel.muc.Room instance""" | 174 @return: a wokkel.muc.Room instance""" |
175 profile = C.PROFILE[user_index] | 175 profile = C.PROFILE[user_index] |
176 muc_jid = C.MUC[muc_index] | 176 muc_jid = C.MUC[muc_index] |
177 try: | 177 try: |
178 return self.clients[profile].joined_rooms[muc_jid] | 178 return self.clients[profile].joined_rooms[muc_jid] |
179 except (AttributeError, KeyError): | 179 except (AttributeError, KeyError): |
180 return None | 180 return None |
181 | 181 |
182 def getNick(self, muc_index, user_index): | 182 def get_nick(self, muc_index, user_index): |
183 try: | 183 try: |
184 return self.getRoomNick(C.MUC[muc_index], C.PROFILE[user_index]) | 184 return self.get_room_nick(C.MUC[muc_index], C.PROFILE[user_index]) |
185 except (KeyError, AttributeError): | 185 except (KeyError, AttributeError): |
186 return "" | 186 return "" |
187 | 187 |
188 def getNickOfUser(self, muc_index, user_index, profile_index, secure=True): | 188 def get_nick_of_user(self, muc_index, user_index, profile_index, secure=True): |
189 try: | 189 try: |
190 room = self.clients[C.PROFILE[profile_index]].joined_rooms[C.MUC[muc_index]] | 190 room = self.clients[C.PROFILE[profile_index]].joined_rooms[C.MUC[muc_index]] |
191 return self.getRoomNickOfUser(room, C.JID[user_index]) | 191 return self.getRoomNickOfUser(room, C.JID[user_index]) |
192 except (KeyError, AttributeError): | 192 except (KeyError, AttributeError): |
193 return None | 193 return None |
198 self.host = host | 198 self.host = host |
199 | 199 |
200 def invite(self, target, room, options={}, profile_key="@DEFAULT@"): | 200 def invite(self, target, room, options={}, profile_key="@DEFAULT@"): |
201 """ | 201 """ |
202 Invite a user to a room. To accept the invitation from a test, | 202 Invite a user to a room. To accept the invitation from a test, |
203 just call FakeXEP_0045.joinRoom (no need to have a dedicated method). | 203 just call FakeXEP_0045.join_room (no need to have a dedicated method). |
204 @param target: jid of the user to invite | 204 @param target: jid of the user to invite |
205 @param room: jid of the room where the user is invited | 205 @param room: jid of the room where the user is invited |
206 @options: attribute with extra info (reason, password) as in #XEP-0249 | 206 @options: attribute with extra info (reason, password) as in #XEP-0249 |
207 @profile_key: %(doc_profile_key)s | 207 @profile_key: %(doc_profile_key)s |
208 """ | 208 """ |
276 if "rsm" in ext_data: | 276 if "rsm" in ext_data: |
277 args = (0, items[0]["id"], items[-1]["id"]) if items else () | 277 args = (0, items[0]["id"], items[-1]["id"]) if items else () |
278 self.__rsm_responses[ext_data["id"]] = RSMResponse(len(items), *args) | 278 self.__rsm_responses[ext_data["id"]] = RSMResponse(len(items), *args) |
279 return defer.succeed(items) | 279 return defer.succeed(items) |
280 | 280 |
281 def retractItems(self, service, nodeIdentifier, itemIdentifiers, sender=None): | 281 def retract_items(self, service, nodeIdentifier, itemIdentifiers, sender=None): |
282 node = self.__items[nodeIdentifier] | 282 node = self.__items[nodeIdentifier] |
283 for item in [item for item in node if item["id"] in itemIdentifiers]: | 283 for item in [item for item in node if item["id"] in itemIdentifiers]: |
284 node.remove(item) | 284 node.remove(item) |
285 return defer.succeed(None) | 285 return defer.succeed(None) |
286 | 286 |
287 def getRSMResponse(self, id): | 287 def get_rsm_response(self, id): |
288 if id not in self.__rsm_responses: | 288 if id not in self.__rsm_responses: |
289 return {} | 289 return {} |
290 result = self.__rsm_responses[id].toDict() | 290 result = self.__rsm_responses[id].toDict() |
291 del self.__rsm_responses[id] | 291 del self.__rsm_responses[id] |
292 return result | 292 return result |
293 | 293 |
294 def subscriptions(self, service, nodeIdentifier, sender=None): | 294 def subscriptions(self, service, nodeIdentifier, sender=None): |
295 return defer.succeed([]) | 295 return defer.succeed([]) |
296 | 296 |
297 def service_getDiscoItems(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE): | 297 def service_get_disco_items(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE): |
298 items = DiscoItems() | 298 items = DiscoItems() |
299 for item in list(self.__items.keys()): | 299 for item in list(self.__items.keys()): |
300 items.append(DiscoItem(service, item)) | 300 items.append(DiscoItem(service, item)) |
301 return defer.succeed(items) | 301 return defer.succeed(items) |