mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Fix os.unsetenv
This commit is contained in:
committed by
Jeong, YunWon
parent
13c491712b
commit
142d333c5c
@@ -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,
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user