MCPcopy Index your code
hub / github.com/RustPython/RustPython / getpwuid

Function getpwuid

crates/vm/src/stdlib/pwd.rs:79–96  ·  view source on GitHub ↗
(uid: PyIntRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

77
78 #[pyfunction]
79 fn getpwuid(uid: PyIntRef, vm: &VirtualMachine) -> PyResult<PasswdData> {
80 let uid_t = libc::uid_t::try_from(uid.as_bigint())
81 .map(unistd::Uid::from_raw)
82 .ok();
83 let user = uid_t
84 .map(User::from_uid)
85 .transpose()
86 .map_err(|err| err.into_pyexception(vm))?
87 .flatten();
88 let user = user.ok_or_else(|| {
89 vm.new_key_error(
90 vm.ctx
91 .new_str(format!("getpwuid(): uid not found: {}", uid.as_bigint()))
92 .into(),
93 )
94 })?;
95 Ok(PasswdData::from(user))
96 }
97
98 // TODO: maybe merge this functionality into nix?
99 #[cfg(not(target_os = "android"))]

Callers

nothing calls this directly

Calls 8

okMethod · 0.80
as_bigintMethod · 0.80
ok_or_elseMethod · 0.80
new_key_errorMethod · 0.80
mapMethod · 0.45
flattenMethod · 0.45
into_pyexceptionMethod · 0.45
new_strMethod · 0.45

Tested by

no test coverage detected