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':
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:
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:
from time import monotonic as _time
import types
-try:
- import pwd
-except ImportError:
- pwd = None
-try:
- import grp
-except ImportError:
- grp = None
try:
import fcntl
except ImportError:
"current platform")
elif isinstance(group, str):
- if grp is None:
+ try:
+ import grp
+ except ImportError:
raise ValueError("The group parameter cannot be a string "
"on systems without the grp module")
gids = []
for extra_group in extra_groups:
if isinstance(extra_group, str):
- if grp is None:
+ try:
+ import grp
+ except ImportError:
raise ValueError("Items in extra_groups cannot be "
"strings on systems without the "
"grp module")
"the current platform")
elif isinstance(user, str):
- if pwd is None:
+ try:
+ import pwd
+ except ImportError:
raise ValueError("The user parameter cannot be a string "
"on systems without the pwd module")
-
uid = pwd.getpwnam(user).pw_uid
elif isinstance(user, int):
uid = user