Mercurial > libervia-backend
comparison sat_frontends/jp/cmd_message.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 | 78b5f356900c |
children | 4b842c1fb686 |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
89 syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body")) | 89 syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body")) |
90 self.parser.add_argument( | 90 self.parser.add_argument( |
91 "jid", help=_("the destination jid") | 91 "jid", help=_("the destination jid") |
92 ) | 92 ) |
93 | 93 |
94 async def sendStdin(self, dest_jid): | 94 async def send_stdin(self, dest_jid): |
95 """Send incomming data on stdin to jabber contact | 95 """Send incomming data on stdin to jabber contact |
96 | 96 |
97 @param dest_jid: destination jid | 97 @param dest_jid: destination jid |
98 """ | 98 """ |
99 header = "\n" if self.args.new_line else "" | 99 header = "\n" if self.args.new_line else "" |
121 if self.args.separate: | 121 if self.args.separate: |
122 # we send stdin in several messages | 122 # we send stdin in several messages |
123 if header: | 123 if header: |
124 # first we sent the header | 124 # first we sent the header |
125 try: | 125 try: |
126 await self.host.bridge.messageSend( | 126 await self.host.bridge.message_send( |
127 dest_jid, | 127 dest_jid, |
128 {self.args.lang: header}, | 128 {self.args.lang: header}, |
129 subject, | 129 subject, |
130 self.args.type, | 130 self.args.type, |
131 profile_key=self.profile, | 131 profile_key=self.profile, |
158 if idx > 0 and C.KEY_ATTACHMENTS in extra: | 158 if idx > 0 and C.KEY_ATTACHMENTS in extra: |
159 # if we send several messages, we only want to send attachments with the | 159 # if we send several messages, we only want to send attachments with the |
160 # first one | 160 # first one |
161 del extra[C.KEY_ATTACHMENTS] | 161 del extra[C.KEY_ATTACHMENTS] |
162 try: | 162 try: |
163 await self.host.bridge.messageSend( | 163 await self.host.bridge.message_send( |
164 dest_jid, | 164 dest_jid, |
165 msg, | 165 msg, |
166 subject, | 166 subject, |
167 self.args.type, | 167 self.args.type, |
168 data_format.serialise(extra), | 168 data_format.serialise(extra), |
191 if self.args.encrypt_noreplace and self.args.encrypt is None: | 191 if self.args.encrypt_noreplace and self.args.encrypt is None: |
192 self.parser.error("You need to use --encrypt if you use --encrypt-noreplace") | 192 self.parser.error("You need to use --encrypt if you use --encrypt-noreplace") |
193 | 193 |
194 if self.args.encrypt is not None: | 194 if self.args.encrypt is not None: |
195 try: | 195 try: |
196 namespace = await self.host.bridge.encryptionNamespaceGet( | 196 namespace = await self.host.bridge.encryption_namespace_get( |
197 self.args.encrypt) | 197 self.args.encrypt) |
198 except Exception as e: | 198 except Exception as e: |
199 self.disp(f"can't get encryption namespace: {e}", error=True) | 199 self.disp(f"can't get encryption namespace: {e}", error=True) |
200 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 200 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
201 | 201 |
202 try: | 202 try: |
203 await self.host.bridge.messageEncryptionStart( | 203 await self.host.bridge.message_encryption_start( |
204 jid_, namespace, not self.args.encrypt_noreplace, self.profile | 204 jid_, namespace, not self.args.encrypt_noreplace, self.profile |
205 ) | 205 ) |
206 except Exception as e: | 206 except Exception as e: |
207 self.disp(f"can't start encryption session: {e}", error=True) | 207 self.disp(f"can't start encryption session: {e}", error=True) |
208 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 208 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
209 | 209 |
210 await self.sendStdin(jid_) | 210 await self.send_stdin(jid_) |
211 | 211 |
212 | 212 |
213 class Retract(base.CommandBase): | 213 class Retract(base.CommandBase): |
214 | 214 |
215 def __init__(self, host): | 215 def __init__(self, host): |
221 help=_("ID of the message (internal ID)") | 221 help=_("ID of the message (internal ID)") |
222 ) | 222 ) |
223 | 223 |
224 async def start(self): | 224 async def start(self): |
225 try: | 225 try: |
226 await self.host.bridge.messageRetract( | 226 await self.host.bridge.message_retract( |
227 self.args.message_id, | 227 self.args.message_id, |
228 self.profile | 228 self.profile |
229 ) | 229 ) |
230 except Exception as e: | 230 except Exception as e: |
231 self.disp(f"can't retract message: {e}", error=True) | 231 self.disp(f"can't retract message: {e}", error=True) |
284 key = 'rsm_' + suff | 284 key = 'rsm_' + suff |
285 value = getattr(self.args,key) | 285 value = getattr(self.args,key) |
286 if value is not None: | 286 if value is not None: |
287 extra[key] = str(value) | 287 extra[key] = str(value) |
288 try: | 288 try: |
289 data, metadata_s, profile = await self.host.bridge.MAMGet( | 289 data, metadata_s, profile = await self.host.bridge.mam_get( |
290 self.args.service, data_format.serialise(extra), self.profile) | 290 self.args.service, data_format.serialise(extra), self.profile) |
291 except Exception as e: | 291 except Exception as e: |
292 self.disp(f"can't retrieve MAM archives: {e}", error=True) | 292 self.disp(f"can't retrieve MAM archives: {e}", error=True) |
293 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 293 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
294 | 294 |
295 metadata = data_format.deserialise(metadata_s) | 295 metadata = data_format.deserialise(metadata_s) |
296 | 296 |
297 try: | 297 try: |
298 session_info = await self.host.bridge.sessionInfosGet(self.profile) | 298 session_info = await self.host.bridge.session_infos_get(self.profile) |
299 except Exception as e: | 299 except Exception as e: |
300 self.disp(f"can't get session infos: {e}", error=True) | 300 self.disp(f"can't get session infos: {e}", error=True) |
301 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 301 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
302 | 302 |
303 # we need to fill own_jid for message output | 303 # we need to fill own_jid for message output |