Fill in _os.environ with the correct types of strings

This commit is contained in:
coolreader18
2019-10-09 23:32:14 -05:00
parent f9572cad23
commit be274ec39e

View File

@@ -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
}