mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-46933: Make pwd module optional (GH-31700)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
parent
3b3be05a16
commit
ca9689f8da
11 changed files with 496 additions and 560 deletions
|
@ -241,7 +241,11 @@ def expanduser(path):
|
|||
i = len(path)
|
||||
if i == 1:
|
||||
if 'HOME' not in os.environ:
|
||||
import pwd
|
||||
try:
|
||||
import pwd
|
||||
except ImportError:
|
||||
# pwd module unavailable, return path unchanged
|
||||
return path
|
||||
try:
|
||||
userhome = pwd.getpwuid(os.getuid()).pw_dir
|
||||
except KeyError:
|
||||
|
@ -251,7 +255,11 @@ def expanduser(path):
|
|||
else:
|
||||
userhome = os.environ['HOME']
|
||||
else:
|
||||
import pwd
|
||||
try:
|
||||
import pwd
|
||||
except ImportError:
|
||||
# pwd module unavailable, return path unchanged
|
||||
return path
|
||||
name = path[1:i]
|
||||
if isinstance(name, bytes):
|
||||
name = str(name, 'ASCII')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue