From 2d12335030a3a6fa7ad2762d1a19aeb54e47433d Mon Sep 17 00:00:00 2001 From: kakwa Date: Fri, 10 Jul 2015 21:01:39 +0200 Subject: [PATCH] pep 8 on ppolicy + docstrings --- ldapcherry/ppolicy/__init__.py | 24 ++++++++++++++++++++++-- ldapcherry/ppolicy/simple.py | 20 ++++++++++++-------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/ldapcherry/ppolicy/__init__.py b/ldapcherry/ppolicy/__init__.py index 4e137b7..9f50373 100644 --- a/ldapcherry/ppolicy/__init__.py +++ b/ldapcherry/ppolicy/__init__.py @@ -7,21 +7,41 @@ from ldapcherry.exceptions import MissingParameter + class PPolicy: def __init__(self, config, logger): + """ password policy constructor + @dict config: the configuration of the ppolicy + @logger logger: a python logger + """ pass def check(self, password): + """ check that a password match the ppolicy + @str password: the password to check + @rtype: dict with keys 'match' a boolean + (True if ppolicy matches, False otherwise) + and 'reason', an explaination string + """ ret = {'match': True, 'reason': 'no password policy'} def info(self): + """ gives information about the ppolicy + @rtype: a string describing the ppolicy + """ ret = "There is no password policy configured" def get_param(self, param, default=None): + """ + @str param: name of the paramter to recover + default: the default value, raises an exception + if param is not in configuration and default + is None (which is the default value). + """ if param in self.config: return self.config[param] - elif not default is None: + elif default is not None: return default else: - raise MissingParameter('ppolicy', param) + raise MissingParameter('ppolicy', param) diff --git a/ldapcherry/ppolicy/simple.py b/ldapcherry/ppolicy/simple.py index 8868927..e9a2cfd 100644 --- a/ldapcherry/ppolicy/simple.py +++ b/ldapcherry/ppolicy/simple.py @@ -8,6 +8,7 @@ import ldapcherry.ppolicy import re + class PPolicy(ldapcherry.ppolicy.PPolicy): def __init__(self, config, logger): @@ -20,17 +21,20 @@ class PPolicy(ldapcherry.ppolicy.PPolicy): if len(password) < self.min_length: return {'match': False, 'reason': 'password too short'} if len(re.findall(r'[A-Z]', password)) < self.min_upper: - return {'match': False, 'reason': 'not enough upper case characters'} + return { + 'match': False, + 'reason': 'not enough upper case characters' + } if len(re.findall(r'[0-9]', password)) < self.min_digit: return {'match': False, 'reason': 'not enough digits'} return {'match': True, 'reason': 'password ok'} def info(self): return \ -"* Minimum length: %(len)n\n\ -* Minimum number of uppercase characters: %(upper)n\n\ -* Minimum number of digits: %(digit)n" % { 'upper': self.min_upper, - 'len': self.min_length, - 'digit': self.min_digit, - } - + "* Minimum length: %(len)n\n"\ + "* Minimum number of uppercase characters: %(upper)n\n"\ + "* Minimum number of digits: %(digit)n" % { + 'upper': self.min_upper, + 'len': self.min_length, + 'digit': self.min_digit + }