2929try :
3030 import ldap
3131except ImportError as err :
32- logging .error ("You need to have python-ldap installed ({0 !s})." . format ( err ) )
32+ logging .error (f "You need to have python-ldap installed ({ err !s} )." )
3333 raise
3434
3535
@@ -157,28 +157,28 @@ def login(self, user_obj, **kw):
157157 if value is not None :
158158 ldap .set_option (option , value )
159159
160- logging .debug ("Trying to initialize {0 !r}." . format ( server ) )
160+ logging .debug (f "Trying to initialize { server !r} ." )
161161 conn = ldap .initialize (server )
162- logging .debug ("Connected to LDAP server {0 !r}." . format ( server ) )
162+ logging .debug (f "Connected to LDAP server { server !r} ." )
163163
164164 if self .start_tls and server .startswith ('ldap:' ):
165- logging .debug ("Trying to start TLS to {0 !r}." . format ( server ) )
165+ logging .debug (f "Trying to start TLS to { server !r} ." )
166166 try :
167167 conn .start_tls_s ()
168- logging .debug ("Using TLS to {0 !r}." . format ( server ) )
168+ logging .debug (f "Using TLS to { server !r} ." )
169169 except (ldap .SERVER_DOWN , ldap .CONNECT_ERROR ) as err :
170- logging .warning ("Couldn't establish TLS to {0 !r} (err: {1 !s})." . format ( server , err ) )
170+ logging .warning (f "Couldn't establish TLS to { server !r} (err: { err !s} )." )
171171 raise
172172
173173 # you can use %(username)s and %(password)s here to get the stuff entered in the form:
174174 binddn = self .bind_dn % locals ()
175175 bindpw = self .bind_pw % locals ()
176176 conn .simple_bind_s (binddn , bindpw )
177- logging .debug ("Bound with binddn {0 !r}" . format ( binddn ) )
177+ logging .debug (f "Bound with binddn { binddn !r} " )
178178
179179 # you can use %(username)s here to get the stuff entered in the form:
180180 filterstr = self .search_filter % locals ()
181- logging .debug ("Searching {0 !r}" . format ( filterstr ) )
181+ logging .debug (f "Searching { filterstr !r} " )
182182 attrs = [getattr (self , attr ) for attr in [
183183 'email_attribute' ,
184184 'displayname_attribute' ,
@@ -190,27 +190,26 @@ def login(self, user_obj, **kw):
190190 # we remove entries with dn == None to get the real result list:
191191 lusers = [(_dn , _ldap_dict ) for _dn , _ldap_dict in lusers if _dn is not None ]
192192 for _dn , _ldap_dict in lusers :
193- logging .debug ("dn:{0 !r}" . format ( _dn ) )
193+ logging .debug (f "dn:{ _dn !r} " )
194194 for key , val in _ldap_dict .items ():
195- logging .debug (" {0 !r}: {1 !r}" . format ( key , val ) )
195+ logging .debug (f " { key !r} : { val !r} " )
196196
197197 result_length = len (lusers )
198198 if result_length != 1 :
199199 if result_length > 1 :
200- logging .warning ("Search found more than one ({0}) matches for {1!r}." .format (
201- result_length , filterstr ))
200+ logging .warning (f"Search found more than one ({ result_length } ) matches for { filterstr !r} ." )
202201 if result_length == 0 :
203- logging .debug ("Search found no matches for {0 !r}." . format ( filterstr , ) )
202+ logging .debug (f "Search found no matches for { filterstr !r} ." )
204203 if self .report_invalid_credentials :
205204 return ContinueLogin (user_obj , _ ("Invalid username or password." ))
206205 else :
207206 return ContinueLogin (user_obj )
208207
209208 dn , ldap_dict = lusers [0 ]
210209 if not self .bind_once :
211- logging .debug ("DN found is {0 !r}, trying to bind with pw" . format ( dn ) )
210+ logging .debug (f "DN found is { dn !r} , trying to bind with pw" )
212211 conn .simple_bind_s (dn , password )
213- logging .debug ("Bound with dn {0 !r} (username: {1 !r})" . format ( dn , username ) )
212+ logging .debug (f "Bound with dn { dn !r} (username: { username !r} )" )
214213
215214 if self .email_callback is None :
216215 if self .email_attribute :
@@ -229,7 +228,7 @@ def login(self, user_obj, **kw):
229228 sn = ldap_dict .get (self .surname_attribute , ['' ])[0 ]
230229 gn = ldap_dict .get (self .givenname_attribute , ['' ])[0 ]
231230 if sn and gn :
232- display_name = "{0 }, {1}" . format ( sn , gn )
231+ display_name = f" { sn } , { gn } "
233232 elif sn :
234233 display_name = sn
235234
@@ -251,12 +250,11 @@ def login(self, user_obj, **kw):
251250 username , email , display_name ))
252251
253252 except ldap .INVALID_CREDENTIALS :
254- logging .debug ("invalid credentials (wrong password?) for dn {0!r} (username: {1!r})" .format (
255- dn , username ))
253+ logging .debug (f"invalid credentials (wrong password?) for dn { dn !r} (username: { username !r} )" )
256254 return CancelLogin (_ ("Invalid username or password." ))
257255
258256 if u and self .autocreate :
259- logging .debug ("calling create_or_update to autocreate user {0 !r}" . format ( u . name ) )
257+ logging .debug (f "calling create_or_update to autocreate user { u . name !r} " )
260258 u .create_or_update (True )
261259 return ContinueLogin (u )
262260
@@ -265,8 +263,7 @@ def login(self, user_obj, **kw):
265263 # authenticator object in cfg.auth list (there could be some second
266264 # ldap authenticator that queries a backup server or any other auth
267265 # method).
268- logging .error ("LDAP server {0} failed ({1!s}). "
269- "Trying to authenticate with next auth list entry." .format (server , err ))
266+ logging .error (f"LDAP server { server } failed ({ err !s} ). Trying to authenticate with next auth list entry." )
270267 return ContinueLogin (user_obj , _ ("LDAP server {server} failed." ).format (server = server ))
271268
272269 except : # noqa
0 commit comments