Fix os.unsetenv

This commit is contained in:
Jeong YunWon
2024-04-19 23:47:35 +09:00
committed by Jeong, YunWon
parent 13c491712b
commit 142d333c5c
3 changed files with 11 additions and 3 deletions

View File

@@ -16,8 +16,7 @@ pub(crate) mod module {
builtins::{PyDictRef, PyStrRef, PyTupleRef},
common::{crt_fd::Fd, os::last_os_error, suppress_iph},
convert::ToPyException,
function::Either,
function::OptionalArg,
function::{Either, OptionalArg},
ospath::OsPath,
stdlib::os::{errno_err, DirFd, FollowSymlinks, SupportFunc, TargetIsDirectory, _os},
PyResult, TryFromObject, VirtualMachine,

View File

@@ -407,7 +407,7 @@ pub(super) mod _os {
return Err(vm.new_value_error("embedded null byte".to_string()));
}
if key.is_empty() || key.contains('=') {
return Err(vm.new_value_error("illegal environment variable name".to_string()));
return Err(vm.new_errno_error(22, "Invalid argument".to_owned()));
}
env::remove_var(key);
Ok(())

View File

@@ -189,6 +189,15 @@ impl VirtualMachine {
self.new_exception_msg(os_error, msg)
}
pub fn new_errno_error(&self, errno: i32, msg: String) -> PyBaseExceptionRef {
let vm = self;
let exc_type =
crate::exceptions::errno_to_exc_type(errno, vm).unwrap_or(vm.ctx.exceptions.os_error);
let errno_obj = vm.new_pyobj(errno);
vm.new_exception(exc_type.to_owned(), vec![errno_obj, vm.new_pyobj(msg)])
}
pub fn new_system_error(&self, msg: String) -> PyBaseExceptionRef {
let sys_error = self.ctx.exceptions.system_error.to_owned();
self.new_exception_msg(sys_error, msg)