summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-03-23 16:42:51 (GMT)
committerGitHub <noreply@github.com>2021-03-23 16:42:51 (GMT)
commitd72e8d487553c103bf2742e229f8266b515fd951 (patch)
treec0cec7aa275f3bcb12d26e6535aaea7f3a6ad3e2 /Lib/shutil.py
parent76b5d714e4e2b9f3b63847325cba51d4c4dc36bc (diff)
downloadcpython-d72e8d487553c103bf2742e229f8266b515fd951.zip
cpython-d72e8d487553c103bf2742e229f8266b515fd951.tar.gz
cpython-d72e8d487553c103bf2742e229f8266b515fd951.tar.bz2
bpo-41718: subprocess imports grp and pwd on demand (GH-24987)
The shutil and subprocess modules now only import the grp and pwd modules when they are needed, which is not the case by default in subprocess.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 89d924d..e29fe4d 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -32,16 +32,6 @@ try:
except ImportError:
_LZMA_SUPPORTED = False
-try:
- from pwd import getpwnam
-except ImportError:
- getpwnam = None
-
-try:
- from grp import getgrnam
-except ImportError:
- getgrnam = None
-
_WINDOWS = os.name == 'nt'
posix = nt = None
if os.name == 'posix':
@@ -843,8 +833,14 @@ def _is_immutable(src):
def _get_gid(name):
"""Returns a gid, given a group name."""
- if getgrnam is None or name is None:
+ if name is None:
+ return None
+
+ try:
+ from grp import getgrnam
+ except ImportError:
return None
+
try:
result = getgrnam(name)
except KeyError:
@@ -855,8 +851,14 @@ def _get_gid(name):
def _get_uid(name):
"""Returns an uid, given a user name."""
- if getpwnam is None or name is None:
+ if name is None:
return None
+
+ try:
+ from pwd import getpwnam
+ except ImportError:
+ return None
+
try:
result = getpwnam(name)
except KeyError: