From 8461dfc0a8f88f6829928ebed7bd0be753807da6 Mon Sep 17 00:00:00 2001
From: Jose Manuel Lopez Lujan <jm.lopez@utoronto.ca>
Date: Fri, 21 Aug 2015 14:38:51 -0400
Subject: [PATCH] - Three configuration directives have been added:
 LDAP_OPENLDAP,  LDAP_GROUP_MEMBER_FILTER, LDAP_GROUP_MEMBER_FILTER_FIELD -
 Examples: basic_auth/app_oldap.py and groups/app_oldap.py - Updated README.md
 with a more instructions - PEP8 check

closes #16
closes #15
closes #14
---
 flask_simpleldap/__init__.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/flask_simpleldap/__init__.py b/flask_simpleldap/__init__.py
index 150cb68..4f63560 100644
--- a/flask_simpleldap/__init__.py
+++ b/flask_simpleldap/__init__.py
@@ -1,14 +1,13 @@
 # -*- coding: utf-8 -*-
-__all__ = ['LDAP']
-
 import re
 from functools import wraps
-
 import ldap
 import ldap.filter
 from flask import abort, current_app, g, make_response, redirect, url_for, \
     request
 
+__all__ = ['LDAP']
+
 try:
     from flask import _app_ctx_stack as stack
 except ImportError:
@@ -187,7 +186,8 @@ class LDAP(object):
                         if records:
                             return records[0][0]
                     else:
-                        if current_app.config['LDAP_OBJECTS_DN'] in records[0][1]:
+                        if current_app.config['LDAP_OBJECTS_DN'] \
+                                in records[0][1]:
                             dn = records[0][1][
                                 current_app.config['LDAP_OBJECTS_DN']]
                             return dn[0]
@@ -207,23 +207,28 @@ class LDAP(object):
         conn = self.bind
         try:
             if current_app.config['LDAP_OPENLDAP']:
-                fields = [str(current_app.config['LDAP_GROUP_MEMBER_FILTER_FIELD'])]
+                fields = \
+                    [str(current_app.config['LDAP_GROUP_MEMBER_FILTER_FIELD'])]
                 records = conn.search_s(
                     current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE,
-                    ldap.filter.filter_format(current_app.config['LDAP_GROUP_MEMBER_FILTER'],
-                                              (self.get_object_details(user, dn_only=True),)),
+                    ldap.filter.filter_format(
+                        current_app.config['LDAP_GROUP_MEMBER_FILTER'],
+                        (self.get_object_details(user, dn_only=True),)),
                     fields)
             else:
                 records = conn.search_s(
                     current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE,
                     ldap.filter.filter_format(
-                        current_app.config['LDAP_USER_OBJECT_FILTER'], (user,)),
+                        current_app.config['LDAP_USER_OBJECT_FILTER'],
+                        (user,)),
                     [current_app.config['LDAP_USER_GROUPS_FIELD']])
 
             conn.unbind_s()
             if records:
                 if current_app.config['LDAP_OPENLDAP']:
-                    groups = [record[1][current_app.config['LDAP_GROUP_MEMBER_FILTER_FIELD']][0] for
+                    group_member_filter = \
+                        current_app.config['LDAP_GROUP_MEMBER_FILTER_FIELD']
+                    groups = [record[1][group_member_filter][0] for
                               record in records]
                     return groups
                 else:
-- 
GitLab