Commits

Peter Sagerson committed f3464eb

Minor pep8 cleanup.

  • Participants
  • Parent commits ec00812

Comments (0)

Files changed (4)

django_auth_ldap/backend.py

     supports_inactive_user = False
 
     _settings = None
-    _ldap = None # The cached ldap module (or mock object)
+    _ldap = None  # The cached ldap module (or mock object)
 
     # This is prepended to our internal setting names to produce the names we
     # expect in Django's settings file. Subclasses can change this in order to
 
         try:
             user = self.get_user_model().objects.get(pk=user_id)
-            _LDAPUser(self, user=user) # This sets user.ldap_user
+            _LDAPUser(self, user=user)  # This sets user.ldap_user
         except ObjectDoesNotExist:
             pass
 
 
     def get_group_permissions(self, user, obj=None):
         if not hasattr(user, 'ldap_user') and self.settings.AUTHORIZE_ALL_USERS:
-            _LDAPUser(self, user=user) # This sets user.ldap_user
+            _LDAPUser(self, user=user)  # This sets user.ldap_user
 
         if hasattr(user, 'ldap_user'):
             return user.ldap_user.get_group_permissions()
             logger.debug(u"Authentication failed for %s" % self._username)
         except self.ldap.LDAPError, e:
             logger.warning(u"Caught LDAPError while authenticating %s: %s",
-                self._username, pprint.pformat(e))
+                           self._username, pprint.pformat(e))
         except Exception:
             logger.exception(u"Caught Exception while authenticating %s",
-                self._username)
+                             self._username)
             raise
 
         return user
                     self._load_group_permissions()
                 except self.ldap.LDAPError, e:
                     logger.warning("Caught LDAPError loading group permissions: %s",
-                        pprint.pformat(e))
+                                   pprint.pformat(e))
 
         return self._group_permissions
 
             user = self._user
         except self.ldap.LDAPError, e:
             logger.warning(u"Caught LDAPError while authenticating %s: %s",
-                self._username, pprint.pformat(e))
+                           self._username, pprint.pformat(e))
         except Exception, e:
             logger.error(u"Caught Exception while authenticating %s: %s",
-                self._username, pprint.pformat(e))
+                         self._username, pprint.pformat(e))
             logger.error(''.join(traceback.format_tb(sys.exc_info()[2])))
             raise
 
         """
         group_names = self._get_groups().get_group_names()
         groups = [Group.objects.get_or_create(name=group_name)[0] for group_name
-            in group_names]
+                  in group_names]
 
         self._user.groups = groups
 
         """
         group_names = self._get_groups().get_group_names()
 
-        perms = Permission.objects.filter(group__name__in=group_names
-            ).values_list('content_type__app_label', 'codename'
-            ).order_by()
+        perms = Permission.objects.filter(group__name__in=group_names)
+        perms = perms.values_list('content_type__app_label', 'codename')
+        perms = perms.order_by()
 
         self._group_permissions = set(["%s.%s" % (ct, name) for ct, name in perms])
 
         Binds to the LDAP server with AUTH_LDAP_BIND_DN and
         AUTH_LDAP_BIND_PASSWORD.
         """
-        self._bind_as(self.settings.BIND_DN,
-            self.settings.BIND_PASSWORD,
-            sticky=True)
+        self._bind_as(self.settings.BIND_DN, self.settings.BIND_PASSWORD,
+                      sticky=True)
 
     def _bind_as(self, bind_dn, bind_password, sticky=False):
         """
         the credentials, after which the connection will be considered unbound.
         """
         self._get_connection().simple_bind_s(bind_dn.encode('utf-8'),
-            bind_password.encode('utf-8'))
+                                             bind_password.encode('utf-8'))
 
         self._connection_bound = sticky
 
 
         if self._group_names is None:
             group_infos = self._get_group_infos()
-            self._group_names = set([self._group_type.group_name_from_info(group_info)
-                for group_info in group_infos])
+            self._group_names = set(
+                self._group_type.group_name_from_info(group_info)
+                for group_info in group_infos
+            )
             self._cache_attr("_group_names")
 
         return self._group_names
         """
         if self._group_dns is None:
             group_infos = self._get_group_infos()
-            self._group_dns = set([group_info[0] for group_info in group_infos])
+            self._group_dns = set(group_info[0] for group_info in group_infos)
 
         return self._group_dns
 
         """
         if self._group_infos is None:
             self._group_infos = self._group_type.user_groups(self._ldap_user,
-                self._group_search)
+                                                             self._group_search)
 
         return self._group_infos
 

django_auth_ldap/config.py

         try:
             filterstr = self.filterstr % filterargs
             results = connection.search_s(self.base_dn.encode('utf-8'),
-                self.scope, filterstr.encode('utf-8'))
+                                          self.scope,
+                                          filterstr.encode('utf-8'))
         except self.ldap.LDAPError, e:
             results = []
             logger.error(u"search_s('%s', %d, '%s') raised %s" %
-                (self.base_dn, self.scope, filterstr, pprint.pformat(e)))
+                         (self.base_dn, self.scope, filterstr, pprint.pformat(e)))
 
         return self._process_results(results)
 
         try:
             filterstr = self.filterstr % filterargs
             msgid = connection.search(self.base_dn.encode('utf-8'),
-                self.scope, filterstr.encode('utf-8'))
+                                      self.scope, filterstr.encode('utf-8'))
         except self.ldap.LDAPError, e:
             msgid = None
             logger.error(u"search('%s', %d, '%s') raised %s" %
-                (self.base_dn, self.scope, filterstr, pprint.pformat(e)))
+                         (self.base_dn, self.scope, filterstr, pprint.pformat(e)))
 
         return msgid
 
 
         result_dns = [result[0] for result in results]
         logger.debug(u"search_s('%s', %d, '%s') returned %d objects: %s" %
-            (self.base_dn, self.scope, self.filterstr, len(result_dns), "; ".join(result_dns)))
+                     (self.base_dn, self.scope, self.filterstr, len(result_dns),
+                      "; ".join(result_dns)))
 
         return results
 
         those groups belong to, etc. Circular references will be detected and
         pruned.
         """
-        group_info_map = {} # Maps group_dn to group_info of groups we've found
-        member_dn_set = set([ldap_user.dn]) # Member DNs to search with next
-        handled_dn_set = set() # Member DNs that we've already searched with
+        group_info_map = {}  # Maps group_dn to group_info of groups we've found
+        member_dn_set = set([ldap_user.dn])  # Member DNs to search with next
+        handled_dn_set = set()  # Member DNs that we've already searched with
 
         while len(member_dn_set) > 0:
             group_infos = self.find_groups_with_any_member(member_dn_set,
-                group_search, ldap_user.connection)
+                                                           group_search,
+                                                           ldap_user.connection)
             new_group_info_map = dict([(info[0], info) for info in group_infos])
             group_info_map.update(new_group_info_map)
             handled_dn_set.update(member_dn_set)

django_auth_ldap/dn.py

 (often naive) implementations of the methods we care about.
 """
 
+
 def escape_dn_chars(dn):
     "Old versions of python-ldap won't get DN escaping. Use with care."
     return dn
+[flake8]
+ignore = E501