mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 09:24:21 +01:00
pep8
This commit is contained in:
parent
be598b0129
commit
3d6e24eb73
@ -173,7 +173,7 @@ class LdapCherry(object):
|
||||
try:
|
||||
self.backends_display_names[backend] = \
|
||||
self.backends_params[backend]['display_name']
|
||||
except:
|
||||
except Exception as e:
|
||||
self.backends_display_names[backend] = backend
|
||||
self.backends_params[backend]['display_name'] = backend
|
||||
params = self.backends_params[backend]
|
||||
@ -225,7 +225,7 @@ class LdapCherry(object):
|
||||
)
|
||||
try:
|
||||
pp = __import__(module, globals(), locals(), ['PPolicy'], 0)
|
||||
except:
|
||||
except Exception as e:
|
||||
raise BackendModuleLoadingFail(module)
|
||||
if 'ppolicy' in config:
|
||||
ppcfg = config['ppolicy']
|
||||
@ -1091,7 +1091,7 @@ class LdapCherry(object):
|
||||
is_admin = self._check_admin()
|
||||
try:
|
||||
referer = cherrypy.request.headers['Referer']
|
||||
except:
|
||||
except Exception as e:
|
||||
referer = '/'
|
||||
self._deleteuser(user)
|
||||
self._add_notification('User Deleted')
|
||||
@ -1110,7 +1110,7 @@ class LdapCherry(object):
|
||||
self._add_notification("User modified")
|
||||
try:
|
||||
referer = cherrypy.request.headers['Referer']
|
||||
except:
|
||||
except Exception as e:
|
||||
referer = '/'
|
||||
raise cherrypy.HTTPRedirect(referer)
|
||||
|
||||
|
@ -33,7 +33,7 @@ class Attributes:
|
||||
self.key = None
|
||||
try:
|
||||
stream = open(attributes_file, 'r')
|
||||
except:
|
||||
except Exception as e:
|
||||
raise MissingAttributesFile(attributes_file)
|
||||
try:
|
||||
self.attributes = loadNoDump(stream)
|
||||
@ -71,7 +71,7 @@ class Attributes:
|
||||
raise MissingUserKey()
|
||||
|
||||
def _is_email(self, email):
|
||||
pattern = '[\.\w]{1,}[@]\w+[.]\w+'
|
||||
pattern = r'[\.\w]{1,}[@]\w+[.]\w+'
|
||||
if re.match(pattern, email):
|
||||
return True
|
||||
else:
|
||||
|
@ -9,14 +9,13 @@
|
||||
|
||||
|
||||
import sys
|
||||
if sys.version < '3':
|
||||
from sets import Set as set
|
||||
|
||||
import ldapcherry.backend
|
||||
from ldapcherry.exceptions import UserDoesntExist, \
|
||||
GroupDoesntExist, MissingParameter, \
|
||||
UserAlreadyExists
|
||||
import re
|
||||
if sys.version < '3':
|
||||
from sets import Set as set
|
||||
|
||||
|
||||
class Backend(ldapcherry.backend.Backend):
|
||||
@ -41,13 +40,17 @@ class Backend(ldapcherry.backend.Backend):
|
||||
self.backend_name = name
|
||||
admin_user = self.get_param('admin.user', 'admin')
|
||||
admin_password = self.get_param('admin.password', 'admin')
|
||||
admin_groups = set(self._basic_splitter(self.get_param('admin.groups')))
|
||||
admin_groups = set(
|
||||
self._basic_splitter(self.get_param('admin.groups'))
|
||||
)
|
||||
basic_user = self.get_param('basic.user', 'user')
|
||||
basic_password = self.get_param('basic.password', 'user')
|
||||
basic_groups = set(self._basic_splitter(self.get_param('basic.groups')))
|
||||
basic_groups = set(
|
||||
self._basic_splitter(self.get_param('basic.groups'))
|
||||
)
|
||||
pwd_attr = self.get_param('pwd_attr')
|
||||
self.search_attrs = set(
|
||||
re.split('\W+', self.get_param('search_attributes')),
|
||||
re.split(r'\W+', self.get_param('search_attributes')),
|
||||
)
|
||||
self.pwd_attr = pwd_attr
|
||||
self.admin_user = admin_user
|
||||
@ -66,7 +69,8 @@ class Backend(ldapcherry.backend.Backend):
|
||||
|
||||
@staticmethod
|
||||
def _basic_splitter(in_str):
|
||||
return [re.sub(r'(?<!\\)\\', '', x) for x in re.split(r'(?<!\\),\W*', in_str)]
|
||||
return [re.sub(r'(?<!\\)\\', '', x)
|
||||
for x in re.split(r'(?<!\\),\W*', in_str)]
|
||||
|
||||
def _check_fix_users(self, username):
|
||||
if self.admin_user == username or self.basic_user == username:
|
||||
@ -111,7 +115,7 @@ class Backend(ldapcherry.backend.Backend):
|
||||
self._check_fix_users(username)
|
||||
try:
|
||||
del self.users[username]
|
||||
except:
|
||||
except Exception as e:
|
||||
raise UserDoesntExist(username, self.backend_name)
|
||||
|
||||
def set_attrs(self, username, attrs):
|
||||
@ -184,7 +188,7 @@ class Backend(ldapcherry.backend.Backend):
|
||||
"""
|
||||
try:
|
||||
return self.users[username]
|
||||
except:
|
||||
except Exception as e:
|
||||
raise UserDoesntExist(username, self.backend_name)
|
||||
|
||||
def get_groups(self, username):
|
||||
@ -196,5 +200,5 @@ class Backend(ldapcherry.backend.Backend):
|
||||
"""
|
||||
try:
|
||||
return self.users[username]['groups']
|
||||
except:
|
||||
except Exception as e:
|
||||
raise UserDoesntExist(username, self.backend_name)
|
||||
|
@ -12,14 +12,13 @@ import ldap.filter
|
||||
import logging
|
||||
import ldapcherry.backend
|
||||
import sys
|
||||
if sys.version < '3':
|
||||
from sets import Set as set
|
||||
|
||||
from ldapcherry.exceptions import UserDoesntExist, \
|
||||
GroupDoesntExist, \
|
||||
UserAlreadyExists
|
||||
import os
|
||||
import re
|
||||
if sys.version < '3':
|
||||
from sets import Set as set
|
||||
|
||||
|
||||
class CaFileDontExist(Exception):
|
||||
@ -74,7 +73,7 @@ class Backend(ldapcherry.backend.Backend):
|
||||
self.key = key
|
||||
# objectclasses parameter is a coma separated list in configuration
|
||||
# split it to get a real list, and convert it to bytes
|
||||
for o in re.split('\W+', self.get_param('objectclasses')):
|
||||
for o in re.split(r'\W+', self.get_param('objectclasses')):
|
||||
self.objectclasses.append(self._str(o))
|
||||
self.group_attrs = {}
|
||||
self.group_attrs_keys = set([])
|
||||
|
@ -9,14 +9,14 @@ import os
|
||||
import sys
|
||||
import copy
|
||||
|
||||
if sys.version < '3':
|
||||
from sets import Set as set
|
||||
|
||||
from ldapcherry.pyyamlwrapper import loadNoDump
|
||||
from ldapcherry.pyyamlwrapper import DumplicatedKey
|
||||
from ldapcherry.exceptions import *
|
||||
import yaml
|
||||
|
||||
if sys.version < '3':
|
||||
from sets import Set as set
|
||||
|
||||
|
||||
class CustomDumper(yaml.SafeDumper):
|
||||
"A custom YAML dumper that never emits aliases"
|
||||
@ -32,7 +32,7 @@ class Roles:
|
||||
self.backends = set([])
|
||||
try:
|
||||
stream = open(role_file, 'r')
|
||||
except:
|
||||
except Exception as e:
|
||||
raise MissingRolesFile(role_file)
|
||||
try:
|
||||
self.roles_raw = loadNoDump(stream)
|
||||
|
Loading…
Reference in New Issue
Block a user