comparison sat_frontends/jp/cmd_encryption.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 4b842c1fb686
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
47 self.disp(_("Following encryption algorithms are available: {algos}").format( 47 self.disp(_("Following encryption algorithms are available: {algos}").format(
48 algos=', '.join([p['name'] for p in plugins]))) 48 algos=', '.join([p['name'] for p in plugins])))
49 49
50 async def start(self): 50 async def start(self):
51 try: 51 try:
52 plugins_ser = await self.host.bridge.encryptionPluginsGet() 52 plugins_ser = await self.host.bridge.encryption_plugins_get()
53 plugins = data_format.deserialise(plugins_ser, type_check=list) 53 plugins = data_format.deserialise(plugins_ser, type_check=list)
54 except Exception as e: 54 except Exception as e:
55 self.disp(f"can't retrieve plugins: {e}", error=True) 55 self.disp(f"can't retrieve plugins: {e}", error=True)
56 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 56 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
57 else: 57 else:
75 75
76 async def start(self): 76 async def start(self):
77 jids = await self.host.check_jids([self.args.jid]) 77 jids = await self.host.check_jids([self.args.jid])
78 jid = jids[0] 78 jid = jids[0]
79 try: 79 try:
80 serialised = await self.host.bridge.messageEncryptionGet(jid, self.profile) 80 serialised = await self.host.bridge.message_encryption_get(jid, self.profile)
81 except Exception as e: 81 except Exception as e:
82 self.disp(f"can't get session: {e}", error=True) 82 self.disp(f"can't get session: {e}", error=True)
83 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 83 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
84 84
85 session_data = data_format.deserialise(serialised) 85 session_data = data_format.deserialise(serialised)
115 ) 115 )
116 116
117 async def start(self): 117 async def start(self):
118 if self.args.name is not None: 118 if self.args.name is not None:
119 try: 119 try:
120 namespace = await self.host.bridge.encryptionNamespaceGet(self.args.name) 120 namespace = await self.host.bridge.encryption_namespace_get(self.args.name)
121 except Exception as e: 121 except Exception as e:
122 self.disp(f"can't get encryption namespace: {e}", error=True) 122 self.disp(f"can't get encryption namespace: {e}", error=True)
123 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 123 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
124 elif self.args.namespace is not None: 124 elif self.args.namespace is not None:
125 namespace = self.args.namespace 125 namespace = self.args.namespace
128 128
129 jids = await self.host.check_jids([self.args.jid]) 129 jids = await self.host.check_jids([self.args.jid])
130 jid = jids[0] 130 jid = jids[0]
131 131
132 try: 132 try:
133 await self.host.bridge.messageEncryptionStart( 133 await self.host.bridge.message_encryption_start(
134 jid, namespace, not self.args.encrypt_noreplace, 134 jid, namespace, not self.args.encrypt_noreplace,
135 self.profile) 135 self.profile)
136 except Exception as e: 136 except Exception as e:
137 self.disp(f"can't get encryption namespace: {e}", error=True) 137 self.disp(f"can't get encryption namespace: {e}", error=True)
138 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 138 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
155 155
156 async def start(self): 156 async def start(self):
157 jids = await self.host.check_jids([self.args.jid]) 157 jids = await self.host.check_jids([self.args.jid])
158 jid = jids[0] 158 jid = jids[0]
159 try: 159 try:
160 await self.host.bridge.messageEncryptionStop(jid, self.profile) 160 await self.host.bridge.message_encryption_stop(jid, self.profile)
161 except Exception as e: 161 except Exception as e:
162 self.disp(f"can't end encrypted session: {e}", error=True) 162 self.disp(f"can't end encrypted session: {e}", error=True)
163 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 163 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
164 164
165 self.host.quit() 165 self.host.quit()
185 help=_("algorithm namespace (DEFAULT: current algorithm)")) 185 help=_("algorithm namespace (DEFAULT: current algorithm)"))
186 186
187 async def start(self): 187 async def start(self):
188 if self.args.name is not None: 188 if self.args.name is not None:
189 try: 189 try:
190 namespace = await self.host.bridge.encryptionNamespaceGet(self.args.name) 190 namespace = await self.host.bridge.encryption_namespace_get(self.args.name)
191 except Exception as e: 191 except Exception as e:
192 self.disp(f"can't get encryption namespace: {e}", error=True) 192 self.disp(f"can't get encryption namespace: {e}", error=True)
193 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 193 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
194 elif self.args.namespace is not None: 194 elif self.args.namespace is not None:
195 namespace = self.args.namespace 195 namespace = self.args.namespace
198 198
199 jids = await self.host.check_jids([self.args.jid]) 199 jids = await self.host.check_jids([self.args.jid])
200 jid = jids[0] 200 jid = jids[0]
201 201
202 try: 202 try:
203 xmlui_raw = await self.host.bridge.encryptionTrustUIGet( 203 xmlui_raw = await self.host.bridge.encryption_trust_ui_get(
204 jid, namespace, self.profile) 204 jid, namespace, self.profile)
205 except Exception as e: 205 except Exception as e:
206 self.disp(f"can't get encryption session trust UI: {e}", error=True) 206 self.disp(f"can't get encryption session trust UI: {e}", error=True)
207 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 207 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
208 208
209 xmlui = xmlui_manager.create(self.host, xmlui_raw) 209 xmlui = xmlui_manager.create(self.host, xmlui_raw)
210 await xmlui.show() 210 await xmlui.show()
211 if xmlui.type != C.XMLUI_DIALOG: 211 if xmlui.type != C.XMLUI_DIALOG:
212 await xmlui.submitForm() 212 await xmlui.submit_form()
213 self.host.quit() 213 self.host.quit()
214 214
215 class EncryptionTrust(base.CommandBase): 215 class EncryptionTrust(base.CommandBase):
216 subcommands = (TrustUI,) 216 subcommands = (TrustUI,)
217 217