jrnl.prompt   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 6

2 Functions

Rating   Name   Duplication   Size   Complexity  
A yesno() 0 4 1
A create_password() 0 18 5
1
import getpass
2
import sys
3
4
5
def create_password(
6
    journal_name: str, prompt: str = "Enter password for new journal: "
7
) -> str:
8
    while True:
9
        pw = getpass.getpass(prompt)
10
        if not pw:
11
            print("Password can't be an empty string!", file=sys.stderr)
12
            continue
13
        elif pw == getpass.getpass("Enter password again: "):
14
            break
15
16
        print("Passwords did not match, please try again", file=sys.stderr)
17
18
    if yesno("Do you want to store the password in your keychain?", default=True):
19
        from .EncryptedJournal import set_keychain
20
21
        set_keychain(journal_name, pw)
22
    return pw
23
24
25
def yesno(prompt, default=True):
26
    prompt = f"{prompt.strip()} {'[Y/n]' if default else '[y/N]'} "
27
    response = input(prompt)
28
    return {"y": True, "n": False}.get(response.lower().strip(), default)
29