mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Fill in _os.environ with the correct types of strings
This commit is contained in:
@@ -457,8 +457,26 @@ fn os_unsetenv(key: Either<PyStringRef, PyBytesRef>, vm: &VirtualMachine) -> PyR
|
||||
|
||||
fn _os_environ(vm: &VirtualMachine) -> PyDictRef {
|
||||
let environ = vm.ctx.new_dict();
|
||||
for (key, value) in env::vars() {
|
||||
environ.set_item(&key, vm.new_str(value), vm).unwrap();
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::ffi::OsStringExt;
|
||||
for (key, value) in env::vars_os() {
|
||||
environ
|
||||
.set_item(
|
||||
&vm.ctx.new_bytes(key.into_vec()),
|
||||
vm.ctx.new_bytes(value.into_vec()),
|
||||
vm,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
for (key, value) in env::vars() {
|
||||
environ
|
||||
.set_item(&vm.new_str(key), vm.new_str(value), vm)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
environ
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user