(self, length: int = DEFAULT_PASSWORD_LENGTH,
symbols: Optional[int] = None,
digits: Optional[int] = None,
caps: Optional[int] = None,
lower: Optional[int] = None,
special_characters: str = PW_SPECIAL_CHARACTERS)
| 103 | |
| 104 | class KeeperPasswordGenerator(PasswordGenerator): |
| 105 | def __init__(self, length: int = DEFAULT_PASSWORD_LENGTH, |
| 106 | symbols: Optional[int] = None, |
| 107 | digits: Optional[int] = None, |
| 108 | caps: Optional[int] = None, |
| 109 | lower: Optional[int] = None, |
| 110 | special_characters: str = PW_SPECIAL_CHARACTERS): |
| 111 | |
| 112 | sum_categories = sum((abs(i) if isinstance(i, int) else 0) for i in (symbols, digits, caps, lower)) |
| 113 | extra_count = length - sum_categories if length > sum_categories else 0 |
| 114 | extra_chars = '' |
| 115 | if symbols is None or isinstance(symbols, int) and symbols > 0: |
| 116 | extra_chars += special_characters |
| 117 | if digits is None or isinstance(digits, int) and digits > 0: |
| 118 | extra_chars += string.digits |
| 119 | if caps is None or isinstance(caps, int) and caps > 0: |
| 120 | extra_chars += string.ascii_uppercase |
| 121 | if lower is None or isinstance(lower, int) and lower > 0: |
| 122 | extra_chars += string.ascii_lowercase |
| 123 | if extra_count > 0 and not extra_chars: |
| 124 | if isinstance(symbols, int) and symbols < 0: |
| 125 | extra_chars += special_characters |
| 126 | if isinstance(digits, int) and digits < 0: |
| 127 | extra_chars += string.digits |
| 128 | if isinstance(caps, int) and caps < 0: |
| 129 | extra_chars += string.ascii_uppercase |
| 130 | if isinstance(lower, int) and lower < 0: |
| 131 | extra_chars += string.ascii_lowercase |
| 132 | |
| 133 | if extra_count > 0 and not extra_chars: |
| 134 | raise Exception('Password character set is empty') |
| 135 | self.category_map = [ |
| 136 | (abs(symbols) if isinstance(symbols, int) else 0, special_characters), |
| 137 | (abs(digits) if isinstance(digits, int) else 0, string.digits), |
| 138 | (abs(caps) if isinstance(caps, int) else 0, string.ascii_uppercase), |
| 139 | (abs(lower) if isinstance(lower, int) else 0, string.ascii_lowercase), |
| 140 | (extra_count, extra_chars) |
| 141 | ] |
| 142 | |
| 143 | def generate(self) -> str: |
| 144 | password_list = [] |
nothing calls this directly
no outgoing calls
no test coverage detected