Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 468f1aa

Browse filesBrowse files
mmednickyouknowone
authored andcommitted
Implmentation for os.pathconf_names
1 parent ef873b4 commit 468f1aa
Copy full SHA for 468f1aa

File tree

2 files changed

+28
-2
lines changed
Filter options

2 files changed

+28
-2
lines changed

‎extra_tests/snippets/stdlib_os.py

Copy file name to clipboardExpand all lines: extra_tests/snippets/stdlib_os.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
507507

508508
for arg in [None, 1, 1.0, TabError]:
509509
assert_raises(TypeError, os.system, arg)
510+
511+
# Testing for os.pathconf_names
512+
if not sys.platform.startswith("win"):
513+
assert len(os.pathconf_names) > 0
514+
assert 'PC_NAME_MAX' in os.pathconf_names
515+
for option,index in os.pathconf_names.items():
516+
assert os.pathconf('/', index) == os.pathconf('/', option)
517+

‎vm/src/stdlib/posix.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/posix.rs
+20-2Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ pub mod module {
5050
ffi::{CStr, CString},
5151
fs, io,
5252
os::unix::{ffi as ffi_ext, io::RawFd},
53+
str::FromStr,
5354
};
54-
use strum_macros::EnumString;
55+
use strum::VariantNames;
56+
use strum_macros::{EnumString, EnumVariantNames};
5557

5658
#[pyattr]
5759
use libc::{PRIO_PGRP, PRIO_PROCESS, PRIO_USER};
@@ -1681,7 +1683,7 @@ pub mod module {
16811683

16821684
// Copy from [nix::unistd::PathconfVar](https://docs.rs/nix/0.21.0/nix/unistd/enum.PathconfVar.html)
16831685
// Change enum name to fit python doc
1684-
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, EnumString)]
1686+
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, EnumString, EnumVariantNames)]
16851687
#[repr(i32)]
16861688
#[allow(non_camel_case_types)]
16871689
pub enum PathconfVar {
@@ -1881,6 +1883,22 @@ pub mod module {
18811883
pathconf(PathOrFd::Fd(fd), name, vm)
18821884
}
18831885

1886+
#[pyattr]
1887+
fn pathconf_names(vm: &VirtualMachine) -> PyDictRef {
1888+
let pathname = vm.ctx.new_dict();
1889+
for variant in PathconfVar::VARIANTS {
1890+
// get the name of variant as a string to use as the dictionary key
1891+
let key = vm.ctx.new_str(variant.to_string());
1892+
// get the enum from the string and convert it to an integer for the dictionary value
1893+
let value: PyObjectRef = vm
1894+
.ctx
1895+
.new_int(PathconfVar::from_str(variant).unwrap() as u8)
1896+
.into();
1897+
pathname.set_item(&*key, value, vm).unwrap();
1898+
}
1899+
pathname
1900+
}
1901+
18841902
#[cfg(any(target_os = "linux", target_os = "macos"))]
18851903
#[derive(FromArgs)]
18861904
struct SendFileArgs {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.