Skip to content

Commit

Permalink
Replace spwd in examples with getpass
Browse files Browse the repository at this point in the history
spwd is removed in Python 3.13
  • Loading branch information
stefanor committed Oct 7, 2024
1 parent 45ab534 commit 16d72f9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions examples/the_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from __future__ import absolute_import
from __future__ import print_function

import getpass
import hashlib
import io
import os
import spwd

import mitogen.core
import mitogen.master
Expand Down Expand Up @@ -57,19 +57,17 @@ def streamy_download_file(context, path):
}


def get_password_hash(username):
def get_password(username):
"""
Fetch a user's password hash.
Ask a user for their password.
"""
try:
h = spwd.getspnam(username)
except KeyError:
return None

password = getpass.getpass("Password:")

# mitogen.core.Secret() is a Unicode subclass with a repr() that hides the
# secret data. This keeps secret stuff out of logs. Like blobs, secrets can
# also be serialized.
return mitogen.core.Secret(h)
return mitogen.core.Secret(password)


def md5sum(path):
Expand Down

0 comments on commit 16d72f9

Please sign in to comment.