From f988763daee7e1abda9ee084a398dfe249b39278 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= <ldachary@easter-eggs.com>
Date: Thu, 11 Feb 2021 15:53:57 +0100
Subject: [PATCH 2/4] ldap: do not use f'' for python 3.5 compatibility

---
 src/authentic2/backends/ldap_backend.py       | 11 +++----
 .../locale/fr/LC_MESSAGES/django.po           | 30 ++++++++++++-------
 tests/test_ldap.py                            | 18 +++++------
 3 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/src/authentic2/backends/ldap_backend.py b/src/authentic2/backends/ldap_backend.py
index 81ba48263..48651c192 100644
--- a/src/authentic2/backends/ldap_backend.py
+++ b/src/authentic2/backends/ldap_backend.py
@@ -252,16 +252,17 @@ def password_policy_control_messages(ctrl):
             'passwordTooYoung': _('It is too soon to change the password.'),
             'passwordInHistory': _('This password was recently used and cannot be used again.'),
         }
-        messages.append(error2message.get(error, _('Unexpected error {error}')))
+        messages.append(error2message.get(error, _('Unexpected error {error}').format(error=error)))
         return messages
 
     if ctrl.timeBeforeExpiration:
-        messages.append(_(f'The password will expire in {ctrl.timeBeforeExpiration} seconds.'))
+        messages.append(_('The password will expire in {timeBeforeExpiration} seconds.').format(
+            timeBeforeExpiration=ctrl.timeBeforeExpiration))
     if ctrl.graceAuthNsRemaining:
         messages.append(ngettext(
-            f'This is the last time this password can be used.',
-            f'This password can only be used {ctrl.graceAuthNsRemaining} times, including this one.',
-            ctrl.graceAuthNsRemaining))
+            'This is the last time this password can be used.',
+            'This password can only be used {graceAuthNsRemaining} times, including this one.',
+            ctrl.graceAuthNsRemaining).format(graceAuthNsRemaining=ctrl.graceAuthNsRemaining))
     return messages
 
 class LDAPUser(User):
diff --git a/src/authentic2/locale/fr/LC_MESSAGES/django.po b/src/authentic2/locale/fr/LC_MESSAGES/django.po
index af179fe1c..ad4366be2 100644
--- a/src/authentic2/locale/fr/LC_MESSAGES/django.po
+++ b/src/authentic2/locale/fr/LC_MESSAGES/django.po
@@ -856,23 +856,33 @@ msgstr "Le mot de passe est trop court."
 msgid "It is too soon to change the password."
 msgstr "Il est trop tôt pour changer ce mot de passe."
 
-#: src/authentic2/backends/ldap_backend.py:252
+#: src/authentic2/backends/ldap_backend.py:253
 msgid "This password was recently used and cannot be used again."
-msgstr "Ce mot de passe a été utilisé récemment et ne peut pas être utilisé de nouveau."
+msgstr ""
+"Ce mot de passe a été utilisé récemment et ne peut pas être utilisé de "
+"nouveau."
+
+#: src/authentic2/backends/ldap_backend.py:255
+#, python-brace-format
+msgid "Unexpected error {error}"
+msgstr "Erreur inattendue {error}"
 
-#: src/authentic2/backends/ldap_backend.py:258
+#: src/authentic2/backends/ldap_backend.py:259
 #, python-brace-format
-msgid "The password will expire in {ctrl.timeBeforeExpiration} seconds."
-msgstr "Le mot de passe expirera dans {ctrl.timeBeforeExpiration} secondes."
+msgid "The password will expire in {timeBeforeExpiration} seconds."
+msgstr "Le mot de passe expirera dans {timeBeforeExpiration} secondes."
 
-#: src/authentic2/backends/ldap_backend.py:261
+#: src/authentic2/backends/ldap_backend.py:263
 #, python-brace-format
 msgid "This is the last time this password can be used."
 msgid_plural ""
-"This password can only be used {ctrl.graceAuthNsRemaining} times, including "
-"this one."
-msgstr[0] "C'est la dernière fois qu'il est possible d'utiliser ce mot de passe."
-msgstr[1] "Ce mot de passe ne pourra être utilisé que {ctrl.graceAuthNsRemaining} fois, celle ci incluse."
+"This password can only be used {graceAuthNsRemaining} times, including this "
+"one."
+msgstr[0] ""
+"C'est la dernière fois qu'il est possible d'utiliser ce mot de passe."
+msgstr[1] ""
+"Ce mot de passe ne pourra être utilisé que {graceAuthNsRemaining} fois, "
+"celle ci incluse."
 
 #: src/authentic2/csv_import.py:157
 msgid "Cannot detect encoding"
diff --git a/tests/test_ldap.py b/tests/test_ldap.py
index 8d5dc77da..014d4190c 100644
--- a/tests/test_ldap.py
+++ b/tests/test_ldap.py
@@ -912,7 +912,7 @@ def test_login_ppolicy_pwdMaxFailure(slapd_ppolicy, settings, db, app):
     }]
 
     pwdMaxFailure = 2
-    slapd_ppolicy.add_ldif(f'''
+    slapd_ppolicy.add_ldif('''
 dn: cn=default,ou=ppolicies,o=ôrga
 cn: default
 objectclass: top
@@ -935,7 +935,7 @@ pwdFailureCountInterval: 0
 pwdMustChange: FALSE
 pwdAllowUserChange: FALSE
 pwdSafeModify: FALSE
-''')
+'''.format(pwdMaxFailure=pwdMaxFailure))
 
     for _ in range(pwdMaxFailure):
         response = app.get('/login/')
@@ -959,7 +959,7 @@ def test_authenticate_ppolicy_pwdMaxFailure(slapd_ppolicy, settings, db, caplog)
     }]
 
     pwdMaxFailure = 2
-    slapd_ppolicy.add_ldif(f'''
+    slapd_ppolicy.add_ldif('''
 dn: cn=default,ou=ppolicies,o=ôrga
 cn: default
 objectclass: top
@@ -982,7 +982,7 @@ pwdFailureCountInterval: 0
 pwdMustChange: FALSE
 pwdAllowUserChange: FALSE
 pwdSafeModify: FALSE
-''')
+'''.format(pwdMaxFailure=pwdMaxFailure))
 
     for _ in range(pwdMaxFailure):
         assert authenticate(username=USERNAME, password='incorrect') is None
@@ -1001,7 +1001,7 @@ def test_authenticate_ppolicy_pwdGraceAuthnLimit(slapd_ppolicy, settings, db, ca
 
     pwdMaxAge = 1
     pwdGraceAuthnLimit = 2
-    slapd_ppolicy.add_ldif(f'''
+    slapd_ppolicy.add_ldif('''
 dn: cn=default,ou=ppolicies,o=ôrga
 cn: default
 objectclass: top
@@ -1024,7 +1024,7 @@ pwdFailureCountInterval: 0
 pwdMustChange: FALSE
 pwdAllowUserChange: TRUE
 pwdSafeModify: FALSE
-''')
+'''.format(pwdMaxAge=pwdMaxAge, pwdGraceAuthnLimit=pwdGraceAuthnLimit))
 
     user = authenticate(username=USERNAME, password=UPASS)
     assert user.check_password(UPASS)
@@ -1050,7 +1050,7 @@ def test_authenticate_ppolicy_pwdExpireWarning(slapd_ppolicy, settings, db, capl
     }]
 
     pwdMaxAge = 3600
-    slapd_ppolicy.add_ldif(f'''
+    slapd_ppolicy.add_ldif('''
 dn: cn=default,ou=ppolicies,o=ôrga
 cn: default
 objectclass: top
@@ -1073,7 +1073,7 @@ pwdFailureCountInterval: 0
 pwdMustChange: FALSE
 pwdAllowUserChange: TRUE
 pwdSafeModify: FALSE
-''')
+'''.format(pwdMaxAge=pwdMaxAge))
 
     user = authenticate(username=USERNAME, password=UPASS)
     assert user.check_password(UPASS)
@@ -1094,7 +1094,7 @@ def test_authenticate_ppolicy_pwdAllowUserChange(slapd_ppolicy, settings, db, ca
         'use_tls': False,
     }]
 
-    slapd_ppolicy.add_ldif(f'''
+    slapd_ppolicy.add_ldif('''
 dn: cn=default,ou=ppolicies,o=ôrga
 cn: default
 objectclass: top
-- 
2.25.1

