|
|
@@ -4,12 +4,16 @@ Platform-specific APIs.
|
|
|
Public APIs are documented in platform.base.
|
|
|
"""
|
|
|
|
|
|
+from types import ModuleType
|
|
|
+
|
|
|
from ..platformflags import is_win32, is_linux, is_freebsd, is_netbsd, is_darwin, is_cygwin
|
|
|
|
|
|
from .base import ENOATTR, API_VERSION
|
|
|
from .base import SaveFile, sync_dir, fdatasync, safe_fadvise
|
|
|
from .base import get_process_id, fqdn, hostname, hostid
|
|
|
|
|
|
+platform_ug: ModuleType | None = None # make mypy happy
|
|
|
+
|
|
|
if is_linux: # pragma: linux only
|
|
|
from .linux import API_VERSION as OS_API_VERSION
|
|
|
from .linux import listxattr, getxattr, setxattr
|
|
|
@@ -19,7 +23,8 @@ if is_linux: # pragma: linux only
|
|
|
from .posix import process_alive, local_pid_alive
|
|
|
from .posix import swidth
|
|
|
from .posix import get_errno
|
|
|
- from .posix import uid2user, user2uid, gid2group, group2gid, getosusername
|
|
|
+ from .posix import getosusername
|
|
|
+ from . import posix_ug as platform_ug
|
|
|
elif is_freebsd: # pragma: freebsd only
|
|
|
from .freebsd import API_VERSION as OS_API_VERSION
|
|
|
from .freebsd import listxattr, getxattr, setxattr
|
|
|
@@ -30,7 +35,8 @@ elif is_freebsd: # pragma: freebsd only
|
|
|
from .posix import process_alive, local_pid_alive
|
|
|
from .posix import swidth
|
|
|
from .posix import get_errno
|
|
|
- from .posix import uid2user, user2uid, gid2group, group2gid, getosusername
|
|
|
+ from .posix import getosusername
|
|
|
+ from . import posix_ug as platform_ug
|
|
|
elif is_netbsd: # pragma: netbsd only
|
|
|
from .netbsd import API_VERSION as OS_API_VERSION
|
|
|
from .netbsd import listxattr, getxattr, setxattr
|
|
|
@@ -40,7 +46,8 @@ elif is_netbsd: # pragma: netbsd only
|
|
|
from .posix import process_alive, local_pid_alive
|
|
|
from .posix import swidth
|
|
|
from .posix import get_errno
|
|
|
- from .posix import uid2user, user2uid, gid2group, group2gid, getosusername
|
|
|
+ from .posix import getosusername
|
|
|
+ from . import posix_ug as platform_ug
|
|
|
elif is_darwin: # pragma: darwin only
|
|
|
from .darwin import API_VERSION as OS_API_VERSION
|
|
|
from .darwin import listxattr, getxattr, setxattr
|
|
|
@@ -52,7 +59,8 @@ elif is_darwin: # pragma: darwin only
|
|
|
from .posix import process_alive, local_pid_alive
|
|
|
from .posix import swidth
|
|
|
from .posix import get_errno
|
|
|
- from .posix import uid2user, user2uid, gid2group, group2gid, getosusername
|
|
|
+ from .posix import getosusername
|
|
|
+ from . import posix_ug as platform_ug
|
|
|
elif not is_win32: # pragma: posix only
|
|
|
# Generic code for all other POSIX OSes
|
|
|
OS_API_VERSION = API_VERSION
|
|
|
@@ -63,7 +71,8 @@ elif not is_win32: # pragma: posix only
|
|
|
from .posix import process_alive, local_pid_alive
|
|
|
from .posix import swidth
|
|
|
from .posix import get_errno
|
|
|
- from .posix import uid2user, user2uid, gid2group, group2gid, getosusername
|
|
|
+ from .posix import getosusername
|
|
|
+ from . import posix_ug as platform_ug
|
|
|
else: # pragma: win32 only
|
|
|
# Win32-specific stuff
|
|
|
OS_API_VERSION = API_VERSION
|
|
|
@@ -73,7 +82,8 @@ else: # pragma: win32 only
|
|
|
from .base import SyncFile
|
|
|
from .windows import process_alive, local_pid_alive
|
|
|
from .base import swidth
|
|
|
- from .windows import uid2user, user2uid, gid2group, group2gid, getosusername
|
|
|
+ from .windows import getosusername
|
|
|
+ from . import windows_ug as platform_ug
|
|
|
|
|
|
|
|
|
def get_birthtime_ns(st, path, fd=None):
|
|
|
@@ -86,3 +96,21 @@ def get_birthtime_ns(st, path, fd=None):
|
|
|
return int(st.st_birthtime * 10**9)
|
|
|
else:
|
|
|
return None
|
|
|
+
|
|
|
+
|
|
|
+# have some wrapper functions, so we can monkeypatch the functions in platform_ug.
|
|
|
+# for normal usage from outside the platform package, always import these:
|
|
|
+def uid2user(uid, default=None):
|
|
|
+ return platform_ug._uid2user(uid, default)
|
|
|
+
|
|
|
+
|
|
|
+def gid2group(gid, default=None):
|
|
|
+ return platform_ug._gid2group(gid, default)
|
|
|
+
|
|
|
+
|
|
|
+def user2uid(user, default=None):
|
|
|
+ return platform_ug._user2uid(user, default)
|
|
|
+
|
|
|
+
|
|
|
+def group2gid(group, default=None):
|
|
|
+ return platform_ug._group2gid(group, default)
|