Project

General

Profile

0002-ldap-do-not-use-f-for-python-3.5-compatibility.patch

Loïc Dachary, 11 February 2021 04:10 PM

Download (6.67 KB)

View differences:

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(-)
src/authentic2/backends/ldap_backend.py
252 252
            'passwordTooYoung': _('It is too soon to change the password.'),
253 253
            'passwordInHistory': _('This password was recently used and cannot be used again.'),
254 254
        }
255
        messages.append(error2message.get(error, _('Unexpected error {error}')))
255
        messages.append(error2message.get(error, _('Unexpected error {error}').format(error=error)))
256 256
        return messages
257 257

  
258 258
    if ctrl.timeBeforeExpiration:
259
        messages.append(_(f'The password will expire in {ctrl.timeBeforeExpiration} seconds.'))
259
        messages.append(_('The password will expire in {timeBeforeExpiration} seconds.').format(
260
            timeBeforeExpiration=ctrl.timeBeforeExpiration))
260 261
    if ctrl.graceAuthNsRemaining:
261 262
        messages.append(ngettext(
262
            f'This is the last time this password can be used.',
263
            f'This password can only be used {ctrl.graceAuthNsRemaining} times, including this one.',
264
            ctrl.graceAuthNsRemaining))
263
            'This is the last time this password can be used.',
264
            'This password can only be used {graceAuthNsRemaining} times, including this one.',
265
            ctrl.graceAuthNsRemaining).format(graceAuthNsRemaining=ctrl.graceAuthNsRemaining))
265 266
    return messages
266 267

  
267 268
class LDAPUser(User):
src/authentic2/locale/fr/LC_MESSAGES/django.po
856 856
msgid "It is too soon to change the password."
857 857
msgstr "Il est trop tôt pour changer ce mot de passe."
858 858

  
859
#: src/authentic2/backends/ldap_backend.py:252
859
#: src/authentic2/backends/ldap_backend.py:253
860 860
msgid "This password was recently used and cannot be used again."
861
msgstr "Ce mot de passe a été utilisé récemment et ne peut pas être utilisé de nouveau."
861
msgstr ""
862
"Ce mot de passe a été utilisé récemment et ne peut pas être utilisé de "
863
"nouveau."
864

  
865
#: src/authentic2/backends/ldap_backend.py:255
866
#, python-brace-format
867
msgid "Unexpected error {error}"
868
msgstr "Erreur inattendue {error}"
862 869

  
863
#: src/authentic2/backends/ldap_backend.py:258
870
#: src/authentic2/backends/ldap_backend.py:259
864 871
#, python-brace-format
865
msgid "The password will expire in {ctrl.timeBeforeExpiration} seconds."
866
msgstr "Le mot de passe expirera dans {ctrl.timeBeforeExpiration} secondes."
872
msgid "The password will expire in {timeBeforeExpiration} seconds."
873
msgstr "Le mot de passe expirera dans {timeBeforeExpiration} secondes."
867 874

  
868
#: src/authentic2/backends/ldap_backend.py:261
875
#: src/authentic2/backends/ldap_backend.py:263
869 876
#, python-brace-format
870 877
msgid "This is the last time this password can be used."
871 878
msgid_plural ""
872
"This password can only be used {ctrl.graceAuthNsRemaining} times, including "
873
"this one."
874
msgstr[0] "C'est la dernière fois qu'il est possible d'utiliser ce mot de passe."
875
msgstr[1] "Ce mot de passe ne pourra être utilisé que {ctrl.graceAuthNsRemaining} fois, celle ci incluse."
879
"This password can only be used {graceAuthNsRemaining} times, including this "
880
"one."
881
msgstr[0] ""
882
"C'est la dernière fois qu'il est possible d'utiliser ce mot de passe."
883
msgstr[1] ""
884
"Ce mot de passe ne pourra être utilisé que {graceAuthNsRemaining} fois, "
885
"celle ci incluse."
876 886

  
877 887
#: src/authentic2/csv_import.py:157
878 888
msgid "Cannot detect encoding"
tests/test_ldap.py
912 912
    }]
913 913

  
914 914
    pwdMaxFailure = 2
915
    slapd_ppolicy.add_ldif(f'''
915
    slapd_ppolicy.add_ldif('''
916 916
dn: cn=default,ou=ppolicies,o=ôrga
917 917
cn: default
918 918
objectclass: top
......
935 935
pwdMustChange: FALSE
936 936
pwdAllowUserChange: FALSE
937 937
pwdSafeModify: FALSE
938
''')
938
'''.format(pwdMaxFailure=pwdMaxFailure))
939 939

  
940 940
    for _ in range(pwdMaxFailure):
941 941
        response = app.get('/login/')
......
959 959
    }]
960 960

  
961 961
    pwdMaxFailure = 2
962
    slapd_ppolicy.add_ldif(f'''
962
    slapd_ppolicy.add_ldif('''
963 963
dn: cn=default,ou=ppolicies,o=ôrga
964 964
cn: default
965 965
objectclass: top
......
982 982
pwdMustChange: FALSE
983 983
pwdAllowUserChange: FALSE
984 984
pwdSafeModify: FALSE
985
''')
985
'''.format(pwdMaxFailure=pwdMaxFailure))
986 986

  
987 987
    for _ in range(pwdMaxFailure):
988 988
        assert authenticate(username=USERNAME, password='incorrect') is None
......
1001 1001

  
1002 1002
    pwdMaxAge = 1
1003 1003
    pwdGraceAuthnLimit = 2
1004
    slapd_ppolicy.add_ldif(f'''
1004
    slapd_ppolicy.add_ldif('''
1005 1005
dn: cn=default,ou=ppolicies,o=ôrga
1006 1006
cn: default
1007 1007
objectclass: top
......
1024 1024
pwdMustChange: FALSE
1025 1025
pwdAllowUserChange: TRUE
1026 1026
pwdSafeModify: FALSE
1027
''')
1027
'''.format(pwdMaxAge=pwdMaxAge, pwdGraceAuthnLimit=pwdGraceAuthnLimit))
1028 1028

  
1029 1029
    user = authenticate(username=USERNAME, password=UPASS)
1030 1030
    assert user.check_password(UPASS)
......
1050 1050
    }]
1051 1051

  
1052 1052
    pwdMaxAge = 3600
1053
    slapd_ppolicy.add_ldif(f'''
1053
    slapd_ppolicy.add_ldif('''
1054 1054
dn: cn=default,ou=ppolicies,o=ôrga
1055 1055
cn: default
1056 1056
objectclass: top
......
1073 1073
pwdMustChange: FALSE
1074 1074
pwdAllowUserChange: TRUE
1075 1075
pwdSafeModify: FALSE
1076
''')
1076
'''.format(pwdMaxAge=pwdMaxAge))
1077 1077

  
1078 1078
    user = authenticate(username=USERNAME, password=UPASS)
1079 1079
    assert user.check_password(UPASS)
......
1094 1094
        'use_tls': False,
1095 1095
    }]
1096 1096

  
1097
    slapd_ppolicy.add_ldif(f'''
1097
    slapd_ppolicy.add_ldif('''
1098 1098
dn: cn=default,ou=ppolicies,o=ôrga
1099 1099
cn: default
1100 1100
objectclass: top
1101
-