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