Skip to content

Commit 4117dea

Browse files
committed
Code optimization
1 parent e70e8d2 commit 4117dea

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

addon/globalPlugins/remoteClient/dialogs.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,6 @@ def on_client_or_server(self, evt):
220220
self.panel = ServerPanel(parent=self.container)
221221
self.main_sizer.Fit(self)
222222

223-
def is_sequential(self, password):
224-
if len(password) < 3:
225-
return False
226-
for i in range(len(password) - 2):
227-
if ord(password[i]) == ord(password[i + 1]) - 1 == ord(password[i + 2]) - 2:
228-
return True
229-
return False
230-
231223
def on_ok(self, evt):
232224
if self.client_or_server.GetSelection() == 0:
233225
if not self.panel.host.GetValue() or not self.panel.key.GetValue():
@@ -238,8 +230,9 @@ def on_ok(self, evt):
238230
gui.messageBox(_("The key must be longer than 6 characters."), _("Error"), wx.OK | wx.ICON_ERROR)
239231
self.panel.key.SetFocus()
240232
return
241-
elif self.is_sequential(self.panel.key.GetValue()):
242-
gui.messageBox(_("The key must not be sequential."), _("Error"), wx.OK | wx.ICON_ERROR)
233+
elif is_sequential(self.panel.key.GetValue()):
234+
# Translators: error message for key/password being sequential, example 123456
235+
gui.messageBox(_("The key must not be sequential. Please, avoid keys such as 1234, 4321 or similar."), _("Error"), wx.OK | wx.ICON_ERROR)
243236
self.panel.key.SetFocus()
244237
return
245238
elif self.client_or_server.GetSelection() == 1:
@@ -251,8 +244,9 @@ def on_ok(self, evt):
251244
gui.messageBox(_("The key must be longer than 6 characters."), _("Error"), wx.OK | wx.ICON_ERROR)
252245
self.panel.key.SetFocus()
253246
return
254-
elif self.is_sequential(self.panel.key.GetValue()):
255-
gui.messageBox(_("The key must not be sequential."), _("Error"), wx.OK | wx.ICON_ERROR)
247+
elif is_sequential(self.panel.key.GetValue()):
248+
# Translators: error message for key/password being sequential, example 123456
249+
gui.messageBox(_("The key must not be sequential. Please, avoid keys such as 1234, 4321 or similar."), _("Error"), wx.OK | wx.ICON_ERROR)
256250
self.panel.key.SetFocus()
257251
return
258252
evt.Skip()
@@ -388,9 +382,9 @@ def onSave(self):
388382
gui.messageBox(_("The key must be longer than 6 characters."), _("Error"), wx.OK | wx.ICON_ERROR)
389383
self.key.SetFocus()
390384
raise
391-
elif self.is_sequential(self.key.GetValue()):
385+
elif is_sequential(self.key.GetValue()):
392386
# Translators: error message for key/password being sequential, example 123456
393-
gui.messageBox(_("The key must not be sequential."), _("Error"), wx.OK | wx.ICON_ERROR)
387+
gui.messageBox(_("The key must not be sequential. Please, avoid keys such as 1234, 4321 or similar."), _("Error"), wx.OK | wx.ICON_ERROR)
394388
self.key.SetFocus()
395389
raise
396390
NVDAConfig.conf.profiles[-1].name = self.originalProfileName
@@ -415,14 +409,6 @@ def onSave(self):
415409
config['ui']['portcheck'] = self.portcheck.GetValue()
416410
config.write()
417411

418-
def is_sequential(self, password):
419-
if len(password) < 3:
420-
return False
421-
for i in range(len(password) - 2):
422-
if ord(password[i]) == ord(password[i + 1]) - 1 == ord(password[i + 2]) - 2:
423-
return True
424-
return False
425-
426412
class CertificateUnauthorizedDialog(wx.MessageDialog):
427413

428414
def __init__(self, parent, fingerprint=None):
@@ -432,3 +418,11 @@ def __init__(self, parent, fingerprint=None):
432418
message = _("Warning! The certificate of this server could not be verified.\nThis connection may not be secure. It is possible that someone is trying to overhear your communication.\nBefore continuing please make sure that the following server certificate fingerprint is a proper one.\nIf you have any questions, please contact the server administrator.\n\nServer SHA256 fingerprint: {fingerprint}\n\nDo you want to continue connecting?").format(fingerprint=fingerprint)
433419
super().__init__(parent, caption=title, message=message, style=wx.YES_NO|wx.CANCEL|wx.CANCEL_DEFAULT|wx.CENTRE)
434420
self.SetYesNoLabels(_("Connect and do not ask again for this server"), _("Connect"))
421+
422+
def is_sequential(password):
423+
if len(password) < 3:
424+
return False
425+
for i in range(len(password) - 2):
426+
if ord(password[i]) == ord(password[i + 1]) - 1 == ord(password[i + 2]) - 2:
427+
return True
428+
return False

0 commit comments

Comments
 (0)