22__all__ = ['LDAP' ]
33
44import re
5+ from functools import wraps
6+
57import ldap
68import ldap .filter
7- from functools import wraps
8- from flask import abort , current_app , g , make_response , redirect , url_for , request
9+ from flask import abort , current_app , g , make_response , redirect , url_for , \
10+ request
911
1012try :
1113 from flask import _app_ctx_stack as stack
@@ -202,8 +204,8 @@ def get_user_groups(self, user):
202204 [current_app .config ['LDAP_USER_GROUPS_FIELD' ]])
203205 conn .unbind_s ()
204206 if records :
205- if current_app .config ['LDAP_USER_GROUPS_FIELD' ] in records [ 0 ][
206- 1 ]:
207+ if current_app .config ['LDAP_USER_GROUPS_FIELD' ] in \
208+ records [ 0 ][ 1 ]:
207209 groups = records [0 ][1 ][
208210 current_app .config ['LDAP_USER_GROUPS_FIELD' ]]
209211 result = [re .findall ('(?:cn=|CN=)(.*?),' , group )[0 ] for
@@ -259,7 +261,8 @@ def login_required(func):
259261 @wraps (func )
260262 def wrapped (* args , ** kwargs ):
261263 if g .user is None :
262- return redirect (url_for (current_app .config ['LDAP_LOGIN_VIEW' ], next = request .path ))
264+ return redirect (url_for (current_app .config ['LDAP_LOGIN_VIEW' ],
265+ next = request .path ))
263266 return func (* args , ** kwargs )
264267
265268 return wrapped
@@ -272,7 +275,7 @@ def group_required(groups=None):
272275
273276 The login view is responsible for asking for credentials, checking
274277 them, and setting ``flask.g.user`` to the name of the authenticated
275- user and ``flask.g.ldap_groups`` to the authenticated's user's groups
278+ user and ``flask.g.ldap_groups`` to the authenticated user's groups
276279 if the credentials are acceptable.
277280
278281 :param list groups: List of groups that should be able to access the
@@ -284,7 +287,8 @@ def wrapper(func):
284287 def wrapped (* args , ** kwargs ):
285288 if g .user is None :
286289 return redirect (
287- url_for (current_app .config ['LDAP_LOGIN_VIEW' ], next = request .path ))
290+ url_for (current_app .config ['LDAP_LOGIN_VIEW' ],
291+ next = request .path ))
288292
289293 match = [group for group in groups if group in g .ldap_groups ]
290294 if not match :
0 commit comments